Skip to content

Commit

Permalink
change graph code
Browse files Browse the repository at this point in the history
  • Loading branch information
srmnitc committed Sep 13, 2023
1 parent 02925e3 commit 12bf23e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion notebooks/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion notebooks/memory_profiling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
6 changes: 5 additions & 1 deletion pyscal_rdf/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
4 changes: 2 additions & 2 deletions pyscal_rdf/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 6 additions & 2 deletions pyscal_rdf/network/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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 = []
Expand Down

0 comments on commit 12bf23e

Please sign in to comment.