Trying to create triples between two instances, but...

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

Trying to create triples between two instances, but...

Luis Antonio Rodriguez
Hi,

I'm trying to load an owl existent file and create new instances and triples between two instances using existent Object Properties.

My code:

from owlready2 import*

flight_plan_ontology = get_ontology("/home/rodriguez/Desktop/TesteAnimadoInserindoInstancias.owl")
flight_plan_ontology.load()

plano1 = flight_plan_ontology.Flight_Plan_BR("Plano_Teste")

flight_plan_ontology.save("/home/rodriguez/Desktop/TesteAnimadoInserindoInstancias.owl")

print(list(flight_plan_ontology.individuals()))# At this point "Plano_Teste" exists and appears when listing individuals

flight_plan_ontology.Plano_Teste.departureAirport = flight_plan_ontology.SBGL#trying to create a relationship between two #individuals : "Plano_Teste" and "SBGL" using the ObjProperty "departureAirport"

print(flight_plan_ontology.search(type = flight_plan_ontology.Flight_Plan_BR, departureAirport = flight_plan_ontology.SBGL))#trying to find the matching individual

print("%%%%%%%%")

Shell results presents all individuals including Plano_Teste but presents empty for the search method.

Why python doesn't create the relation : flight_plan_ontology.Plano_Teste.departureAirport = flight_plan_ontology.SBGL?

I've opened the ontology with Protegé and the triple is really not there.

What is happening?
Reply | Threaded
Open this post in threaded view
|

Re: Trying to create triples between two instances, but...

Luis Antonio Rodriguez
Hi, code works, the fact is:

The names of python variables are the same names of the OWL Individuals.

So the parameters of the code to create a relation are the python variables my_drug = Drug("Ibuprofeno")

But and when we want to make a relation with existing Individuals which we don't need to create?
Reply | Threaded
Open this post in threaded view
|

Re: Trying to create triples between two instances, but...

Jiba
Administrator
Hi,

Could you verify that flight_plan_ontology.SBGL exists and is really an individual (not a class)?

You can add these lines in Python for verifying it:

print(flight_plan_ontology.SBGL)
print(flight_plan_ontology.SBGL.__class__) # owlready2.entity.ThingClass means it is a class

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Trying to create triples between two instances, but...

Luis Antonio Rodriguez
Hi Jiba, very thanks for answering,

Everything works, but I have a suggestion:

The 0.37 online documentation presents the same name for the instances and for the python variables:

>>> my_drug = Drug("my_drug")

>>> acetaminophen = Ingredient("acetaminophen")

>>> my_drug.has_for_ingredient = [acetaminophen]

I've implemented different names for both and I was using the name of the instance as a parameter and I should use the python variable, when I've done this way, it has worked. This situation could be highlighted at the official documentation to guide new users like me to avoid that!!  :-)

I'm keeping programming!

Thanks.