Bug with .individuals()

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

Bug with .individuals()

Stefan
Hi,

I found a bug with the .individuals() method. If you try to list all individuals from an ontology, and you have an individual with the same name as its class, you get a stack overflow.

Python code and ontology to reproduce the issue:

import owlready2 as or2

o = or2.get_ontology("< PATH TO ONTOLOGY >").load()

for ind in o.individuals():
    print(ind.name)


<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.semanticweb.org/stlu/ontologies/2019/1/untitled-ontology-108#"
     xml:base="http://www.semanticweb.org/stlu/ontologies/2019/1/untitled-ontology-108"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:www="http://www.example.com/#"
     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#"
     xmlns:untitled-ontology-108="http://www.semanticweb.org/stlu/ontologies/2019/1/untitled-ontology-108#">
    <owl:Ontology rdf:about="http://www.example.com/"/>
   


   

   


   

    <owl:Class rdf:about="http://www.example.com/#A"/>
   


   

    <owl:Class rdf:about="http://www.example.com/#B">
        <rdfs:subClassOf rdf:resource="http://www.example.com/#A"/>
    </owl:Class>
   


   

   


   

    <owl:NamedIndividual rdf:about="http://www.example.com/#B">
        <rdf:type rdf:resource="http://www.example.com/#B"/>
    </owl:NamedIndividual>
   


</rdf:RDF>






Reply | Threaded
Open this post in threaded view
|

Re: Bug with .individuals()

Jiba
Administrator
Hi,

The problem is caused by the following part of the ontology:

    <owl:NamedIndividual rdf:about="http://www.example.com/#B">
        <rdf:type rdf:resource="http://www.example.com/#B"/>
    </owl:NamedIndividual>

This means that B is an instance of itself. In OWL, whether the class B is the same entity as the individual B is not clear -- most tools and reasoners consider that it is not, but when using punning, it is.

In Owlready, I chosed to identify an entity by its IRI. This means that two distinct entities cannot share the same IRI. This is consistent with the typeless nature of Python.

A consequence is that you should avoid having different entities with the same IRI. Owlready tries its best to merge such entities, but in this case, they cannot be merged without causing an infinite cycle of "instance-of" relation.

Hope this help,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Bug with .individuals()

Stefan
Thank you, noted.

It might be a good idea to have some kind of check for this to produce an error message, it took quite some time for me to track the problem down.