public Pattern52 getPattern(ConditionCol52 col) { for ( CompositeColumn< ? > cc : conditionPatterns ) { if ( cc instanceof Pattern52 ) { Pattern52 p = (Pattern52) cc; if ( p.getChildColumns().contains( col ) ) { return p; } } } return new Pattern52(); }
public Pattern52 getPattern(ConditionCol52 col) { for ( CompositeColumn< ? > cc : conditionPatterns ) { if ( cc instanceof Pattern52 ) { Pattern52 p = (Pattern52) cc; if ( p.getChildColumns().contains( col ) ) { return p; } } } return new Pattern52(); }
@Override public List<String> getBoundVariablesInScope(BaseSingleFieldConstraint con) { Set<String> variables = new HashSet<String>(); for ( CompositeColumn< ? extends BaseColumn> col : dtable.getConditions() ) { if ( col instanceof Pattern52 ) { Pattern52 p = (Pattern52) col; if ( p.isBound() ) { variables.add( p.getBoundName() ); } for ( ConditionCol52 cc : p.getChildColumns() ) { if ( cc.isBound() ) { variables.add( cc.getBinding() ); } } } else if ( col instanceof BRLConditionColumn ) { //Delegate to super class's implementation RuleModel rm = new RuleModel(); BRLConditionColumn brl = (BRLConditionColumn) col; rm.lhs = brl.getDefinition().toArray( new IPattern[brl.getDefinition().size()] ); variables.addAll( rm.getBoundVariablesInScope( con ) ); } } variables.addAll( super.getBoundVariablesInScope( con ) ); return new ArrayList<String>( variables ); }
@Override public List<String> getBoundVariablesInScope(BaseSingleFieldConstraint con) { Set<String> variables = new HashSet<String>(); for ( CompositeColumn< ? extends BaseColumn> col : dtable.getConditions() ) { if ( col instanceof Pattern52 ) { Pattern52 p = (Pattern52) col; if ( p.isBound() ) { variables.add( p.getBoundName() ); } for ( ConditionCol52 cc : p.getChildColumns() ) { if ( cc.isBound() ) { variables.add( cc.getBinding() ); } } } else if ( col instanceof BRLConditionColumn ) { //Delegate to super class's implementation RuleModel rm = new RuleModel(); BRLConditionColumn brl = (BRLConditionColumn) col; rm.lhs = brl.getDefinition().toArray( new IPattern[brl.getDefinition().size()] ); variables.addAll( rm.getBoundVariablesInScope( con ) ); } } variables.addAll( super.getBoundVariablesInScope( con ) ); return new ArrayList<String>( variables ); }
@Override public FieldConstraint getLHSBoundField(String var) { for ( CompositeColumn< ? extends BaseColumn> col : dtable.getConditions() ) { if ( col instanceof Pattern52 ) { Pattern52 p = (Pattern52) col; for ( ConditionCol52 cc : p.getChildColumns() ) { if ( cc.isBound() && cc.getBinding().equals( var ) ) { return new ConditionCol52FieldConstraintAdaptor( cc ); } } } else if ( col instanceof BRLConditionColumn ) { BRLConditionColumn brl = (BRLConditionColumn) col; for ( IPattern p : brl.getDefinition() ) { if ( p instanceof FactPattern ) { final FactPattern fp = (FactPattern) p; for ( FieldConstraint fc : fp.getFieldConstraints() ) { List<String> fieldBindings = getFieldBinding( fc ); if ( fieldBindings.contains( var ) ) { return fc; } } } } } } return super.getLHSBoundField( var ); }
@Override public FieldConstraint getLHSBoundField(String var) { for ( CompositeColumn< ? extends BaseColumn> col : dtable.getConditions() ) { if ( col instanceof Pattern52 ) { Pattern52 p = (Pattern52) col; for ( ConditionCol52 cc : p.getChildColumns() ) { if ( cc.isBound() && cc.getBinding().equals( var ) ) { return new ConditionCol52FieldConstraintAdaptor( cc ); } } } else if ( col instanceof BRLConditionColumn ) { BRLConditionColumn brl = (BRLConditionColumn) col; for ( IPattern p : brl.getDefinition() ) { if ( p instanceof FactPattern ) { final FactPattern fp = (FactPattern) p; for ( FieldConstraint fc : fp.getFieldConstraints() ) { List<String> fieldBindings = getFieldBinding( fc ); if ( fieldBindings.contains( var ) ) { return fc; } } } } } } return super.getLHSBoundField( var ); }
return p.getFactType(); for ( ConditionCol52 cc : p.getChildColumns() ) { if ( cc.isBound() && cc.getBinding().equals( var ) ) { return cc.getFieldType();
col1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); col1.setOperator( "" ); p1.getChildColumns().add( col1 ); allColumns.add( col1 );
@Test public void testNoConstraintLists() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); // add cols for LHS ConditionCol52 c1 = new ConditionCol52(); Pattern52 p1 = new Pattern52(); p1.setBoundName( "c1" ); p1.setFactType( "Driver" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); ConditionCol52 c2 = new ConditionCol52(); Pattern52 p2 = new Pattern52(); p2.setBoundName( "c2" ); p2.setFactType( "Driver" ); c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); c2.setValueList( "a,b,c" ); p2.getChildColumns().add( c2 ); dt.getConditions().add( p1 ); SuggestionCompletionEngine sce = new SuggestionCompletionEngine(); sce.putDataEnumList( "Driver.name", new String[]{"bob", "michael"} ); assertEquals( 0, dt.getValueList( c1 ).length ); assertEquals( 3, dt.getValueList( c2 ).length ); }
cc1.setFactField( "name" ); cc1.setOperator( "!= null" ); p1.getChildColumns().add( cc1 ); cc2.setFactField( "age" ); cc2.setOperator( "!= null" ); p1.getChildColumns().add( cc2 ); cc3.setFactField( "dateOfBirth" ); cc3.setOperator( "!= null" ); p1.getChildColumns().add( cc3 );
@Test public void testNoConstraints() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); Pattern52 p1 = new Pattern52(); p1.setBoundName( "x" ); p1.setFactType( "Context" ); ConditionCol52 c = new ConditionCol52(); c.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c ); dt.getConditions().add( p1 ); ActionSetFieldCol52 asf = new ActionSetFieldCol52(); asf.setBoundName( "x" ); asf.setFactField( "age" ); asf.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( asf ); String[][] data = new String[][]{ new String[]{"1", "desc", "y", "old"} }; dt.setData( upgrader.makeDataLists( data ) ); String drl = GuidedDTDRLPersistence.getInstance().marshal( dt ); assertTrue( drl.indexOf( "Context( )" ) > -1 ); assertTrue( drl.indexOf( "x.setAge" ) > drl.indexOf( "Context( )" ) ); assertFalse( drl.indexOf( "update( x );" ) > -1 ); dt.setData( upgrader.makeDataLists( new String[][]{ new String[]{"1", "desc", "", "old"} } ) ); drl = GuidedDTDRLPersistence.getInstance().marshal( dt ); assertEquals( -1, drl.indexOf( "Context( )" ) ); }
cc1.setFactField( "name" ); cc1.setOperator( "in" ); p1.getChildColumns().add( cc1 ); cc2.setFactField( "age" ); cc2.setOperator( "in" ); p1.getChildColumns().add( cc2 );
cc1.setFactField( "name" ); cc1.setOperator( "not in" ); p1.getChildColumns().add( cc1 ); cc2.setFactField( "age" ); cc2.setOperator( "not in" ); p1.getChildColumns().add( cc2 );
p1.getChildColumns().add( c ); dt.getConditions().add( p1 );
@Test public void testOnlyDecisionTableColumns() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); Pattern52 p1 = new Pattern52(); p1.setFactType( "Driver" ); p1.setBoundName( "$p1" ); ConditionCol52 c1 = new ConditionCol52(); c1.setFactField( "name" ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); c1.setBinding( "$c1" ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); ActionInsertFactCol52 ins = new ActionInsertFactCol52(); ins.setBoundName( "$ins" ); ins.setFactField( "rating" ); ins.setFactType( "Person" ); ins.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( ins ); BRLRuleModel model = new BRLRuleModel( dt ); assertNotNull( model.getAllVariables() ); assertEquals( 3, model.getAllVariables().size() ); assertTrue( model.getAllVariables().contains( "$p1" ) ); assertTrue( model.getAllVariables().contains( "$c1" ) ); assertTrue( model.getAllVariables().contains( "$ins" ) ); }
@Test public void testLimitedEntryConditionsNoConstraints() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat( TableFormat.LIMITED_ENTRY ); dt.setTableName( "limited-entry" ); Pattern52 p1 = new Pattern52(); p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 ); // This is a hack consistent with how the Expanded Form decision table // works. I wouldn't be too surprised if this changes at some time, but // GuidedDTDRLPersistence.marshal does not support empty patterns at // present. LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52(); cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc1.setValue( new DTCellValue52( "y" ) ); p1.getChildColumns().add( cc1 ); dt.setData( upgrader.makeDataLists( new Object[][]{ new Object[]{1l, "desc", true}, new Object[]{2l, "desc", false} } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); int index = -1; index = drl.indexOf( "Smurf( )" ); assertTrue( index > -1 ); index = drl.indexOf( "Smurf( )", index + 1 ); assertFalse( index > -1 ); }
cc1.setOperator( "in" ); cc1.setValue( new DTCellValue52( "Pupa, Brains" ) ); p1.getChildColumns().add( cc1 ); cc2.setOperator( "in" ); cc2.setValue( new DTCellValue52( "55, 66" ) ); p1.getChildColumns().add( cc2 );
@Test public void testLimitedEntryConditionsConstraints1() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat( TableFormat.LIMITED_ENTRY ); dt.setTableName( "limited-entry" ); Pattern52 p1 = new Pattern52(); p1.setBoundName( "p1" ); p1.setFactType( "Smurf" ); dt.getConditions().add( p1 ); LimitedEntryConditionCol52 cc1 = new LimitedEntryConditionCol52(); cc1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); cc1.setFieldType( SuggestionCompletionEngine.TYPE_STRING ); cc1.setFactField( "name" ); cc1.setOperator( "==" ); cc1.setValue( new DTCellValue52( "Pupa" ) ); p1.getChildColumns().add( cc1 ); dt.setData( upgrader.makeDataLists( new Object[][]{ new Object[]{1l, "desc", true}, new Object[]{2l, "desc", false} } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); int index = -1; index = drl.indexOf( "Smurf( name == \"Pupa\" )" ); assertTrue( index > -1 ); index = drl.indexOf( "Smurf( name == \"Pupa\" )", index + 1 ); assertFalse( index > -1 ); }
c1.setBinding( "$c1" ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 );
c.setDefaultValue( new DTCellValue52( "cheddar" ) ); c.setOperator( "==" ); p1.getChildColumns().add( c ); dt.getConditions().add( p1 );