Creating realtion between instances and the relation is in another namespace

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

Creating realtion between instances and the relation is in another namespace

rami_dhouib
So I have 2 instances : instance 1 and instance 2 how to create a relation between them when the relation is in another instance
Such a code yields an error:
ns1 = onto.get_namespace("http://www.ns1.org/")

class Class1(Thing):
    pass

class Class2(Thing):
    pass

inst1 = Class1("inst1")
inst2 = Class2("inst2")

# Access the property from the other namespace
property = ns1.relation

# Add the relation between the instances
inst1.property.append(inst2)
Reply | Threaded
Open this post in threaded view
|

Re: Creating realtion between instances and the relation is in another namespace

Jiba
Administrator
Hi,

First, you should not create your classes outside a "with onto:" block, otherwise they are not defined in a proper ontology.

Then, "property = ns1.relation" does not define a property for future use of ".property". Owlready automatically support ".property" notation, but you need to use the name of the property in OWL (in your example, it seems to be "relation"). If the name is not valid in Python, you can change it by setting the annotation "python_name" on the property.

jiba