diff --git a/notebooks/example.ipynb b/notebooks/example.ipynb index dbf5756..e5ca59a 100644 --- a/notebooks/example.ipynb +++ b/notebooks/example.ipynb @@ -746,7 +746,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/notebooks/memory_profiling.ipynb b/notebooks/memory_profiling.ipynb index 40a06e0..979eb4f 100644 --- a/notebooks/memory_profiling.ipynb +++ b/notebooks/memory_profiling.ipynb @@ -445,7 +445,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.11" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/pyscal_rdf/graph.py b/pyscal_rdf/graph.py index 409f77e..8b324fa 100644 --- a/pyscal_rdf/graph.py +++ b/pyscal_rdf/graph.py @@ -882,7 +882,11 @@ def query(self, inquery): """ res = self.graph.query(inquery) if res is not None: - return pd.DataFrame(res) + for line in inquery.split('\n'): + if 'SELECT DISTINCT' in line: + break + labels = [x[1:] for x in line.split()[2:]] + return pd.DataFrame(res, columns=labels) raise ValueError("SPARQL query returned None") diff --git a/pyscal_rdf/network/network.py b/pyscal_rdf/network/network.py index ad0c8ec..0ff5faf 100644 --- a/pyscal_rdf/network/network.py +++ b/pyscal_rdf/network/network.py @@ -15,12 +15,12 @@ class OntologyNetwork: """ Network representation of Onto """ - def __init__(self, infile=None): + def __init__(self, infile=None, delimiter='/'): if infile is None: infile = owlfile self.g = nx.DiGraph() - self.onto = OntoParser(infile) + self.onto = OntoParser(infile, delimiter=delimiter) self.data_prefix = 'value' self._parse_all() diff --git a/pyscal_rdf/network/parser.py b/pyscal_rdf/network/parser.py index 2af5442..af11012 100644 --- a/pyscal_rdf/network/parser.py +++ b/pyscal_rdf/network/parser.py @@ -10,6 +10,8 @@ class OntoParser: def __init__(self, infile, delimiter='/'): if os.path.exists(infile): self.tree = get_ontology(f'file://{infile}').load() + elif infile[:4] == 'http': + self.tree = get_ontology(infile) else: raise FileNotFoundError(f'file {infile} not found!') self.attributes = {} @@ -131,10 +133,12 @@ def _parse_object_property(self): self.attributes['object_property'][term.name] = term for d in dm: if d!='07:owl#Thing': - self.attributes['class'][d].is_range_of.append(term.name) + if d in self.attributes['class']: + self.attributes['class'][d].is_range_of.append(term.name) for r in rn: if r!='07:owl#Thing': - self.attributes['class'][d].is_domain_of.append(term.name) + if d in self.attributes['class']: + self.attributes['class'][d].is_domain_of.append(term.name) def _parse_class_basic(self): classes = []