protegeproject / swrlapi

Java API for working with the SWRL rule and SQWRL query languages
Other
99 stars 40 forks source link

`swrlb:divide` built-in fails with decimal arguments #39

Open LorenzBuehmann opened 6 years ago

LorenzBuehmann commented 6 years ago

Reported first on StackOverflow.

Setup

Protege 5.2.0 SWRLTab Protege Plugin 2.0.5

Problem

Using swrlb:divide seems to fail during some weird numeric conversions, see this standalone SQWRL query

swrlb:divide(?r, 5.0, 3.0) -> sqwrl:select(?r)

Exception:

Exception running SQWRL query S1: error running SQWRL queries: error running Drools rule engine:
[Error: invoker.invoke("S1", "swrlb:divide", 0, false, new VPATH(), new BAVNs("r", "", ""), new UBA("r"), new L("5.0", "xsd:decimal"), new L("3.0", "xsd:decimal")): runtime exception thrown by built-in swrlb:divide in rule S1: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.]
[Near : {... invoker.invoke("S1", "swrlb:di ....}]
             ^
[Line: 1, Column: 1]: runtime exception thrown by built-in swrlb:divide in rule S1: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.: error running Drools rule engine:
[Error: invoker.invoke("S1", "swrlb:divide", 0, false, new VPATH(), new BAVNs("r", "", ""), new UBA("r"), new L("5.0", "xsd:decimal"), new L("3.0", "xsd:decimal")): runtime exception thrown by built-in swrlb:divide in rule S1: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.]
[Near : {... invoker.invoke("S1", "swrlb:di ....}]
             ^
[Line: 1, Column: 1]: runtime exception thrown by built-in swrlb:divide in rule S1: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.: [Error: invoker.invoke("S1", "swrlb:divide", 0, false, new VPATH(), new BAVNs("r", "", ""), new UBA("r"), new L("5.0", "xsd:decimal"), new L("3.0", "xsd:decimal")): runtime exception thrown by built-in swrlb:divide in rule S1: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.]
[Near : {... invoker.invoke("S1", "swrlb:di ....}]
             ^
[Line: 1, Column: 1]: runtime exception thrown by built-in swrlb:divide in rule S1: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.: Non-terminating decimal expansion; no exact representable decimal result.

On the other hand, probably due to different implementation, the swrlm:eval extension works, try

swrlm:eval(?r, "5.0/3.0") -> sqwrl:select(?r)

Result: "1.6666666666666667"^^xsd:double

I guess, something is different with the literal conversion, the latter seems to use xsd:double literals, while the former works with xsd:decimal - but it's just a guess. By the way, XPath also uses either xsd:int or xsd:decimal.

martinjoconnor commented 6 years ago

Thanks for the report. I will take a look at this.