Reading out "nested" restritions

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

Reading out "nested" restritions

nntvi
Hello everyone,

in an important ontology there exists an individual (individual_x) with a type restriction of the following pattern:

object_property_a only (object_property_b value individual_y)

This means, that there can only exist a relation of type object_property_a between individual_x (subject) and a third individual individual_z (object), if individual_z also has a relation to individual_y of the type object_property_b.

Given individual_x read from the ontology, I can read out the information regarding this restriction using the following code (assuming the restriction is at index 0)

individual_x.is_instance_of[0] // Gives me the outer restriction
individual_x.is_instance_of[0].property // Gives me object_property_a
individual_x.is_instance_of[0].type // Type of of outer restriction (ONLY)

individual_x.is_instance_of[0].value // Gives me the inner restriction
individual_x.is_instance_of[0].value.property // Gives me object_property_b
individual_x.is_instance_of[0].value.type // Type of of inner restriction (VALUE)
individual_x.is_instance_of[0].value.value // DOES NOT EXIST

As such I am unable to get individual_y, which is however what I want.

Is there a way to get this inner value?

Thank you very much
nntvi
Reply | Threaded
Open this post in threaded view
|

Re: Reading out "nested" restritions

Jiba
Administrator
Hello,

You should be able to use .value to obtain the individual in the VALUE restriction.

I've tried with the small example below and it works well... Could you send me an example or an ontology that allows to reproduce the problem ?

Jiba

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

from owlready2 import *

onto = get_ontology("http://test.org/onto.owl")
#onto = get_ontology("/tmp/t3.owl").load()

with onto:
  class a(Thing >> Thing): pass
  class b(Thing >> Thing): pass

  class C(Thing): pass
  x = C("x")
  y = C("y")
  x.is_a.append(a.some(b.value(y)))
 
print(x.is_a[1].value.value)
Reply | Threaded
Open this post in threaded view
|

Re: Reading out "nested" restritions

nntvi
Thank you very much for your response.

I tried to implement a minimum working example using your code, and it worked. It then helped to find the issue with my code, and I was actually able to replicate it using a minimum working example showing the problem (see below).

The issue appears, when individual_y is part of a class, also titled individual_y.

Not only is the inner restriction incomplete, in fact I get a stack overflow (which probably causes the problem).

I am not sure if in OWL it is is allowed to have an individual with the same name as a class, but I think it should be.

Here is the code and the exception

== test.py

from owlready2 import *

onto = get_ontology("./test.owl").load()

with onto:
    x = Thing("individual_x")

    print(x.is_a[1].value.value)


== test.owl

<?xml version="1.0"?>
<Ontology xmlns="http://www.w3.org/2002/07/owl#"
     xml:base="http://test/restriction"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     ontologyIRI="http://test/restriction">
    <Prefix name="" IRI="http://test/restriction"/>
    <Prefix name="owl" IRI="http://www.w3.org/2002/07/owl#"/>
    <Prefix name="rdf" IRI="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
    <Prefix name="xml" IRI="http://www.w3.org/XML/1998/namespace"/>
    <Prefix name="xsd" IRI="http://www.w3.org/2001/XMLSchema#"/>
    <Prefix name="rdfs" IRI="http://www.w3.org/2000/01/rdf-schema#"/>
    <Declaration>
        <Class IRI="#individual_y"/>
    </Declaration>
    <Declaration>
        <ObjectProperty IRI="#property_a"/>
    </Declaration>
    <Declaration>
        <ObjectProperty IRI="#property_b"/>
    </Declaration>
    <Declaration>
        <NamedIndividual IRI="#individual_x"/>
    </Declaration>
    <Declaration>
        <NamedIndividual IRI="#individual_y"/>
    </Declaration>
    <Declaration>
        <NamedIndividual IRI="#individual_z"/>
    </Declaration>
    <ClassAssertion>
        <ObjectAllValuesFrom>
            <ObjectProperty IRI="#property_a"/>
            <ObjectHasValue>
                <ObjectProperty IRI="#property_b"/>
                <NamedIndividual IRI="#individual_y"/>
            </ObjectHasValue>
        </ObjectAllValuesFrom>
        <NamedIndividual IRI="#individual_x"/>
    </ClassAssertion>
    <ClassAssertion>
        <Class IRI="#individual_y"/>
        <NamedIndividual IRI="#individual_y"/>
    </ClassAssertion>
    <ObjectPropertyAssertion>
        <ObjectProperty IRI="#property_a"/>
        <NamedIndividual IRI="#individual_x"/>
        <NamedIndividual IRI="#individual_z"/>
    </ObjectPropertyAssertion>
    <ObjectPropertyAssertion>
        <ObjectProperty IRI="#property_b"/>
        <NamedIndividual IRI="#individual_z"/>
        <NamedIndividual IRI="#individual_y"/>
    </ObjectPropertyAssertion>
</Ontology>


== EXCEPTION

Current thread 0x00003b20 (most recent call first):
  File "D:\test\venv\lib\site-packages\owlready2\triplelite.py", line 655 in _get_obj_triples_sp_co
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 545 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 539 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 537 in _get_by_storid
  File "D:\test\venv\lib\site-packages\owlready2\namespace.py", line 557 in _load_by_storid
  ...

Process finished with exit code -1073740791 (0xC0000409)
Reply | Threaded
Open this post in threaded view
|

Re: Reading out "nested" restritions

Jiba
Administrator
> I am not sure if in OWL it is is allowed to have an individual with the same name as a class, but I think it should be.

This is known as "punning"; some tools support it and some other don't, and Owlready does not support punning currently. Reasoners accept it, but does not take it into account for reasoning.

Jiba