美文网首页
owlready2的简单介绍

owlready2的简单介绍

作者: 一一的试验田 | 来源:发表于2019-05-14 20:14 被阅读0次

    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!

    相关文章

      网友评论

          本文标题:owlready2的简单介绍

          本文链接:https://www.haomeiwen.com/subject/xkaeaqtx.html