Re: Accessing Property Chains

Posted by msf on
URL: http://owlready.306.s1.nabble.com/Accessing-Property-Chains-tp2225p2228.html

Resorted to accessing RDFLib to get the property chain.  Here is the code. Note that it works for a single property chain.  Will have to generalize for multiple property chains for the same property.

"""
prop: the property for which a property chain is defined
w: the world object in which the data is stored

returns a list of properties comprising the property chain
"""

def getPropertyChain(prop, w=default_world) :
        chain = []
        rdfGraph = w.as_rdflib_graph()
        obj = rdfGraph.value(URIRef(prop.iri), OWL.propertyChainAxiom)
        while obj != RDF.nil :
                chain.append(IRIS[str(rdfGraph.value(obj, RDF.first))])
                obj = rdfGraph.value(obj, RDF.rest)
        return(chain)