Handling multiple ontologies

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

Handling multiple ontologies

dguidi
Hello,

I have 2 ontologies:
- Ontology 1 contains a class A with property has_title and the individual 'a' 'has_title' 'title1'.
- Ontology 2 (with different base IRI) contains class B with property has_title and individual 'b' 'has_title' 'title2'.

If I load Ontology1 and then print the individual value, I get:

print(onto1.a.has_title) -> 'title1' (correct)

Now, if after loading Ontology1, I load Ontology2 (which contains a has_title property with different base IRI), I get:

print(onto1.a.has_title) -> None (?)
print(onto2.b.has_title) -> title2 (correct)

If I invert the load order, then the opposite is true:

print(onto1.a.has_title) -> title1 (correct)
print(onto2.b.has_title) -> None (?)

Is this behaviour expected?
If so, can I somehow set the namespace beforehand and keep using this syntax?

Many thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Handling multiple ontologies

Jiba
Administrator
Hi,

Both ontologies 1 and 2 have a "has_title" property, there is thus a name clash here. Owlready uses the last loaded property. Consequently, after loading ontology 2, "onto1.a.has_title" actually refer to has_title from ontology 2 and no longer from ontology 1.

To prevent name clash, you can either :

1) use the alternate syntax "onto1.has_title[onto1.a]"

or :

2) give a different name in Python to the properties, e.g. :

onto1.has_title.python_name = "has_title1"
onto2.has_title.python_name = "has_title2"
print(onto1.a.has_title1)

Jiba