Load an ontology from a local repository, or from Internet:
>>> from owlready import * >>> onto_path.append("/path/to/your/local/ontology/repository") >>> onto = get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl") >>> onto.load()
Create new classes in the ontology, possibly mixing OWL restrictions and Python methods:
>>> class NonVegetarianPizza(onto.Pizza): ... equivalent_to = [ ... onto.Pizza ... & ( restriction("has_topping", SOME, onto.MeatTopping) ... | restriction("has_topping", SOME, onto.FishTopping) ... ) ] ... def eat(self): print("Beurk! I'm vegetarian!")
Access ontology class, and create new instances / individuals:
>>> onto.Pizza pizza_onto.Pizza >>> test_pizza = onto.Pizza("test_pizza_owl_identifier") >>> test_pizza.has_topping = [ onto.CheeseTopping(), ... onto.TomatoTopping(), ... onto.MeatTopping () ]
Export to OWL/XML file:
>>> test_onto.save()
Perform reasoning, and classify instances and classes:
>>> test_pizza.__class__ onto.Pizza >>> # Execute HermiT and reparent instances and classes >>> onto.sync_reasoner() >>> test_pizza.__class__ onto.NonVegetarianPizza >>> test_pizza.eat() Beurk! I'm vegetarian !
More examples are available in the documentation and the /doc/examples directory in the sources.