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