Add subclasses into an ontology

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

Add subclasses into an ontology

EL_ABBA
Hello,

I have designed an ontology and now i want to load the ontology via python and assign new subclasses into exsiting classes.
I am able to load the ontology and add a new classes with the following code:

from owlready2 import *
import types
onto_world = owlready2.World()
onto = onto_world.get_ontology()
onto = onto.load()

with onto:
    class Plasmid(Thing) : pass

But I get the error >NameError: name '' is not defined< when trying to add a new subclass into an existing class. It only works by adding the class into "Thing" and than add subclasses into e.g. "Plasmid".
I was able to print all the class names and thought I could just copy them from the console, but it just doesn't work and I don't know how too fix the error.
 
Perhaps someone can help me?
Thanks a lot and happy holidays!
Reply | Threaded
Open this post in threaded view
|

Re: Add subclasses into an ontology

Jiba
Administrator
Hello,

You can add a new subclass as follow:

with onto:
    class Plasmid(onto.ParentClass) : pass


ParentClass needs to be defined at the same IRI as the ontology. If it is not, you can use default_world["http://full_iri/to/ParentClass"] to obtain the parent class.

Jiba