if( debug ) Gpr.debug("Tree: " + tree.toStringTree());
name = tree.getChild(0).getText();
if( debug ) Gpr.debug("RuleBlock name: " + name);
// Use 'default' methods
RuleConnectionMethod and = new RuleConnectionMethodAndMin(), or = new RuleConnectionMethodOrMax();
String ruleAccumulationMethodType = "SUM";
// Explore each sibling in this level
for( int childNum = 1; childNum < tree.getChildCount(); childNum++ ) {
Tree child = tree.getChild(childNum);
if( debug ) Gpr.debug("Parsing: " + child.toStringTree());
String leaveName = child.getText();
if( leaveName.equalsIgnoreCase("AND") ) {
//---
// Which 'AND' method to use? (Note: We also set 'OR' method accordingly to fulfill DeMorgan's law
//---
if( rulesAdded ) throw new RuntimeException("AND method must be defined prior to RULE definition");
String type = child.getChild(0).getText();
if( type.equalsIgnoreCase("MIN") ) {
and = new RuleConnectionMethodAndMin();
or = new RuleConnectionMethodOrMax();
} else if( type.equalsIgnoreCase("PROD") ) {
and = new RuleConnectionMethodAndProduct();
or = new RuleConnectionMethodOrProbOr();
} else if( type.equalsIgnoreCase("BDIF") ) {
and = new RuleConnectionMethodAndBoundedDif();
or = new RuleConnectionMethodOrBoundedSum();
} else throw new RuntimeException("Unknown (or unimplemented) 'AND' method: " + type);
} else if( leaveName.equalsIgnoreCase("OR") ) {
//---
// Which 'OR' method to use? (Note: We also set 'AND' method accordingly to fulfill DeMorgan's law
//---
if( rulesAdded ) throw new RuntimeException("OR method must be defined prior to RULE definition");
String type = child.getChild(0).getText(); // Bug corrected by Arkadiusz M. amaterek@users.sourceforge.net
if( type.equalsIgnoreCase("MAX") ) {
or = new RuleConnectionMethodOrMax();
and = new RuleConnectionMethodAndMin();
} else if( type.equalsIgnoreCase("ASUM") ) {
or = new RuleConnectionMethodOrProbOr();
and = new RuleConnectionMethodAndProduct();
} else if( type.equalsIgnoreCase("BSUM") ) {
or = new RuleConnectionMethodOrBoundedSum();