dice-group / owlapy

OWLAPY is a Python Framework for creating and manipulating OWL Ontologies.
MIT License
16 stars 1 forks source link

Catching instances of owl:Nothing #71

Closed Demirrr closed 3 weeks ago

Demirrr commented 3 weeks ago
from owlapy.owl_reasoner import SyncReasoner
from owlapy.class_expression import OWLClass
from owlapy.owl_individual import OWLNamedIndividual
from owlapy.iri import IRI

ontology_path = "KGs/Family/father.owl"
hermit  = SyncReasoner(ontology=ontology_path, reasoner = "HermiT")

thing=OWLClass(IRI('http://www.w3.org/2002/07/owl#', 'Thing'))
nothing=OWLClass(IRI('http://www.w3.org/2002/07/owl#', 'Nothing'))
print(nothing.iri.as_str())
print(hermit.instances(nothing))

Throws the following error

Traceback (most recent call last): File "ManchesterOWLSyntaxClassExpressionParser.java", line 53, in org.semanticweb.owlapi.manchestersyntax.parser.ManchesterOWLSyntaxClassExpressionParser.parse Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/cdemir/Desktop/Softwares/owlapy/temp.py", line 12, in <module>
    print(hermit.instances(nothing))
  File "/home/cdemir/Desktop/Softwares/owlapy/owlapy/owl_reasoner.py", line 1233, in instances
    mapped_ce=self.mapper.map_(ce)
  File "/home/cdemir/anaconda3/envs/temp_owlapy/lib/python3.10/functools.py", line 926, in _method
    return method.__get__(obj, cls)(*args, **kwargs)
  File "/home/cdemir/Desktop/Softwares/owlapy/owlapy/owlapi_mapper.py", line 154, in _
    return self.parser.parse(owl_expression_to_manchester(e))
org.semanticweb.owlapi.manchestersyntax.renderer.org.semanticweb.owlapi.manchestersyntax.renderer.ParserException: org.semanticweb.owlapi.manchestersyntax.renderer.ParserException: Encountered Nothing at line 1 column 1. Expected one of:
    Class name
    Object property name
    Data property name
    inverse
    not
    (
    {
Demirrr commented 3 weeks ago

Using nothing doesn't seem to work

# hasChild a nothing.
assert hermit.instances(OWLObjectSomeValuesFrom(property=hasChild, filler=nothing))==eval("{OWLNamedIndividual(IRI('http://example.com/father#', 'michelle')), OWLNamedIndividual(IRI('http://example.com/father#', 'heinz')))}")
alkidbaci commented 3 weeks ago

This got fixed. There was a Manchester rendering & parsing issue for owl:Nothing. Btw you can use OWLNothing and OWLThing instead of declaring them from scratch.

from owlapy.class_expression import OWLNothing, OWLThing
Demirrr commented 3 weeks ago

Great thank you!

Demirrr commented 3 weeks ago

hermit.instances(OWLNothing.get_object_complement_of()) doesnt seem to work :(

alkidbaci commented 3 weeks ago

This is now fixed fixed! PR: #73