[SOLVED] Rules: Could not invoke method in if() with Double?

Hi there,

I’ve got the following script:

when                                                                                                                                                           
    Item Snips_Intent received update                                                                                                                          
then                                                                                                                                                           
                                                                                                                                                               
  var Double confid = transform("JSONPATH", "$.intent.confidenceScore", Snips_Intent.state.toString)                                                           
  logInfo("snips.rule", "Confidence too low" + confid)                                                                                                         
  if (confid < 0.8) {                                                                                                                                          
     logInfo("snips.rule", "Confidence too low" + confid)                                                                                                      
     return                                                                                                                                                    
  } 
...

And while outputting the number works, I get the following error for the if condition:

2019-03-17 13:27:14.721 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Snips’: An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.DoubleExtensions.operator_lessThan(double,double) on instance: null

What am I doing wrong?

confid is probably a string. Maybe you should parse the JSON output.

How do you mean? The log line says that it’s null

No, the log says that it’s having trouble invoking a comparison.

My original concern was because I understood transforms to return a string (which could of course be “1.5” etc.), and so requiring a parseFloat or similar to be treated as a number.

Looking at the error again, it does seem to realize that confid is supposed to be a Double. Maybe it’s the constant 0.8 that it can’t treat as Double, I don’t know.

A smarter man than me offers the advice to always try to use type Number in rules DSL, to avoid problems, so I’d begin with that. Rules DSL is not pure java.
var Number confid =

I’m getting the same output using Number…

var Number confid = Float::parseFloat(transform(“JSONPATH”, “$.intent.confidenceScore”, Snips_Intent.state.toString))

1 Like

Great thanks, that worked!