Accessing class by its name in owlready2

classic Classic list List threaded Threaded
2 messages Options
KZ
Reply | Threaded
Open this post in threaded view
|

Accessing class by its name in owlready2

KZ
Hello!

I've been trying to access my ontology's classes simply by names like in Pizza examples and it works good for Pizza ontology on my side as well, but doesn't work with my own ontology. However I can access them through ontology.classes() or search. Could you please advise, what could be the reason for that?

Many thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Accessing class by its name in owlready2

Jiba
Administrator
Hello,

There are 4 ways to access a class:

1) if you created the class locally, for example with:

        class MyClass(Thing):
                ...

Then the class is available as "MyClass" as usual in Python.
Of course, classes defined in an OWL file but not created locally in Python are not available this way.


2) if the class is available in the ontology namespace, you can access it as:

        onto.ClassName

This works only is the IRI of the class is the IRI of the ontology + the class name.
If the class is defined in another namespace (as common in OBO ontologies), this would not works as expected.


3) In this case, you need a namespace:

        namespace = onto.get_namespace("http://purl.obolibrary.org/obo/")
        namespace.ClassName


4) You can also get the class from its full IRI:

        IRIS["http://test.org/test.owl#MyClass"]

Best regards,
Jean-Baptiste Lamy
MCF HDR, Laboratoire LIMICS, Université Paris 13