Skip to content

Commit

Permalink
update network
Browse files Browse the repository at this point in the history
  • Loading branch information
srmnitc committed Sep 20, 2023
1 parent f47ca88 commit aee3066
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pyscal_rdf/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ def __init__(self, infile=None, delimiter='/'):

self.g = nx.DiGraph()
self.onto = OntoParser(infile, delimiter=delimiter)
self.onto.attributes['data_node'] = []
self.data_prefix = 'value'
self._parse_all()


def _parse_all(self):
#call methods
self._add_class_nodes()
Expand Down Expand Up @@ -87,6 +89,7 @@ def _add_data_properties(self):
self.g.add_edge(d, val.name)
for r in val.range:
data_node = f'{val.name}{self.data_prefix}'
self.onto.attributes['data_node'].append(data_node)
self.g.add_node(data_node, node_type='literal', data_type=r)
self.g.add_edge(val.name, data_node)

Expand Down Expand Up @@ -146,11 +149,8 @@ def draw(self, styledict = {"class": {"shape":"box"},
return dot

def get_path_from_sample(self, target):
path = self.get_shortest_path(source="Sample", target=target)
triplets = []
for x in range(len(path)//2):
triplets.append(path[2*x:2*x+3])
return triplets
path = self.get_shortest_path(source="cmso:ComputationalSample", target=target, triples=True)
return path

def phrase_to_sparql(self, phrase):
def _extract_operation(phr):
Expand Down
21 changes: 20 additions & 1 deletion pyscal_rdf/network/term.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from rdflib import Namespace

class OntoTerm:
def __init__(self, uri, node_type=None,
Expand Down Expand Up @@ -38,6 +39,24 @@ def name(self):
return ":".join(uri_split[-2:])
else:
return self.uri


@property
def namespace(self):
uri_split = self.uri.split(self.delimiter)
if len(uri_split)>1:
return uri_split[-2]
else:
return self.uri

@property
def namespace_object(self):
uri_split = self.uri.split(self.delimiter)
if len(uri_split)>1:
namespace = self.delimiter.join(uri_split[:-1]) + self.delimiter
prop = uri_split[-1]
return getattr(Namespace(namespace), prop)
else:
return self.uri

def __repr__(self):
return str(self.name)

0 comments on commit aee3066

Please sign in to comment.