How can i get the ancestors/superclasses of a given class?

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

How can i get the ancestors/superclasses of a given class?

PippoBurando
Hello, i wanted to ask how could i get the ancestors/superclasses of a given class, for example
from Margherita i want to get: NamedPizza, Pizza, Food, Thing.
I have already tryed something like this:

>>>onto = get_ontology("https://protege.stanford.edu/ontologies/pizza/pizza.owl").load()
>>>onto.Pizza
>>>namespace = onto.get_namespace("http://www.co-ode.org/ontologies/pizza/pizza.owl#")
>>>print(list(namespace.Margherita.ancestors()))

but i don't necessarily know the starting class. The class is going to be given to me by the user through a string input. (in the example Margherita would be given to me by the user).

Reply | Threaded
Open this post in threaded view
|

Re: How can i get the ancestors/superclasses of a given class?

Jiba
Administrator
Hi,

You can use .ancestors(). To obtain the class from its name, use :

name = "Margherita"
onto[name].ancestors()

or:

namespace[name].ancestors()

Jiba