Skip to content

Commit

Permalink
Added Dataset.contains_named_graph()
Browse files Browse the repository at this point in the history
Fixed `pyoxigraph` version at 0.3.20
  • Loading branch information
namedgraph committed Nov 4, 2023
1 parent 328935c commit 7be5130
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions oxijen/model_impl/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions oxijen/rdf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pyoxigraph
pyoxigraph == 0.3.20

0 comments on commit 7be5130

Please sign in to comment.