Read out restrictions of classes

classic Classic list List threaded Threaded
4 messages Options
Lux
Reply | Threaded
Open this post in threaded view
|

Read out restrictions of classes

Lux
Hello, I need to readout an existing ontology from a file. But I have a problem to readout the details of the restrictions of a class:

import owlready2 as or2
ontology = or2.get_ontology("file://sargon owl xml.owl").load()

for cla in ontology.classes():
      for restriction in cla.is_a:
            print(restriction)


The print gives an output like:
"sargon owl xml.hasFunction.some(sargon owl xml.StartStopFunction)"

But I don't know how to decompose this knowlegde into its seperate pieces (.property, .type , .cardinality and .value).

Calling e.g restriction.type resolves in "AttributeError: 'type' property is not defined".

Does someone know how I can access these informations?

Thank you in advance,
Lux


Reply | Threaded
Open this post in threaded view
|

Re: Read out restrictions of classes

Jiba
Administrator
Hello,

You can use the property, type, cardinality and value attribute of the restriction to decompose it.

Attention, Class.is_a contains all is-a relations, and not only Restriction. You should check before is the current parent is a restriction, with:

     if not isinstance(restriction, Restriction): continue

Jiba
Lux
Reply | Threaded
Open this post in threaded view
|

Re: Read out restrictions of classes

Lux
Hello,
thank you for your quick reply this solved my problem.

But I know see an other issue, restrictions that are referencing imported classes are pointing to None. My owl file contains this import statment: <Import>http://www.w3.org/2006/time</Import>

This leads to a file which syntax is probably not readable for owlready, i tried to convert it and saving it locally in the same folder, as discussed here:
http://owlready.8326.n8.nabble.com/handling-of-imported-ontology-td273.html

But I am not sure if Owlready can do this or how to name the file that it is correctly registered, I tried to name the file time.owl and used the code:

    onto_path.append(".")
    ontology = or2.get_ontology("file://sargon owl xml.owl").load()
    print(ontology.imported_ontologies)

As imported ontologies is [] it does not seem to work this way, is there a way to achieve a result?

Again thanks in advance,
Lux
Reply | Threaded
Open this post in threaded view
|

Re: Read out restrictions of classes

Jiba
Administrator
Hello,

The RDF/XML syntax for imports is the following:

<owl:Ontology rdf:about="http://test.org/testB.owl">
  <owl:imports rdf:resource="http://test.org/testA.owl"/>
</owl:Ontology>

Jiba