Problem with inferring classes caused by logical operators

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

Problem with inferring classes caused by logical operators

jayson
Hello together,

I cannot infer a class (consecutive), and I have the feeling that is has to do with logical operators.

There are the three classes:

(1)
class Rupture(Ieffect):
    equivalent_to = [Ieffect &
                          (effect_of_deviation.some(HighPressure) &
                          effect_involves.some(unit_ontology.PressurizedContainment))]

(2)
class BrittleFracture(Ieffect):
     equivalent_to = [Ieffect &
                           (effect_of_deviation.some(LowTemperature) &
                           effect_involves.some(unit_ontology.PressurizedContainment))]


(3a)
class LOC(Ieffect):
     equivalent_to = [Rupture | BrittleFracture]

(3b)
class LOC(Ieffect):
     equivalent_to = [Rupture]


Base on a specific INPUT the class (1) is inferred by the reasoner. Thus, when using the definition (3a) "LOC" is not inferred. If I use the class definition (3b), "LOC" is inferred, because "Rupture" (3a) was inferred. But definition (3b) is not complete.

For my understanding the definition in 3a should work, but is not. Did I understand something wrong using logical operators? Or do you need more details regarding the problem?


Thanks in advance.

Best regards
Jayson
Reply | Threaded
Open this post in threaded view
|

Re: Problem with inferring classes caused by logical operators

Jiba
Administrator
Hi,

I tested your problem with the script below.

The individual i is reclassed as an instance of Rupture, but not a (direct) instance of LOC (as you expected, if I understood well). This is because the Rupture class itself is reclassed as a child class of LOC (due to the union).

As a consequent, the individual is an instance of LOC, but indirectly.

Jiba

----8<---------

from owlready2 import *

onto = get_ontology("http://test.org/onto.owl")
with onto:
  class Ieffect(Thing): pass
  class effect_of_deviation(Thing >> Thing): pass
  class effect_involves(Thing >> Thing): pass
  class HighPressure(Thing): pass
  class LowTemperature(Thing): pass
  class PressurizedContainment(Thing): pass
 
  class Rupture(Ieffect):
    equivalent_to = [
      Ieffect & (effect_of_deviation.some(HighPressure) & effect_involves.some(PressurizedContainment))
    ]
   
  class BrittleFracture(Ieffect):
     equivalent_to = [
       Ieffect &(effect_of_deviation.some(LowTemperature) & effect_involves.some(PressurizedContainment))
     ]

  class LOC(Ieffect):
    equivalent_to = [Rupture | BrittleFracture]

  i = Ieffect(effect_of_deviation = [HighPressure()], effect_involves = [PressurizedContainment()])


sync_reasoner()

assert isinstance(i, Rupture)
assert isinstance(i, LOC)

Reply | Threaded
Open this post in threaded view
|

Re: Problem with inferring classes caused by logical operators

jayson
Hi,

thank you so much for testing the example.

I think I understand what you mean, but what is the consequence of it?
Can I infer this (indirect) instance)? I need a way to infer this "LOC" as a consequence
of "Rupture"?

Or is there a different way to model it? (I could model the same coherences from Rupture and Brittlefracture in LOC, but I have the feeling that it is redundant and could be inherited)

Thanks in advance.

Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Problem with inferring classes caused by logical operators

Jiba
Administrator
Hi,

You can use isinstance(i, LOC) to test if i inherits from LOC.

You can also get all classes inherited by i as follows:

ancestors = set()
for c in i.is_a:
    if isinstance(c, ThingClass):
        ancestors.update(c.ancestors())
print(ancestors)

It will include LOC.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Problem with inferring classes caused by logical operators

jayson
Hi Jiba,

thank you a lot, that solved my issues completely.

Best regards
jayson