http://owlready.306.s1.nabble.com/How-to-move-concepts-from-one-ontology-to-another-tp1386p1401.html
Hi,
Yes, the class is just a wrapper arround the data stored in the SQL tables.
equivalent_to and is_a need to be copied, recursively.
Each class has a "default" owning ontology, however, part of the class may be defined in other ontologies. But equivalent_to and is_a are blank nodes, and blank nodes are anonymous and thus they are "ontology-local" : an ontology cannot refer to the blank node
from another ontology.
I think you missed something in types.new_class() : you must specify the parent classes. If you don't, you create a standard Python class, not a Owlready class. So you need something like types.new_class("class_name", (Thing,)) to create a new class that is
a Thing.
You can put the new class in a (temporary) variable name, and then adds its parent in .is_a. In addition, you can add the blank nodes, as long as you remove them from their former child class (blank nodes cannot be shared by several classes from different ontologies).
The code example below does that.
Jiba
----8<------------
from owlready2 import *
onto_orig = get_ontology("
http://test.org/onto_orig.owl")
with onto_orig:
class A(Thing): pass
class B(Thing): pass
class C(Thing): pass
class D(Thing):
is_a = [A & (B | C)]
onto_dest = get_ontology("
http://test.org/onto_dest.owl")
with onto_dest:
for class_orig in onto_orig.classes():
class_dest = types.new_class(class_orig.name, (Thing,))
for parent in list(class_orig.is_a):
if not isinstance(parent, Thing): class_orig.is_a.remove(parent) # Bank node
class_dest.is_a.append(parent)
onto_dest.save("/tmp/o.owl")
print(open("/tmp/o.owl").read())
To unsubscribe from How to move concepts from one ontology to another,
click here.
NAML