RDFLib / rdflib

RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
https://rdflib.readthedocs.org
BSD 3-Clause "New" or "Revised" License
2.15k stars 555 forks source link

best practice for rdfs:subClassOf closure #1137

Closed danbri closed 2 years ago

danbri commented 4 years ago

I'm working with @Gnomus042 on SHACL/ShEx topics and we had need to update a Graph to explicitly add all the implied rdfs:subClassOf arcs. We found two approaches, one using transitiveClosure(), and the other using SPARQL .query():

Working examples - https://colab.research.google.com/drive/1DWrR-VKus4elIJ2lpHy7BXw7Jhk5qmDH?usp=sharing

Can you advise on which is preferred, or whether there is some other built-in or nearby extension to perform such tasks (and related inference e.g. subPropertyOf etc). I searched around but couldn't find clear guidance. Thanks for any pointers!

ashleysommer commented 4 years ago

@danbri The owl-rl project can operate in RDFS mode, which will expand a graph to inference all RDFS axioms including subClassOf and subPropertyOf. To answer your first question, I believe all graph expanders built on rdflib use the transitiveClosure() mechanism.

I see in your examples you're using PySHACL. Note, pySHACL has owl-rl built in, you can expand your graph before validation automatically using inference="rdfs" when calling validate().