org.knime.base.node.rules
Class Rule

java.lang.Object
  extended by org.knime.base.node.rules.Rule

public class Rule
extends Object

A rule consists of a condition part (antecedant) and an outcome (consequent). The condition may consists of arithmetic or string comparisons combined by boolean operators. The outcome is a simple string. The grammar for a rule is as follow:

 RULE := BEXPR '=>' STRING
 BEXPR := '(' BEXPR ')' |
          'NOT' BEXPR |
          'MISSING' COL |
          AEXPR (BINOP BEXPR)?
 AEXPR := COL OP COL |
          NUMBER OP COL |
          COL OP NUMBER |
          STRING OP COL |
          COL OP STRING |
          COL LOP STRINGLIST
 BOP := 'AND' | 'OR' | 'XOR'
 OP := '>' | '<' | '>=' | '<=' | '=' | 'LIKE'
 LOP := 'IN'
 STRING := '"' [ˆ"]* '"'
 NUMBER := [1-9][0-9]*(\.[0-9]+)?
 COL := '$' [ˆ$]+ '$'
 STRINGLIST := '(' STRING (',' STRING)* ')'
 
The operators should be self-describing, if not look them up in SQL ;-)
While parsing a rule, the parser also checks if the arithmetic operations are in fact done with numerical columns and throws an exception if not. Therefore the constructor needs the spec of the table on which the rule will lateron be used.

Author:
Thorsten Meinl, University of Konstanz

Nested Class Summary
static class Rule.Operators
          Enumeration for all possible operators used in a rule.
 
Constructor Summary
Rule(String rule, DataTableSpec spec)
          Creates a new rule by parsing a rule string.
 
Method Summary
 String getCondition()
          Returns the rule's condition (antecedant).
 String getOutcome()
          Returns the rule's outcome (consequent).
static void main(String[] args)
          Zum Testen...
 boolean matches(DataRow row)
          Returns if this rules matches the given row.
 String serialize()
          Returns the parsed rule in string representation.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rule

public Rule(String rule,
            DataTableSpec spec)
     throws ParseException
Creates a new rule by parsing a rule string.

Parameters:
rule - the rule string
spec - the spec of the table on which the rule will be applied.
Throws:
ParseException - if the rule contains a syntax error
Method Detail

matches

public boolean matches(DataRow row)
Returns if this rules matches the given row.

Parameters:
row - a data row
Returns:
true if the rule matches, false otherwise

getOutcome

public String getOutcome()
Returns the rule's outcome (consequent).

Returns:
a string

getCondition

public String getCondition()
Returns the rule's condition (antecedant).

Returns:
the condition

toString

public String toString()

Overrides:
toString in class Object

serialize

public String serialize()
Returns the parsed rule in string representation. This representation is not completely identical to the input rule string, but the logical structure should match.

Returns:
a string representation of this rule

main

public static void main(String[] args)
                 throws Exception
Zum Testen...

Parameters:
args - Pieps
Throws:
Exception - Tröt


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.