Skip to content

Commit

Permalink
rewrite get graph method
Browse files Browse the repository at this point in the history
  • Loading branch information
srmnitc committed Aug 15, 2024
1 parent 60006f1 commit fd4d710
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions atomrdf/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ def iterate_and_reapply_triples(self, item):
uri_dict[triple[0].toPython()] = None
return uri_dict

def get_sample(self, sample, no_atoms=False):
def get_sample(self, sample, no_atoms=False, stop_at_sample=True):
"""
Get the Sample as a KnowledgeGraph
Expand All @@ -1257,6 +1257,9 @@ def get_sample(self, sample, no_atoms=False):
no_atoms: bool, optional
if True, returns the number of atoms in the sample
stop_at_sample: bool, optional
if True, stops the iteration at the when a sample object is encountered. Default is True.
Returns
-------
sgraph: :py:class:`RDFGraph`
Expand All @@ -1268,11 +1271,11 @@ def get_sample(self, sample, no_atoms=False):
if isinstance(sample, str):
sample = URIRef(sample)

_ = self.iterate_graph(sample, create_new_graph=True)
sgraph = self.iterate_and_create_graph(sample, stop_at_sample=stop_at_sample)
if no_atoms:
na = self.sgraph.value(sample, CMSO.hasNumberOfAtoms).toPython()
return self.sgraph, na
return self.sgraph
na = sgraph.value(sample, CMSO.hasNumberOfAtoms).toPython()
return sgraph, na
return sgraph

def get_label(self, item):
label = self.graph.value(item, RDFS.label)
Expand Down

0 comments on commit fd4d710

Please sign in to comment.