RDFLib / OWL-RL

A simple implementation of the OWL2 RL Profile on top of RDFLib: it expands the graph with all possible triples that OWL RL defines. It can be used together with RDFLib to expand an RDFLib Graph object, or as a stand alone service with its own serialization.
http://www.ivan-herman.net/Misc/2008/owlrl/
Other
139 stars 30 forks source link

OWL RL creates triples with a Literal as Subject when evaluating PROV-O ontology #50

Open anatoly-scherbakov opened 2 years ago

anatoly-scherbakov commented 2 years ago

Such triples are illegal due to RDF standard, and they break at least some of the storage engines: see https://github.com/RDFLib/rdflib-sqlalchemy/issues/85

The full working example is here: https://gist.github.com/anatoly-scherbakov/ebde3d6b70ddde7f7b3baadb65d8464b

I am not entirely clear why these are created. I am willing to help by writing a PR if you could please explain the reason of those triples to be asserted.

majidaldo commented 1 year ago

related https://github.com/RDFLib/OWL-RL/issues/13

majidaldo commented 1 year ago

patch hack: capture the offensive triples.

from rdflib import Literal, Graph as _Graph
class Graph(_Graph):

    def __init__(self, *p, **k):
        self._offensive = set()
        super().__init__(*p, **k)

    def add(self, t):
        if isinstance(t[0], Literal):
            self._offensive.add(t)
        # so that it keeps working as usual
        return super().add(t)

   # could patch __iter__ to filter out the offensive triples.

this is the 'last defense' procedure but there should be some config for this.