HELP : Add elements from one ontology to another

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

HELP : Add elements from one ontology to another

jlbellier
Hello

I am turning around on my problem and I do not know how to solve it. I am using Owlready2 with Python.

I have two ontologies onto_A and onto_B that are stored in local files (let's say fileA and fileB). The structure is the same for both, only the individuals are different.

I would like to copy the individuals from fileB to fileA. I tried to do an import :

onto_A.imported_ontologies.append(onto_B) and then call save, but when I open fileA in Protege, I get an error.

I also tried to build the list of individuals of onto_B, let's call it list_indiv , and then do a instruction like this :

with_onto_A:
    for indiv in list_indiv:
       ...

    onto_A.save(fileA)

But fileA is still unchanged.

Is there an easy way to do that (a kind of append mode on the save method) ??

I am really stucked.

Thnak you in advance for your help.

Best regards,
Jean-luc.



Reply | Threaded
Open this post in threaded view
|

Re: HELP : Add elements from one ontology to another

cknoll
The only way that I know is to dynamically *create* the individuals from B in the context of onto_A:

I implemented a minimal example:

https://github.com/cknoll/demo-material/blob/main/expertise_system/copy_individuals.ipynb

It also shows how to use separate worlds to keep both ontologies apart. However it might be necessary to copy more data than just the comments.


Let me know, if you find a better solution.


Best,
Carsten.
Reply | Threaded
Open this post in threaded view
|

Re: HELP : Add elements from one ontology to another

Jiba
Administrator
In reply to this post by jlbellier
Hello,

I'm sorry, there is currently no copy functionality in Owlready -- mostly because copy is more difficult to implement that it seems to be, since one usually wants to copy some facts but not all.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: HELP : Add elements from one ontology to another

jlbellier
In reply to this post by cknoll
Thank you cknoll for your reply.

That is finnally what i did. I defined an ontology on my target file and re-created the individuals from the source file and it worked.

Best regards,
Jean-Luc.