Skip to content

Commit

Permalink
Allows to inject pyoxigraph.Store into oxrdflib.OxigraphStore
Browse files Browse the repository at this point in the history
  • Loading branch information
Tpt committed Mar 20, 2023
1 parent c45a05e commit be36d20
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ If the `open` method is not called Oxigraph will automatically use a ramdisk on

To do anything else, use the usual rdflib python API.

It is also possible to directly inject a [pyoxigraph `Store` object](https://pyoxigraph.readthedocs.io/en/stable/store.html#pyoxigraph.Store) directly into an Oxrdflib store:

```python
graph = rdflib.Graph(store=oxrdflib.OxigraphStore(store=pyoxigraph.Store("test_dir")))
```

This might be handy to e.g. open the database as read-only:

```python
graph = rdflib.Graph(store=oxrdflib.OxigraphStore(store=pyoxigraph.Store.read_only("test_dir")))
```


## Differences with rdflib default store
- relative IRIs are not supported by Oxigraph.
- Just like the `SPARQLStore`, Oxigraph joins the `initBindings` parameter of the `query` method after the query has been evaluated, instead of injecting them at the beginning of the query.
Expand Down
4 changes: 3 additions & 1 deletion oxrdflib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def __init__(
self,
configuration: Optional[str] = None,
identifier: Optional[Identifier] = None,
*,
store: Optional[ox.Store] = None,
):
self._store = None
self._store = store
self._prefix_for_namespace: Dict[URIRef, str] = {}
self._namespace_for_prefix: Dict[str, URIRef] = {}
super().__init__(configuration, identifier)
Expand Down
11 changes: 10 additions & 1 deletion tests/test_store.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import unittest
from pathlib import Path

from pyoxigraph import Store
from rdflib import RDF, XSD, BNode, ConjunctiveGraph, Graph, Literal, Namespace

from oxrdflib import OxigraphStore

EX = Namespace("http://example.com/")


Expand Down Expand Up @@ -34,7 +37,13 @@ def test_store_with_late_open(self):
with self.assertRaises(Exception) as _:
g.open("test_store")

def _fill_graph(self, g: Graph):
def test_store_with_shared_backend(self):
store = Store()
self._fill_graph(Graph(store=OxigraphStore(store=store), identifier="http://example.com"))
self._test_graph(Graph(store=OxigraphStore(store=store), identifier="http://example.com"))

@staticmethod
def _fill_graph(g: Graph):
g.add((EX.foo, RDF.type, EX.Entity))
g.add((EX.foo, EX.prop, BNode("123")))
g.add((EX.foo, EX.prop1, Literal("foo")))
Expand Down

0 comments on commit be36d20

Please sign in to comment.