0

It seems SWRL divide function does not accept decimal . this is my query:

universityproject:professor(?x) ^ universityproject:has_height(?x, ?h) ^ universityproject:has_weight(?x, ?w) ^ swrlb:pow(?phm, ?h, 2) ^ swrlb:divide(?res, ?w, ?phm) ^ swrlb:greaterThan(?res, 30) -> sqwrl:select(?x, ?h, ?w, ?phm)

this is output error in protege sqwrl tab:

Exception running SQWRL query S12: error running SQWRL queries: error inserting asserted OWL axioms into Drools:
[Error: invoker.invoke("S12", "swrlb:divide", 1, false, new VPATH($h), new BAVNs("res", "w", "phm"), new UBA("res"), $w, $phm): runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.]
[Near : {... invoker.invoke("S12", "swrlb:d ....}]
             ^
[Line: 1, Column: 1]: runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.: Non-terminating decimal expansion; no exact representable decimal result.: error inserting asserted OWL axioms into Drools:
[Error: invoker.invoke("S12", "swrlb:divide", 1, false, new VPATH($h), new BAVNs("res", "w", "phm"), new UBA("res"), $w, $phm): runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.]
[Near : {... invoker.invoke("S12", "swrlb:d ....}]
             ^
[Line: 1, Column: 1]: runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.: Non-terminating decimal expansion; no exact representable decimal result.: [Error: invoker.invoke("S12", "swrlb:divide", 1, false, new VPATH($h), new BAVNs("res", "w", "phm"), new UBA("res"), $w, $phm): runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.]
[Near : {... invoker.invoke("S12", "swrlb:d ....}]
             ^
[Line: 1, Column: 1]: runtime exception thrown by built-in swrlb:divide in rule S12: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.: Non-terminating decimal expansion; no exact representable decimal result.

How can i do a decimal division in swrl syntax?

alex
  • 7,551
  • 13
  • 48
  • 80
  • That is the correct syntax. According to [the SWRL W3C submssion](https://www.w3.org/Submission/SWRL/) and given that the `divide` function is based on the [XPath function](https://www.w3.org/TR/xpath-functions/#func-numeric-divide), it should work perfectly for decimals. Can you check the intermedia results? Anyways, if the divisor isn't zero I guess this is a simply a bug. You should raise an issue on the Github project page – UninformedUser Aug 14 '17 at 14:19
  • 1
    As a workaround, you could try to use the `eval` function: `swrlm:eval(?res, "(w / phm)", ?w, ?phm)` – UninformedUser Aug 14 '17 at 14:21
  • Thanks, ill try it – alex Aug 15 '17 at 08:31

0 Answers0