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. |
Administrator
|
Hello,
Can you send me your ontology, for reproducing the problem please? Best regards, Jiba |
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) |
Are you able to reproduce m problem? Just checking.
|
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 |
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. |
Just downloaded the latest version: Successfully installed owlready2-0.46.
It is getting better which past the previous failure. However, there is a new error message as shown below: * Owlready2 * Running Pellet... java -Xmx2000M -cp /home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/jena-tdb-0.10.0.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/httpclient-4.2.3.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/antlr-runtime-3.2.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/pellet-2.3.1.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/commons-codec-1.6.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/owlapi-distribution-3.4.3-bin.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/slf4j-api-1.6.4.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/jcl-over-slf4j-1.6.4.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/aterm-java-1.6.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/log4j-core-2.19.0.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/xml-apis-1.4.01.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/log4j-api-2.19.0.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/antlr-3.2.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/slf4j-log4j12-1.6.4.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/jena-arq-2.10.0.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/log4j-1.2-api-2.19.0.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/xercesImpl-2.10.0.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/jena-core-2.10.0.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/httpcore-4.2.2.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/jena-iri-0.9.5.jar:/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/pellet/jgrapht-jdk1.5.jar pellet.Pellet realize --loader Jena --input-format N-Triples --infer-prop-values --infer-data-prop-values --ignore-imports /tmp/tmp2h20k1yy * Owlready2 * Pellet took 8.639118194580078 seconds * Owlready * (NB: only changes on entities loaded in Python are shown, other changes are done but not listed) bespoke_travel_ontology.BestDeal bespoke_travel_ontology.CostEstimation bespoke_travel_ontology.CruiseFinder bespoke_travel_ontology.LowBudgetFinder bespoke_travel_ontology.TicketFinder bespoke_travel_ontology.CapitalCity bespoke_travel_ontology.MajorCity bespoke_travel_ontology.SmallCity bespoke_travel_ontology.BigFamily bespoke_travel_ontology.CompanyEventTravel bespoke_travel_ontology.CompanyGroupTravel bespoke_travel_ontology.CompanySoloTravel bespoke_travel_ontology.FamilyWithKid bespoke_travel_ontology.ReligiousTravel bespoke_travel_ontology.RetiredCouple bespoke_travel_ontology.Solo bespoke_travel_ontology.SportTeamTravel bespoke_travel_ontology.TravelEntourage bespoke_travel_ontology.YoungCouple bespoke_travel_ontology.Summer bespoke_travel_ontology.Winter bespoke_travel_ontology.BoutiqueHotel bespoke_travel_ontology.BudgetHotel bespoke_travel_ontology.ChainHotel bespoke_travel_ontology.LuxuryHotel bespoke_travel_ontology.DomesticTravel bespoke_travel_ontology.InternationalTravel bespoke_travel_ontology.Sport bespoke_travel_ontology.Fall bespoke_travel_ontology.Spring bespoke_travel_ontology.AirTravel bespoke_travel_ontology.RailTravel bespoke_travel_ontology.RoadTravel bespoke_travel_ontology.WaterTravel bespoke_travel_ontology.Countryside bespoke_travel_ontology.FarmStay bespoke_travel_ontology.Ranch bespoke_travel_ontology.CoastalTown bespoke_travel_ontology.MountainTown bespoke_travel_ontology.TouristTown bespoke_travel_ontology.BrickAndMortar bespoke_travel_ontology.Online bespoke_travel_ontology.TravelOperator bespoke_travel_ontology.CustomizedDailyHouseKeeping bespoke_travel_ontology.CustomizedGroceryDelivery bespoke_travel_ontology.CustomizedMarketingMaterialsWithPhoto bespoke_travel_ontology.CustomizedReview bespoke_travel_ontology.Consistency bespoke_travel_ontology.Flexibility bespoke_travel_ontology.Privacy bespoke_travel_ontology.Service bespoke_travel_ontology.Space bespoke_travel_ontology.Value bespoke_travel_ontology.DemographicPreference bespoke_travel_ontology.ForeignCountryRestriction bespoke_travel_ontology.LocalStateOrCityRestriction bespoke_travel_ontology.LocalTrend bespoke_travel_ontology.LocationRestriction bespoke_travel_ontology.WeatherRestriction bespoke_travel_ontology.Arrival bespoke_travel_ontology.Departure bespoke_travel_ontology.Apartment bespoke_travel_ontology.BeachResort bespoke_travel_ontology.Cabin bespoke_travel_ontology.Condo bespoke_travel_ontology.GolfResort bespoke_travel_ontology.House bespoke_travel_ontology.Villa Traceback (most recent call last): File "/home/ernest/nomadic_bot/test_bug.py", line 14, in <module> for each_global_individual in world.individuals(): File "/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/namespace.py", line 245, in individuals i = self.world._get_by_storid(s) File "/home/ernest/miniconda3/envs/nomadicbotenv/lib/python3.10/site-packages/owlready2/namespace.py", line 645, 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.10/site-packages/owlready2/namespace.py", line 768, in _load_by_storid elif len(types) > 1: entity = FusionClass._get_fusion_class(types)(name = name, namespace = namespace, is_a = types) TypeError: FusionClass1() takes no arguments |
Today, I tried a few SPARQL query. If the relationship is too generic, I will bumped into this problem. It seems that this bug will surface in a number of different way.
|
When I get to the point which I need to fix all these issue, will download the open source and try to debug it.
|
It is confirmed that it is due to that some of my instances have equivalent classes and has abstract class.
|
Thanks for your work of owlready2. It is wonderful because I can use it for the 1st release of our Digital Travel Agent. I think my main issue is that I have too many fine grained classes and object properties. You can easily know that I am a newbie to the implementation of Ontology.
After giving a deep 2nd thought, I think I will consolidate fine-grained relationship as I can ask the type of object to know more. It seems that generic predicate will not be welcome for SPARQL. That means I will not bump into this issue so often now as I will deal with a lot of concrete relationship and classes. In case I am blocked by this issue in the future, will definitely download the source code and try to fix it. Lastly but not lease, thanks a million to your help. Have a good day. |
My further investigation showed that the main issue is due to the Enum in my Ontology. Don't do it because it will cause severe performance degradation and infinite loop in owlready2.
The Enum means that I create a class with EquivalentTo all the instances {BestDeal, CostEstimation}. As the old saying said, the C Enum is a devil to performance. |
Free forum by Nabble | Edit this page |