enter a loop when printing individual name when reason is enabled.

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

enter a loop when printing individual name when reason is enabled.

ernest.tam@ontologicalemf.com
With reasoner enabled, the generator self.world.individuals() will enter a loop after printing the first individual. The code snippet is shown below:
---> 33         for each_global_individual in self.world.individuals():
     34             print(each_global_individual.name)

Output is shown below (the system hang after print the first individual name)
individuals are as below:
CapitalCity

The reasoner is enabled by the following code.
sync_reasoner_pellet(self.world, infer_property_values=True, infer_data_property_values=True)

When I commented out the above reasoner line, it worked fine.

When I hit ctrl C, it will print the following exception:
Traceback (most recent call last):
  File "/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.9/site-packages/owlready2/namespace.py", line 638, in _get_by_storid
    return self._load_by_storid(storid, full_iri, main_type, main_onto, default_to_none)
  File "/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.9/site-packages/owlready2/namespace.py", line 643, in _load_by_storid
    with LOADING:
  File "/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.9/site-packages/owlready2/util.py", line 298, in __enter__
    def __enter__(self): self.level.set(self.level.get() + 1)
RecursionError: maximum recursion depth exceeded while calling a Python object

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.9/site-packages/owlready2/namespace.py", line 638, in _get_by_storid
    return self._load_by_storid(storid, full_iri, main_type, main_onto, default_to_none)
  File "/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.9/site-packages/owlready2/namespace.py", line 760, in _load_by_storid


Thanks for your time looking into my issue. When I get familiar with this project, should check out the source code to see whether I can debug it.
Reply | Threaded
Open this post in threaded view
|

Re: enter a loop when printing individual name when reason is enabled.

Jiba
Administrator
Hello,

Can you send me your ontology, for reproducing the problem please?

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

Re: enter a loop when printing individual name when reason is enabled.

ernest.tam@ontologicalemf.com
I tried the button clicks "More > Upload a file > Choose File > Upload file" and it doesn't work.

Hence, I uploaded to my web site. Here is link http://vehorg.com/external/owlready_question.zip. Feel free to download my ontology file for debugging.

The following is my code snippet to reproduce the problem:

from owlready2 import *

if __name__ == "__main__":
    onto_file = "/home/ernest/Downloads/bespoke_travel_ontology.owl"
    prefix = "http://www.vehorg.com/2024/04/bespoke_travel#"
    world = World()
    world.get_ontology(onto_file).load()
    # avoid duplicated ontology
    # self.world.set_backend()  # owlready2 will automatically update quadstore.
    # use inference engine
    sync_reasoner_pellet(
        world, infer_property_values=True, infer_data_property_values=True
    )
    for each_global_individual in world.individuals():
        print(each_global_individual.name)
    print("=" * 60)
Reply | Threaded
Open this post in threaded view
|

Re: enter a loop when printing individual name when reason is enabled.

ernest.tam@ontologicalemf.com
Are you able to reproduce m problem? Just checking.
Reply | Threaded
Open this post in threaded view
|

Re: enter a loop when printing individual name when reason is enabled.

Jiba
Administrator
Yes, I finally found the problem: it was caused by an individual belonging to several classes with one of these classes having a OneOf construct including that individual. This creates a kind of cycle, thus leading to an infinite loop.

I have fixed the problem in the development version of Owlready on Bitbucket, and I was able to run your example successfully with the fix!

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: enter a loop when printing individual name when reason is enabled.

ernest.tam@ontologicalemf.com
Great! I am building a model driven knowledge graph for my LLM. Hence, an instance may belong to multiple classes.

When my level 4 conversation AI is up, I will use the SPARQL of owlready2 to answer questions. Thanks again. I love owlready2.