From 59930f3cea21dc252f5ec1c737cf7918bde16197 Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Wed, 15 May 2024 17:18:47 +0200 Subject: [PATCH] fix typing issue and add get_value function --- ianalyzer_readers/extract.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ianalyzer_readers/extract.py b/ianalyzer_readers/extract.py index a2c1ae7..4797f6e 100644 --- a/ianalyzer_readers/extract.py +++ b/ianalyzer_readers/extract.py @@ -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