Search code examples
pythonsparqlrdfrdflib

How to obtain individuals (instances) and the value (Literals) using Sparql Query in python


I have created an ontology in protegee and uploaded it online in .owl file format. Now I am able to load it in python using jupyter notebook and rdflib to obtain all statements or the Entity-Attribute-Value (EAV). Now I want to obtain individuals and the value of their properties. For instance, "Bob hasAge 32", "Alice hasAge 23", etc. I want to query the ontology to get the result in the form of the table below. How can I achieve that? I am happy to provide more information if needed. Thank you in advance.

Individual Age
Bob 32
Alice 23

Solution

  • Just rewriting UninformedUser's comment as an answer for acceptance:

    If you have the SPARQL query why can't you do it in rdflib as well? Why not try reading the official documentation? https://rdflib.readthedocs.io/en/stable/intro_to_sparql.html