Hello,
I have been following the
Ontologies in Python textbook and have two questions:
1. Even though I have imported an ontology into another, I still cannot access the classes from the imported ontology (when I list the classes after the merge, it still only shows the original classes before the merge, but when I list the imported ontologies it shows up). Is there a way to combine ontologies so that all classes can be easily accessible just like they were created under one ontology?
2. Basically, all I am trying to do is write SWRL rules across multiple ontologies. For instance, a building ontology consists of multiple ontologies like structure, HVAC, and office space... and I want to write SWRL rules so that they can interact with each other. But I don't know how to specify namespace under SWRL rules in Owlready2, perhaps I am missing something, or is there a better way to approach it?
Thanks in advance.
Here is my script for combining ontologies:
nto_person = get_ontology('
http://test.org/person.owl')
with onto_person:
class Person(Thing):
pass
class weight(Person >> float, FunctionalProperty):
pass
class size(Person >> float, FunctionalProperty):
pass
class bmi(Person >> float, FunctionalProperty):
pass
class Obese(Person):
equivalent_to = [Person & (bmi >= 30.0)]
imp = Imp()
imp.set_as_rule("Person(?x), weight(?x,?w), size(?x,?s), multiply(?s2, ?s, ?s), divide(?b, ?w, ?s2) -> bmi(?x, ?b)")
onto_food = get_ontology('
http://test.org/food.owl')
with onto_food:
class Food(Thing):
pass
class price(Food >> float, FunctionalProperty):
pass
class calo(Food >> float, FunctionalProperty):
pass
class weight(Food >> float, FunctionalProperty):
pass
with onto_food:
class Expensive(Food):
equivalent_to = [Food & (price >= 30.0)]
onto_food.imported_ontologies.append(onto_person)
onto_food.save(r'Path\onto_food.owl')
onto_food = get_ontology(r'Path\onto_food.owl').load()
list(onto_food.classes())
onto_food.imported_ontologies