Using owlready2 I can create properties for my ontology, as below:
with onto:
class Drug(Thing):
pass
class Ingredient(Thing):
pass
relation_name = "has_for_ingredient"
with onto:
NewProperty = types.new_class(relation_name, (ObjectProperty, FunctionalProperty))
NewProperty.domain = domain
NewProperty.range = range
I can see them using list(onto.properties()). Now I want to create relations using the code below (in my actual code this will be done dynamically):
my_drug = Drug("my_drug")
acetaminophen = Ingredient("acetaminophen")
my_drug.has_for_ingredient = [acetaminophen]
but I get the error:
AttributeError: 'list' object has no attribute 'storid'
I have also tried to create the property using only ObjectProperty, without FunctionalProperty, but get the error:
AttributeError: 'int' object has no attribute 'namespace'
Using the documentation I could not figure what is the issue... And also, what is the meaning of using the FunctionalProperty?
with onto:
NewProperty = types.new_class(relation_name, (ObjectProperty, ))
NewProperty.domain = [Drug]
NewProperty.range = [Ingredient]
was the way to go. Whereas:
with onto:
NewProperty = types.new_class(relation_name, (ObjectProperty))
...
thorws the AttributeError: 'list' object has no attribute 'storid'
Apparently a tuple is required to create the property dynamically.