Logical parser utility is used to parse logical expressions. Those expression can have the formula inside.
The logical expression must return either true or false result, e.g. “x0>5” or ”(sin(x0) ⇐ 1) && (sin(x0) >= -1).
Notice that if you use conjunction or union for expressions it is better to use the brackets to specify the boundaries, which parts must be united or conjuncted.
Any formula, which is possible to parse with FormulaParser, can be used in this expression. Also boolean values “true”, “false” are allowed too. If you prefer you can use ”.T”,”.F” instead of true and false. Allowed operations in the expression are: <p>&& - conjunction operator <P>|| - union operator <p>## - xor operator <p>! - negation operator <p> <, >, ==, !=, ⇐, >= are comparison operators <p> (,) - brackets can be used to specify the boundaries of union, negation and etc. Be sure to match the number of brackets. All comparison operations has a higher priority over &&, || and ## operations. So if you want those operations to be performed prior to comparison operations, you must use brackets.
Any comparison operation, except == and !=, will return false value.
Null values can be compared with == and != operators, e.g “x0==null”
Note: When using statistical operations, be sure to set the data model to the LogicalParser as shown in the examples.
Here is a simple example:
1 | try{ LogicalParser lp = new LogicalParser ("mean(x0)>5"); lp.setDataModel(dataModel); lp.eval(); //the output would be true if mean is bigger than 5 }catch(Exception e) { e.printStackTrace(); } |
Here is another example:
1 | try{ LogicalParser lp = new LogicalParser ("(x0>5)&&(x<10)"); lp.eval(x); //the output would be true if x will be between 5 and 10. }catch(Exception e) { e.printStackTrace(); } |