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
144 stars 30 forks source link

RDFS_Semantics add predicate datatype values from unrelated subjects #61

Closed senevoldsen closed 1 month ago

senevoldsen commented 1 year ago

Running version 6.0.2. In this example, after running the closure, both ex:alpha and ex:beta has both 42 and 22 under the ex:hasValue predicate.

from rdflib import Graph
from owlrl import DeductiveClosure, RDFS_Semantics

input_ttl = """
@prefix ex: <urn:example#> .
ex:alpha ex:hasValue "42"^^ex:Blorb .
ex:beta ex:hasValue "22"^^ex:Blorb .
"""

g = Graph()
g.parse(data=input_ttl, format='turtle')
DeductiveClosure(RDFS_Semantics).expand(g)
print(g.serialize(format='turtle'))
senevoldsen commented 1 year ago

It looks like it may be caused by using normal Python semantics to infer literals with same value. In my case ex:Blorb is not understood by Rdflib so it assigns it the value None. However, since both are None they compare equal and they add the attributes.

Another example shows the same happen with integers and booleans:

@prefix ex: <urn:example#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:alpha ex:hasValue "false"^^xsd:boolean .
ex:beta ex:hasValue "0"^^xsd:integer .

Here both ex:alpha and ex:beta ends up with ex:hasValue for both xsd:boolean and xsd:integer even though (at least I think) they are different values in RDF(S) interpretations.