Property assertion instead of individual annotation

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Property assertion instead of individual annotation

jayson
Hello Together,

I am trying to assert Object and Data properties to an individual and what i get is a individual annotation.
Here is how i tried it.

def TestClass(Thing):
     pass

def Attribute(Thing):
     pass

def number_of(DataProperty):
     range = [str]

def create_attr(attr):
     new_attr = Attribute(attr, namespace=onto)
     return new_attr

def has_attribute(TestClass >> Attribute):
     pass

def create_individual(class):
     attr = create_hazardous_attribute(class["attr"])
     new_subst = TestClass(class["name"], has_attribute=attr, )
     new_subst.number_of.append(class["number"])


How can I assert object and data properties to an individual. I think I misunderstood something fundamental.


Thank you in advance
Jayson
Reply | Threaded
Open this post in threaded view
|

Re: Property assertion instead of individual annotation

jayson
I think I found a solution, the individual is created as follows:

def create_individual(class):
     attr = create_attr("test_attr")
     new_subst = TestClass(class["name"], namespace=onto)
     new_restriction = onto.has_attribute.value(onto[attr])
     new_subst.is_a.append(new_restriction)

When I start a reasoner the property assertions are inferred and there are no annotations.

What do you think, is there another solution (anyway, the solution is working for me)?

Best regards
jayson
Reply | Threaded
Open this post in threaded view
|

Re: Property assertion instead of individual annotation

Jiba
Administrator
Hello,

There are several errors in your first example (some of them probably being typo, e.g. you should use class instead of def for creating OW classes and properties).

Here is the corrected version I used:

from owlready2 import *

onto = get_ontology("http://test.org/t2.owl")

with onto:
  class TestClass(Thing): pass

  class Attribute(Thing): pass

  class number_of(DataProperty):
     range = [str]

  def create_attr(attr):
    new_attr = Attribute(attr, namespace = onto)
    return new_attr

  class has_attribute(TestClass >> Attribute):
    pass

  attr = Attribute("hazardous")
  i = TestClass("i", has_attribute = [attr])
  i.number_of.append("9")
   
onto.save("/tmp/t.owl")


With this version, the relation is defined as an RDF triple. This does not mean that it is an annotation (although annotation also use a single RDF triple).

Your second version use a value restriction instead of a relation. Semantically, it is equivalent, but the direct relation is usually easier to use (and it requires fewer RDF triples).

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Property assertion instead of individual annotation

jayson
You are right, there have been typos in the proposed examples.

Thanks for the working example and the hint with the restriction and relation.

Is there an explicit way to add an annotation using owlready2?

Thank you for taking the time!

Best regards,
jayson
Reply | Threaded
Open this post in threaded view
|

Re: Property assertion instead of individual annotation

Jiba
Administrator
Yes, you can both create new annotation classes, and new annotation relations.

Please refer to the doc here : https://owlready2.readthedocs.io/en/latest/annotations.html

Jiba