1. Introduction
Owlready2 is a package for manipulating OWL 2.0 ontologies in Python. It can load, modify, save ontologies, and it supports reasoning via HermiT (included). Owlready allows a transparent access to OWL ontologies.
2. Owlready2 can:
Import ontologies in RDF/XML, OWL/XML or NTriples format.
Manipulates ontology classes, instances and annotations as if they were Python objects.
Add Python methods to ontology classes.
Re-classify instances automatically, using the HermiT reasoner.
Import medical terminologies from UMLS (see PyMedTermino2).
3. instance
from owlready2 import *
onto_path.append("/Users/a-pc/Documents/智齿科技/知识图谱")
onto = get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl")
onto.load()
get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl#")
# Create new classes in the ontology, possibly mixing OWL constructs and Python methods:
class NonVegetarianPizza(onto.Pizza):
equivalent_to = [
onto.Pizza
& ( onto.has_topping.some(onto.MeatTopping)
| onto.has_topping.some(onto.FishTopping)
) ]
def eat(self): print("Beurk! I'm vegetarian!")# Create new classes in the ontology, possibly mixing OWL constructs and Python methods:
class NonVegetarianPizza(onto.Pizza):
equivalent_to = [
onto.Pizza
& ( onto.has_topping.some(onto.MeatTopping)
| onto.has_topping.some(onto.FishTopping)
) ]
def eat(self): print("Beurk! I'm vegetarian!")
# Access the classes of the ontology, and create new instances / individuals:
test_pizza = onto.Pizza("test_pizza_owl_identifier")
test_pizza.has_topping = [ onto.CheeseTopping(), onto.TomatoTopping() ]
test_pizza.has_topping.append(onto.MeatTopping())
# Execute HermiT and reparent instances and classessync_reasoner()
test_pizza.__class__
pizza_onto.NonVegetarianPizza
test_pizza.eat()
Beurk! I'm vegetarian!
网友评论