Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Oxigraph SPARQL update for datasets #59

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ It also exposes pyoxigraph parsers and serializers as rdflib parser and serializ
Oxigraph store can be used as drop-in replacement of the rdflib default one. It support context but not formulas.
Transaction support is not implemented yet.

SPARQL query evaluation is done by pyoxigraph instead of rdflib if the Oxigraph store is used.
SPARQL update evaluation is still done using rdflib because of [a limitation in rdflib context management](https://github.com/RDFLib/rdflib/issues/1396).
SPARQL query and update evaluation is done by pyoxigraph instead of rdflib if the Oxigraph store is used.
SPARQL update evaluation on `Graph` and `ConjunctiveGraph` is still done
using rdflib because of [a limitation in rdflib context management](https://github.com/RDFLib/rdflib/issues/1396).

Oxrdflib is [available on Pypi](https://pypi.org/project/oxrdflib/) and installable with:
```bash
Expand Down
11 changes: 9 additions & 2 deletions oxrdflib/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import pyoxigraph as ox
from rdflib import Graph
from rdflib.graph import DATASET_DEFAULT_GRAPH_ID
from rdflib.plugins.sparql.sparql import Query, Update
from rdflib.query import Result
from rdflib.store import VALID_STORE, Store
Expand Down Expand Up @@ -172,9 +173,15 @@ def update(
initNs: Mapping[str, Any], # noqa: N803
initBindings: Mapping[str, Identifier], # noqa: N803
queryGraph: str, # noqa: N803
**kwargs: Any,
**kwargs: Any, # noqa: ARG002
) -> None:
raise NotImplementedError
init_ns = dict(self._namespace_for_prefix, **initNs)
update = "".join(f"PREFIX {prefix}: <{namespace}>\n" for prefix, namespace in init_ns.items()) + update
if initBindings:
raise NotImplementedError("initBindings are not supported by Oxigraph store")
if queryGraph != DATASET_DEFAULT_GRAPH_ID:
raise NotImplementedError(f"Only {DATASET_DEFAULT_GRAPH_ID} is supported by native Oxigraph store")
self._inner.update(update)

def commit(self) -> None:
# TODO: implement
Expand Down
6 changes: 3 additions & 3 deletions tests/test_sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ def test_insert_where_update_dataset_named_graph(self):
g = Dataset("Oxigraph")
g.add((EX.foo, RDF.type, EX.Entity, EX.g))
g.update("INSERT { ?s a <http://example.com/Entity2> } WHERE { GRAPH ?g { ?s a <http://example.com/Entity> } }")
self.assertIn((EX.foo, RDF.type, EX.Entity2, g), g) # RDFlib issue #2019
self.assertIn((EX.foo, RDF.type, EX.Entity2, g.identifier), g)

def test_insert_where_update_dataset_default_graph(self):
g = Dataset("Oxigraph")
g.add((EX.foo, RDF.type, EX.Entity))
g.update("INSERT { ?s a <http://example.com/Entity2> } WHERE { ?s a <http://example.com/Entity> }")
self.assertIn((EX.foo, RDF.type, EX.Entity2, g.identifier), g) # RDFlib issue #2019
self.assertIn((EX.foo, RDF.type, EX.Entity2, g.identifier), g)

def test_insert_where_update_dataset_default_union(self):
g = Dataset("Oxigraph", default_union=True)
g.add((EX.foo, RDF.type, EX.Entity, EX.g))
g.update("INSERT { ?s a <http://example.com/Entity2> } WHERE { ?s a <http://example.com/Entity> }")
self.assertIn((EX.foo, RDF.type, EX.Entity2, g.identifier), g) # RDFlib issue #2019
self.assertIn((EX.foo, RDF.type, EX.Entity2, g.identifier), g)


if __name__ == "__main__":
Expand Down