Listing individuals for each concept in an ontology using rdflib

I also have an ontology written in OWL / RDF (using Protege). This ontology has already been filled by some people for each concept. I ported it to python using rdflib and FuXi packages. And I can successfully analyze my ontology and set a schedule. Now the only thing I need to do is print all the people for each concept. Does anyone know how I can do this?

+3
source share
1 answer

When you tell all people about each concept, I guess what you mean all the resources of rdf:type an specific class. With help, rdflibyou can easily do this by going through a graph:

from rdflib import Graph
from rdflib import URIRef
g = Graph()
g.parse("ontology.owl")
aClass = URIRef("http://www.someuri.org/for/your/class")
rdftype = URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")

for triple in g.triples((None,rdfType,aClass)):
    print triple

(None,rdfType,aClass) g. , , . rdftype aClass.

, :

for triple in g.triples((None,rdfType,None)):
    print triple

unbound OWL.

+4

All Articles