oxrdflib icon indicating copy to clipboard operation
oxrdflib copied to clipboard

Oxigraph fails to process rdflib.Literal values

Open apirogov opened this issue 1 year ago • 2 comments

Minimal working example:

from rdflib import Graph, Literal
from rdflib.namespace import FOAF

# graph = Graph()  # works
graph = Graph(store="Oxigraph")  # does not work
graph.add((Literal('1'), FOAF.name, Literal('2')))

Stack trace:

Traceback (most recent call last):
  File "/local/home/a.pirogov/projects/data_harvesting/scratch.py", line 6, in <module>
    graph.add((Literal('1'), FOAF.name, Literal('2')))
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/data-harvesting-Lq057YRM-py3.9/lib/python3.9/site-packages/rdflib/graph.py", line 535, in add
    self.__store.add((s, p, o), self, quoted=False)
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/data-harvesting-Lq057YRM-py3.9/lib/python3.9/site-packages/oxrdflib/__init__.py", line 66, in add
    self._inner.add(_to_ox(triple, context))
  File "/local/home/a.pirogov/.cache/pypoetry/virtualenvs/data-harvesting-Lq057YRM-py3.9/lib/python3.9/site-packages/oxrdflib/__init__.py", line 222, in _to_ox
    return ox.Quad(_to_ox(term[0]), _to_ox(term[1]), _to_ox(term[2]), _to_ox(context))
TypeError: argument 'subject': failed to extract enum PySubject ('NamedNode | BlankNode | Triple')
- variant NamedNode (NamedNode): TypeError: failed to extract field PySubject::NamedNode.0, caused by TypeError: 'Literal' object cannot be converted to 'NamedNode'
- variant BlankNode (BlankNode): TypeError: failed to extract field PySubject::BlankNode.0, caused by TypeError: 'Literal' object cannot be converted to 'BlankNode'
- variant Triple (Triple): TypeError: failed to extract field PySubject::Triple.0, caused by TypeError: 'Literal' object cannot be converted to 'Triple'

Expectation:

the backend should support all standard rdflib types, e.g. such as used here

apirogov avatar Apr 03 '24 09:04 apirogov

Hey! This is because Oxigraph enforces that all RDF triples must be valid. This leads to forbidding literals in the subject position of the triple (the first element of the tuple you give to graph.add).

Tpt avatar Apr 07 '24 07:04 Tpt

Ah thanks! That was from some basic sanity check test cases. Well, then I guess maybe a more helpful error message would be nice here :)

apirogov avatar Apr 08 '24 11:04 apirogov