@Override public List<String> getAllRHSVariables() { Set<String> variables = new HashSet<String>(); for ( ActionCol52 col : dtable.getActionCols() ) { if ( col instanceof ActionInsertFactCol52 ) { ActionInsertFactCol52 action = (ActionInsertFactCol52) col; variables.add( action.getBoundName() ); } else if ( col instanceof BRLActionColumn ) { BRLActionColumn brl = (BRLActionColumn) col; for ( IAction a : brl.getDefinition() ) { if ( a instanceof ActionInsertFact ) { ActionInsertFact action = (ActionInsertFact) a; if ( action.isBound() ) { variables.add( action.getBoundName() ); } } } } } variables.addAll( super.getAllRHSVariables() ); return new ArrayList<String>( variables ); }
@Override public List<String> getRHSBoundFacts() { final Set<String> variables = new HashSet<String>(); for ( ActionCol52 col : dtable.getActionCols() ) { if ( col instanceof ActionInsertFactCol52 ) { ActionInsertFactCol52 action = (ActionInsertFactCol52) col; variables.add( action.getBoundName() ); } else if ( col instanceof BRLActionColumn ) { BRLActionColumn brl = (BRLActionColumn) col; for ( IAction a : brl.getDefinition() ) { if ( a instanceof ActionInsertFact ) { ActionInsertFact action = (ActionInsertFact) a; if ( action.isBound() ) { variables.add( action.getBoundName() ); } } } } } variables.addAll( super.getRHSBoundFacts() ); return new ArrayList<String>( variables ); }
@Override public List<String> getAllRHSVariables() { Set<String> variables = new HashSet<String>(); for ( ActionCol52 col : dtable.getActionCols() ) { if ( col instanceof ActionInsertFactCol52 ) { ActionInsertFactCol52 action = (ActionInsertFactCol52) col; variables.add( action.getBoundName() ); } else if ( col instanceof BRLActionColumn ) { BRLActionColumn brl = (BRLActionColumn) col; for ( IAction a : brl.getDefinition() ) { if ( a instanceof ActionInsertFact ) { ActionInsertFact action = (ActionInsertFact) a; if ( action.isBound() ) { variables.add( action.getBoundName() ); } } } } } variables.addAll( super.getAllRHSVariables() ); return new ArrayList<String>( variables ); }
@Override public List<String> getRHSBoundFacts() { final Set<String> variables = new HashSet<String>(); for ( ActionCol52 col : dtable.getActionCols() ) { if ( col instanceof ActionInsertFactCol52 ) { ActionInsertFactCol52 action = (ActionInsertFactCol52) col; variables.add( action.getBoundName() ); } else if ( col instanceof BRLActionColumn ) { BRLActionColumn brl = (BRLActionColumn) col; for ( IAction a : brl.getDefinition() ) { if ( a instanceof ActionInsertFact ) { ActionInsertFact action = (ActionInsertFact) a; if ( action.isBound() ) { variables.add( action.getBoundName() ); } } } } } variables.addAll( super.getRHSBoundFacts() ); return new ArrayList<String>( variables ); }
@Override public boolean isBoundFactUsed(String binding) { for ( ActionCol52 col : dtable.getActionCols() ) { if ( col instanceof ActionInsertFactCol52 ) { ActionInsertFactCol52 action = (ActionInsertFactCol52) col;
@Override public boolean isBoundFactUsed(String binding) { for ( ActionCol52 col : dtable.getActionCols() ) { if ( col instanceof ActionInsertFactCol52 ) { ActionInsertFactCol52 action = (ActionInsertFactCol52) col;
@Override public ActionInsertFact getRHSBoundFact(String var) { for ( ActionCol52 col : dtable.getActionCols() ) { if ( col instanceof ActionInsertFactCol52 ) { ActionInsertFactCol52 action = (ActionInsertFactCol52) col; if ( action.getBoundName().equals( var ) ) { if ( action.isInsertLogical() ) { return new ActionInsertFactCol52ActionInsertLogicalFactAdaptor( action ); } return new ActionInsertFactCol52ActionInsertFactAdaptor( action ); } } else if ( col instanceof BRLActionColumn ) { BRLActionColumn brl = (BRLActionColumn) col; for ( IAction a : brl.getDefinition() ) { if ( a instanceof ActionInsertFact ) { ActionInsertFact action = (ActionInsertFact) a; if ( action.isBound() ) { if ( action.getBoundName().equals( var ) ) { return action; } } } } } } return super.getRHSBoundFact( var ); }
@Override public ActionInsertFact getRHSBoundFact(String var) { for ( ActionCol52 col : dtable.getActionCols() ) { if ( col instanceof ActionInsertFactCol52 ) { ActionInsertFactCol52 action = (ActionInsertFactCol52) col; if ( action.getBoundName().equals( var ) ) { if ( action.isInsertLogical() ) { return new ActionInsertFactCol52ActionInsertLogicalFactAdaptor( action ); } return new ActionInsertFactCol52ActionInsertFactAdaptor( action ); } } else if ( col instanceof BRLActionColumn ) { BRLActionColumn brl = (BRLActionColumn) col; for ( IAction a : brl.getDefinition() ) { if ( a instanceof ActionInsertFact ) { ActionInsertFact action = (ActionInsertFact) a; if ( action.isBound() ) { if ( action.getBoundName().equals( var ) ) { return action; } } } } } } return super.getRHSBoundFact( var ); }
rm ); doActions( allColumns, dt.getActionCols(), rowDataProvider, row,
rm ); doActions( allColumns, dt.getActionCols(), rowDataProvider, row,
@Test public void testBackwardsCompatability() throws Exception { String xml = BRLPersistenceTest.loadResource( "ExistingDecisionTable.xml" ); GuidedDecisionTable52 dt_ = GuidedDTXMLPersistence.getInstance().unmarshal( xml ); assertNotNull( dt_ ); assertEquals( "blah", dt_.getTableName() ); assertEquals( 1, dt_.getMetadataCols().size() ); assertEquals( 1, dt_.getAttributeCols().size() ); assertEquals( 2, dt_.getActionCols().size() ); assertEquals( 1, dt_.getConditions().size() ); assertEquals( 1, dt_.getConditions().get( 0 ).getChildColumns().size() ); assertTrue( dt_.getActionCols().get( 1 ) instanceof ActionSetFieldCol52 ); ActionSetFieldCol52 asf = (ActionSetFieldCol52) dt_.getActionCols().get( 1 ); assertEquals( "foo", asf.getFactField() ); assertEquals( false, asf.isUpdate() ); }
dt.getActionCols().add( new ActionInsertFactCol52() ); ActionSetFieldCol52 set = new ActionSetFieldCol52(); set.setFactField( "foo" ); dt.getActionCols().add( set ); dt_.getAttributeCols().size() ); assertEquals( 2, dt_.getActionCols().size() ); assertEquals( 1, dt_.getConditions().size() );
@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( )" ) ); }
asf.setUpdate( true ); dt.getActionCols().add( asf );
asf1.setValue( new DTCellValue52( "Blue" ) ); dt.getActionCols().add( asf1 );
@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" ) ); }
asf1.setValue( new DTCellValue52( "Blue" ) ); dt.getActionCols().add( asf1 );
ins.setFactType( "Person" ); ins.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( ins );
ins.setFactType( "Person" ); ins.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( ins );
ins.setFactType( "Person" ); ins.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( ins );