fuzzylite operands number error . logical operator <and> expects two operands, but found <3>

StackOverflow https://stackoverflow.com/questions/22228069

  •  10-06-2023
  •  | 
  •  

Question

in fuzzylite API , when i define a rule with more than 2 operator(i am not sure), i receive below error :

 03-06 17:19:49.155: W/System.err(712): java.lang.RuntimeException: [syntax error] logical operator <and> expects two operands, but found <3>

my rules are like to :

    RuleBlock ruleBlock = new RuleBlock();
                     ruleBlock.addRule(Rule.parse("if chestpain is TYPIC and restpress is MIN and serum is MINLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and maxrate is MINRATE and restrate is LOWRATE then angin  is MILD", engine));
                     ruleBlock.addRule(Rule.parse("if chestpain is ASYMPTOMATIC and restpress is MIN and serum is MAXLEVEL and smoke is LOWPOSSIBILITY and sugar is LEVELNO and  maxrate is MINRATE and restrate is HIGHRATE then angin is MASSIVE", engine));

the complete error message is :

03-06 17:19:49.155: W/System.err(712): java.lang.RuntimeException: [syntax error] logical operator <and> expects two operands, but found <3>
03-06 17:19:49.155: W/System.err(712):  at com.fuzzylite.rule.Antecedent.load(Unknown Source)
03-06 17:19:49.155: W/System.err(712):  at com.fuzzylite.rule.Rule.parse(Unknown Source)
03-06 17:19:49.155: W/System.err(712):  at com.example.trsa.RAP1$4.onClick(RAP1.java:253)
03-06 17:19:49.155: W/System.err(712):  at android.view.View.performClick(View.java:2485)
03-06 17:19:49.155: W/System.err(712):  at android.view.View$PerformClick.run(View.java:9080)
03-06 17:19:49.165: W/System.err(712):  at android.os.Handler.handleCallback(Handler.java:587)
03-06 17:19:49.165: W/System.err(712):  at android.os.Handler.dispatchMessage(Handler.java:92)
03-06 17:19:49.165: W/System.err(712):  at android.os.Looper.loop(Looper.java:123)
03-06 17:19:49.165: W/System.err(712):  at android.app.ActivityThread.main(ActivityThread.java:3683)
03-06 17:19:49.165: W/System.err(712):  at java.lang.reflect.Method.invokeNative(Native Method)
03-06 17:19:49.165: W/System.err(712):  at java.lang.reflect.Method.invoke(Method.java:507)
03-06 17:19:49.175: W/System.err(712):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-06 17:19:49.186: W/System.err(712):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-06 17:19:49.186: W/System.err(712):  at dalvik.system.NativeStart.main(Native Method)
Was it helpful?

Solution

This questions was answered in http://www.fuzzylite.com/forums/topic/logical-operators-grammers-error-in-numbers-of-operands/

Specifically, the problem is in rule:

if (chestpain is ASYMPTOMATIC or restpress is MAX or serum is MAXLEVEL) and (smoke is LOWPOSSIBILITY or sugar is LEVELNO or minrate is MINRATE or restrate is HIGHRATE) then angin is MASSIVE

where you refer to minrate, but you have not added any variable named minrate to the engine.

In addition, please make sure you have considered the precedence order of the connectors and|or in your rules. If unsure, please group propositions in parenthesis as I have done (if that grouping makes sense to your problem).

Notice also that since you are using and|or in your rules, you have to set the respective conjunction and disjunction operators of your choice. For example,

engine.configure("AlgebraicProduct", "AlgebraicSum", "AlgebraicProduct", "AlgebraicSum", "Centroid");

For future reference, please refer to the forums at www.fuzzylite.com for help solving any issue you might encounter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top