Skip to content

Commit

Permalink
fix typing issue and add get_value function
Browse files Browse the repository at this point in the history
  • Loading branch information
BeritJanssen committed May 15, 2024
1 parent f0debbb commit 59930f3
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions ianalyzer_readers/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,18 +607,21 @@ def __init__(self, predicate: URIRef, node_type: str = 'object', multiple: bool
self.multiple = multiple
super().__init__(*nargs, **kwargs)

def _apply(self, graph: Graph = None, subject: BNode = None, *nargs, **kwargs) -> str | None:
def _apply(self, graph: Graph = None, subject: BNode = None, *nargs, **kwargs):
if self.node_type == 'subject':
return subject
else:
if self.multiple:
collection = Collection(graph, subject)
return [node.value for node in list(collection)]
return [self.get_value(node) for node in list(collection)]
else:
object = list(graph.objects(subject, self.predicate))[0]
if type(object) == Literal:
return object.value
elif type(object) == URIRef:
return split(object)[-1]
else:
return object
node = list(graph.objects(subject, self.predicate))[0]
return self.get_value(node)

def get_value(node):
if type(node) == Literal:
return node.value
elif type(node) == URIRef:
return split(node)[-1]
else:
return node

0 comments on commit 59930f3

Please sign in to comment.