Pellet Rule Reasoning Error: Could not translate SWRL Atom D-Object

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

Pellet Rule Reasoning Error: Could not translate SWRL Atom D-Object

Lukas
I try to reason over Errors and want to reason that i have a TimeRelated Error, but cannot get the SWRL Rules to work:
from datetime import timedelta

from owlready2 import *

onto = get_ontology("http://test.org/onto.owl")


with onto:
    class Error(Thing):pass
    class timerange_start_at(Error >> datetime.datetime, FunctionalProperty):
        python_name = "start"
    class timerange_end_at(Error >> datetime.datetime, FunctionalProperty):
        python_name = "end"
    class error_at(Error >> datetime.datetime, FunctionalProperty):
        python_name = "appeared"
    class is_after_start(Error >> bool, FunctionalProperty) : pass
    class is_before_end(Error >> bool, FunctionalProperty): pass

    class TimeRangeRelatedError(Error):
        equivalent_to = [Error & is_after_start & is_before_end]

    rule1 = Imp()
    rule1.set_as_rule("""Error(?d), timerange_start_at(?d, ?s), error_at(?d, ?b), greaterThan(?s, ?b) -> is_after_start(?d)""")
    rule2 = Imp()
    rule2.set_as_rule("""Error(?d), timerange_end_at(?d, ?e), error_at(?d, ?b), lessThan(?e, ?b) -> is_before_end(?d)""")


current = datetime.datetime.now()
start = current - timedelta(days=1)
end = current + timedelta(days=1)


error = Error(start = start, end = end, appeared = current)

close_world(Error)

print("Error old Classes:", error.__class__)

onto.save(file="C:/Users/---/PycharmProjects/owlreasoner/rules.owl")

sync_reasoner_pellet(infer_property_values = True, infer_data_property_values = True)

print("Error new Classes:", error.__class__)

I geht the following error:

  File "C:/Users/---/PycharmProjects/owlreasoner/__main__.py", line 41, in <module>
    sync_reasoner_pellet(infer_property_values = True, infer_data_property_values = True)
  File "C:\Users\---\AppData\Local\Programs\Python\Python36\lib\site-packages\owlready2\reasoning.py", line 244, in sync_reasoner_pellet
    raise OwlReadyJavaError("Java error message is:\n%s" % (e.stderr or b"").decode("utf8"))
owlready2.base.OwlReadyJavaError: Java error message is:
[main] WARN org.apache.jena.riot.RDFLanguages - java-jsonld classes not on the classpath - JSON-LD input-output not available.
[main] WARN org.apache.jena.riot.RDFLanguages - Minimum jarfiles are jsonld-java, jackson-core, jackson-annotations
[main] WARN org.apache.jena.riot.RDFLanguages - If using a Jena distribution, put all jars in the lib/ directory on the classpath
[main] WARN org.semanticweb.owlapi.util.SAXParsers - http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit not supported by parser type org.apache.xerces.jaxp.SAXParserImpl
[main] WARN org.semanticweb.owlapi.util.SAXParsers - entityExpansionLimit not supported by parser type org.apache.xerces.jaxp.SAXParserImpl
[main] WARN org.semanticweb.owlapi.util.SAXParsers - http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit not supported by parser type org.apache.xerces.jaxp.SAXParserImpl
[main] WARN org.semanticweb.owlapi.util.SAXParsers - entityExpansionLimit not supported by parser type org.apache.xerces.jaxp.SAXParserImpl
Could not translate SWRL Atom D-Object
Use -v for detail.
Reply | Threaded
Open this post in threaded view
|

Re: Pellet Rule Reasoning Error: Could not translate SWRL Atom D-Object

Lukas
My Rule was wrong, here is the correct one, just as example for others, lessThan/greaterThan will be only called if return value is true, than return xsd:boolean true.

from datetime import timedelta

from owlready2 import *

onto = get_ontology("http://test.org/onto.owl")


with onto:
    class Error(Thing):
        def who(self):
            print("Error")
    class timerange_start_at(Error >> datetime.datetime, FunctionalProperty):
        python_name = "start"
    class timerange_end_at(Error >> datetime.datetime, FunctionalProperty):
        python_name = "end"
    class error_at(Error >> datetime.datetime, FunctionalProperty):
        python_name = "appeared"
    class is_after_start(Error >> bool, FunctionalProperty) : pass
    class is_before_end(Error >> bool, FunctionalProperty): pass

    class TimeRangeRelatedError(Error):
        equivalent_to = [Error & is_after_start.value(True) & is_before_end.value(True)]
        def who(self):
            print("TimeRange")

    rule1 = Imp()
    rule1.set_as_rule("""Error(?d), timerange_start_at(?d, ?s), error_at(?d, ?b), greaterThan(?b, ?s) -> is_after_start(?d, true)""")
    rule2 = Imp()
    rule2.set_as_rule("""Error(?d), timerange_end_at(?d, ?e), error_at(?d, ?b), lessThan(?b, ?e) -> is_before_end(?d, true)""")

onto.save(file="C:/Users/----/PycharmProjects/owlreasoner/rules.owl")

current = datetime.datetime.now()
start = current - timedelta(days=1)
end = current + timedelta(days=1)


error = Error(start = start, end = end, appeared = current)


error.who()



sync_reasoner_pellet(infer_property_values = True, infer_data_property_values = True)


error.who()