From 7be51308485aff8851ac8a9a09e45abb309245b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martynas=20Jusevi=C4=8Dius?= Date: Sat, 4 Nov 2023 12:10:48 +0100 Subject: [PATCH] Added `Dataset.contains_named_graph()` Fixed `pyoxigraph` version at 0.3.20 --- example.py | 6 ++++++ oxijen/model_impl/impl.py | 8 ++++++++ oxijen/rdf_model.py | 4 ++++ requirements.txt | 2 +- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/example.py b/example.py index 046dd18..a96f800 100644 --- a/example.py +++ b/example.py @@ -26,6 +26,12 @@ print("\ndataset.graph_names():\n") print(list(dataset.graph_names())) +print("\ndataset.contains_named_graph(\"http://example.org/graph2\"):\n") +print(dataset.contains_named_graph("http://example.org/graph2")) + +print("\ndataset.contains_named_graph(\"http://example.org/non-existing\"):\n") +print(dataset.contains_named_graph("http://example.org/non-existing")) + print("\ngraph1.list_triples():\n") output = io.BytesIO() serialize(list(graph1.list_triples()), output, "application/n-triples") # "application/n-quads" should work diff --git a/oxijen/model_impl/impl.py b/oxijen/model_impl/impl.py index 0cb1e36..6503353 100644 --- a/oxijen/model_impl/impl.py +++ b/oxijen/model_impl/impl.py @@ -98,6 +98,14 @@ def graph_names(self) -> Iterator[Resource]: return map(lambda name: ResourceImpl(name, None), graph_names) + def contains_named_graph(self, name: Union[str, Resource]) -> bool: + if type(name) is str: + name_node = NamedNode(name) + else: + name_node = name.node + + return self.store.contains_named_graph(name_node) + def get_named_graph(self, name: Union[str, Resource]) -> Graph: if type(name) is str: name_node = NamedNode(name) diff --git a/oxijen/rdf_model.py b/oxijen/rdf_model.py index d39daed..eea2b7c 100644 --- a/oxijen/rdf_model.py +++ b/oxijen/rdf_model.py @@ -89,6 +89,10 @@ def default_graph(self): def graph_names(self) -> Iterator[Resource]: pass + @abstractmethod + def contains_named_graph(self, name: Union[str, Resource]) -> bool: + pass + @abstractmethod def get_named_graph(self, name: Union[str, Resource]) -> Graph: pass diff --git a/requirements.txt b/requirements.txt index 1e86459..e81f3c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pyoxigraph \ No newline at end of file +pyoxigraph == 0.3.20 \ No newline at end of file