owlready keep adding classes into the existing ontology while using load()

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

owlready keep adding classes into the existing ontology while using load()

Waseem85
I am trying to access an ontology and then instantiate it but it looks like owlready keep adding into the existing file.
Here is my code;

    abc = get_ontology("file://D:/Excel_parser_1/OWL-xml_version/abc.owl").load()

    onto = get_ontology("file://C:/.../test_onot").load()
    onto.imported_ontologies.clear()
    onto.imported_ontologies.append(abc)
   
    ebbw_node = abc.Node("Node",ontology = onto)
    bes_instance = abc.ENode(bes.name, ontology = onto)
    bes_instance.hasName.append(bes.name)
   
    onto.save()


Just to summarise, I load an existing ontology named ABC.  I load another ontology "test_onot", which is almost empty. Every time I open the empty file, add ABC and instantiate classes, owlready keeps adding classes rather than just making two connection as in the above example.

Anything I am doing wrong?

Reply | Threaded
Open this post in threaded view
|

Re: owlready keep adding classes into the existing ontology while using load()

Jiba
Administrator
The implementation of clear() was missing in Owlready2's CallbackList, thus clear was not working as expected. I fixed it in the development version on BitBucket.

As a workaround, you can also use onto.imported_ontologies = []

I think there is also a problem in your example. "ontology =" is not a valid argument for instance creation, you probably mean "namespace =" :

    ebbw_node = abc.Node("Node", namespace = onto)

Alternatively, you can also use the "with" syntax :

with onto:
    ebbw_node = abc.Node("Node")
Reply | Threaded
Open this post in threaded view
|

Re: owlready keep adding classes into the existing ontology while using load()

Waseem85
Many thanks, Jiba.

Regards,
Waseem