I want to solve the famous zebra puzzle by A. Einstein with the help of semantic web tools for python, preferably owlready .
The starting point are two owl-files linked in https://github.com/RDFLib/OWL-RL/issues/3. The first one (XML-syntax) works as expected. The second one (different author, n3 turtle syntax) fails to load or only loads "partially" in owlready. For easier comprehension of my steps I documented them in this notebook: https://github.com/cknoll/demo-material/blob/main/expertise_system/einstein-zebra-puzzle-owlready-solution-attempt.ipynb.
<Edit1> For better reference I include the essential part of the notebook:
import os
import owlready2 as owl2
data_path = "ontology_data"
path2 = os.path.join(data_path, "zebra.n3.txt") # original turtle syntax
path2 = os.path.join(data_path, "zebra.n3.txt.xml") # created with ontospy
onto = owl2.get_ontology(path2).load()
list(onto.classes()) # -> empty list -> loading seems to have failed
# now try xml syntax
# create a new world
owl2.default_world = owl2.World()
onto = owl2.get_ontology(path2x).load()
list(onto.classes()) # -> expected result
list(onto.properties()) # -> expected result
onto.hasPet # -> expected result
# unexpected/wrong:
onto.individuals # -> empty list
list(onto.livesIn.get_relations()) # -> KeyError
</Edit1>
Conclusion: I can load the XML-version of this ontology but I cannot confirm that the concepts are defined as owl:oneOf
-objects nor can find where assertions like
:Norwegian :livesIn :House1 .
:Norwegian :livesIn [ :isNextTo [ :hasColor :Blue ] ] .
ended up.
I would be glad for some hints.
(I think, once the ontology is correctly represented the solution could be obtained via something like sync_reasoner_pellet(infer_property_values=True, infer_data_property_values=True))