Creating a relation with property from other ontology

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

Creating a relation with property from other ontology

Mome
Dear all,

I am working with several ontologies, but I am new to owlready. I can't wrap my head around the ways to assert a relation when the resources, particularly the property, are defined in a second or several other ontologies. The main way to assert a relation seems to be setting the attribute on the subject instance with the same name as the property. But how can I make sure that the property in the relation triple has the correct IRI?

"""Example: I am manipulating onto1 using ressources from onto2"""

onto1 = get_ontology(iri)
onto2 = get_ontology("file://...").load()
onto1.imported_ontologies.append(onto2)

with onto1:
    simulator = onto2.Simulator_FSI("my_fsi")   # no problem with individuals
    sim = onto2.Structural_Mechanics_Simulation("my_sim")
    # trying to assert triple (onto1.simulator, onto2.conductsSimulation, onto1.sim)
    # but can't use "onto2." to access correct property, so gets a different attribute
    simulator.conductsSimulation = [sim]

print(list(onto2.conductsSimulation.get_relations()))  # prints []

Many thanks for ideas and clarification.
Best, Mo
Reply | Threaded
Open this post in threaded view
|

Re: Creating a relation with property from other ontology

Mome
Hi,

it works with

onto1._add_obj_triple_spo(simulator.storid, onto2.conductsSimulation.storid, sim.storid)

but if there is another way please let me know.

Best, Mo
Reply | Threaded
Open this post in threaded view
|

Re: Creating a relation with property from other ontology

Jiba
Administrator
Hi,

If the "conductsSimulation" property exists in only one ontology, you can do as usual:

simulator.conductsSimulation.append(sim)

The fact that the property is defined in another ontology is not a problem at all.

If the "conductsSimulation" property exists in both ontologies, it is more tricky because Owlready will use one of the property by default (and possibly not the one you would expect). In that case, you can use the following alternate syntax :

onto2.conductsSimulation[simulator].append(sim)

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Creating a relation with property from other ontology

Mome
Hi Jiba,

I get it, thanks a lot. Getting better day by day.

Best, Mo