Stop generating instance name with number

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

Stop generating instance name with number

Irfan Khan Tanoli
Hi,

import owlready
from owlready import *

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

class Drug(Thing):
        ontology = onto
class DrugAssociation(Drug):
        pass
print(DrugAssociation.is_a)
output: [onto.Drug]

my_drug = Drug("my_drug")
print(my_drug)
output: my_drug

my_drug1=Drug("my_drug")
print(my_drug1)
output: my_drug_2

how can i stop this  number generating instance number  i.e. my_drug_2

I want second output same like previous one i.e. my_drug only not my_drug_2

Please reply soon.
Reply | Threaded
Open this post in threaded view
|

Re: Stop generating instance name with number

Jiba
Administrator
Hello,

You cannot have two distinct instances with the same IRI. This is a requirement in OWL ontologies.

However, you can give a label to each instance, and then you can show them using their labels instead that using their IRI (by default, the name shown is the end of the IRI).

To define the label, do as following:

        my_drug.label = ["my_drug"]

Then to make Owlready 2 display instances using their labels:

        def render(entity):
                label = entity.label.first()
                if label: return label
                return entity.name

        set_render_func(render)


Best regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13