GuidedDecisionTable52 newDTModel = new GuidedDecisionTable52(); newDTModel.setTableFormat( TableFormat.EXTENDED_ENTRY ); newDTModel.setTableName( legacyDTModel.tableName ); newDTModel.setParentName( legacyDTModel.parentName ); newDTModel.setRowNumberCol( new RowNumberCol52() ); newDTModel.setDescriptionCol( new DescriptionCol52() ); newDTModel.getMetadataCols().add( makeNewColumn( c ) ); newDTModel.getAttributeCols().add( makeNewColumn( c ) ); newDTModel.getConditions().add( p ); newDTModel.getActionCols().add( makeNewColumn( c ) ); newDTModel.setData( makeDataLists( legacyDTModel.data ) ); if ( lc instanceof ActionRetractFactCol ) { String boundName = ((ActionRetractFactCol) lc).boundName; for ( List<DTCellValue52> row : newDTModel.getData() ) { row.get( DATA_COLUMN_OFFSET + iCol ).setStringValue( boundName );
List<List<DTCellValue52>> data = dt.getData(); List<BaseColumn> allColumns = dt.getExpandedColumns(); rm.name = getName( dt.getTableName(), num ); dt.getMetadataCols(), row, rm ); doAttribs( allColumns, dt.getAttributeCols(), row, rm ); doConditions( allColumns, dt.getConditions(), rowDataProvider, row, rm ); doActions( allColumns, dt.getActionCols(), rowDataProvider, row, rm ); if ( dt.getParentName() != null ) { rm.parentName = dt.getParentName();
private String getType(ConditionCol52 col, SuggestionCompletionEngine sce) { final Pattern52 pattern = getPattern( col ); return getType( pattern, col, sce ); }
public DTDataTypes52 getTypeSafeType(BaseColumn column, SuggestionCompletionEngine sce) { final String type = getType( column, sce ); return convertToTypeSafeType( type ); }
@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 ); }
tsdt.getTableName() ); tsdt.getMetadataCols().size() ); tsdt.getAttributeCols().size() ); tsdt.getConditions().size() ); tsdt.getConditionPattern( "z1" ).getBoundName() ); assertEquals( "Driver", tsdt.getConditionPattern( "z1" ).getFactType() ); tsdt.getConditionPattern( "f1" ).getBoundName() ); assertEquals( "Person", tsdt.getConditionPattern( "f1" ).getFactType() ); tsdt.getConditionPattern( "f2" ).getBoundName() ); assertEquals( "Person2", tsdt.getConditionPattern( "f2" ).getFactType() ); tsdt.getConditionPattern( "z1" ).getChildColumns().size() ); tsdt.getConditionPattern( "f1" ).getChildColumns().size() ); tsdt.getConditionPattern( "f2" ).getChildColumns().size() ); tsdt.getConditionPattern( "z1" ).getChildColumns().get( 0 ).getConstraintValueType() ); assertEquals( "age", tsdt.getConditionPattern( "z1" ).getChildColumns().get( 0 ).getFactField() );
GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.getActionCols().add( new ActionInsertFactCol52() ); ActionSetFieldCol52 set = new ActionSetFieldCol52(); set.setFactField( "foo" ); dt.getActionCols().add( set ); dt.getMetadataCols().add( new MetadataCol52() ); dt.getAttributeCols().add( new AttributeCol52() ); dt.getConditions().add( p ); dt.setData( upgrader.makeDataLists( new String[][]{new String[]{"1", "hola"}} ) ); dt.setTableName( "blah" ); 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() );
@Test public void test2Rules() throws Exception { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableName( "michael" ); dt.getAttributeCols().add( attr ); dt.getConditions().add( p1 ); dt.getConditions().add( p2 ); ins.setFactField( "price" ); ins.setType( SuggestionCompletionEngine.TYPE_NUMERIC_INTEGER ); dt.getActionCols().add( ins ); dt.getActionCols().add( ret ); set.setFactField( "goo1" ); set.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( set ); set2.setDefaultValue( new DTCellValue52( "whee" ) ); set2.setType( SuggestionCompletionEngine.TYPE_STRING ); dt.getActionCols().add( set2 ); dt.setData( upgrader.makeDataLists( new String[][]{ new String[]{"1", "desc", "42", "33", "michael", "age * 0.2", "age > 7", "6.60", "true", "gooVal1", "f2"}, new String[]{"2", "desc", "66", "39", "bob", "age * 0.3", "age > 7", "6.60", "", "gooVal1", "whee"}
GuidedDecisionTable52 dtable = new GuidedDecisionTable52(); dtable.setRowNumberCol( new RowNumberCol52() ); dtable.setDescriptionCol( new DescriptionCol52() ); brl1.getChildColumns().add( brl1Variable1 ); dtable.getConditions().add( brl1 ); dtable.setData( upgrader.makeDataLists( data ) );
GuidedDecisionTable52 dtable = new GuidedDecisionTable52(); dtable.setRowNumberCol( new RowNumberCol52() ); dtable.setDescriptionCol( new DescriptionCol52() ); brl1.getChildColumns().add( brl1Variable1 ); dtable.getActionCols().add( brl1 ); dtable.setData( upgrader.makeDataLists( data ) );
@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" ) ); }
GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.getAttributeCols().add( at ); dt.getAttributeCols().add( at_ ); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); c1_.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1_.getChildColumns().add( c1_ ); dt.getConditions().add( p1_ ); c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p2.getChildColumns().add( c2 ); dt.getConditions().add( p2 ); dt.getActionCols().add( a ); dt.getActionCols().add( a2 ); ins.setFactType( "Driver" ); ins.setFactField( "name" ); dt.getActionCols().add( ins ); ins_.setFactType( "Driver" ); ins_.setFactField( "age" ); dt.getActionCols().add( ins_ );
@Test public void testLimitedEntryMetadata() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat( TableFormat.LIMITED_ENTRY ); dt.setTableName( "limited-entry" ); MetadataCol52 md = new MetadataCol52(); md.setMetadata( "metadata" ); dt.getMetadataCols().add( md ); dt.setData( upgrader.makeDataLists( new String[][]{ new String[]{"1", "desc", "md1"}, new String[]{"2", "desc", "md2"} } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); assertTrue( drl.indexOf( "@metadata(md1)" ) > -1 ); assertTrue( drl.indexOf( "@metadata(md2)" ) > -1 ); }
@Test public void testLimitedEntryAttributes() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); dt.setTableFormat( TableFormat.LIMITED_ENTRY ); dt.setTableName( "limited-entry" ); AttributeCol52 attr = new AttributeCol52(); attr.setAttribute( "salience" ); dt.getAttributeCols().add( attr ); dt.setData( upgrader.makeDataLists( new String[][]{ new String[]{"1", "desc", "100"}, new String[]{"2", "desc", "200"} } ) ); GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance(); String drl = p.marshal( dt ); assertTrue( drl.indexOf( "salience 100" ) > -1 ); assertTrue( drl.indexOf( "salience 200" ) > -1 ); }
@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() ); }
@Test public void testValueLists() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); Map<String, String> currentValueMap = new HashMap<String, String>(); c1.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); p1_.getChildColumns().add( c1_ ); c1_.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE ); dt.getConditions().add( p1_ ); c1__.setConstraintValueType( BaseSingleFieldConstraint.TYPE_RET_VALUE ); c1__.setValueList( "Male,Female" ); dt.getConditions().add( p1_ ); c1___.setValueList( "one,two,three" ); p1__.getChildColumns().add( c1___ ); dt.getConditions().add( p1__ ); c2.setConstraintValueType( BaseSingleFieldConstraint.TYPE_LITERAL ); p2.getChildColumns().add( c2 ); dt.getConditions().add( p2 ); dt.getActionCols().add( asf ); ins.setFactField( "rating" ); ins.setFactType( "Person" ); dt.getActionCols().add( ins );
@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( )" ) ); }
GuidedDecisionTable52 dtable = new GuidedDecisionTable52(); dtable.setRowNumberCol( new RowNumberCol52() ); dtable.setDescriptionCol( new DescriptionCol52() ); a1.setType( SuggestionCompletionEngine.TYPE_STRING ); dtable.getActionCols().add( a1 ); brl1.getChildColumns().add( brl1Variable2 ); dtable.getActionCols().add( brl1 ); List<BaseColumn> allColumns = dtable.getExpandedColumns(); List<ActionCol52> allActions = dtable.getActionCols();
GuidedDecisionTable52 dtable = new GuidedDecisionTable52(); dtable.setRowNumberCol( new RowNumberCol52() ); dtable.setDescriptionCol( new DescriptionCol52() ); p1.getChildColumns().add( con ); dtable.getConditions().add( p1 ); brl1.getChildColumns().add( brl1Variable2 ); dtable.getConditions().add( brl1 ); List<BaseColumn> allColumns = dtable.getExpandedColumns(); List<CompositeColumn< ? >> allPatterns = dtable.getConditions(); List<List<DTCellValue52>> dtData = upgrader.makeDataLists( data );
@SuppressWarnings("serial") @Test public void testConditionFormulaChoices() { GuidedDecisionTable52 dt = new GuidedDecisionTable52(); c1.setValueList( "getAge()>10,getAge()>20,getAge()>30" ); p1.getChildColumns().add( c1 ); dt.getConditions().add( p1 ); assertTrue( dt.getValueList( c1 ).length > 0 ); assertTrue( dt.getValueList( c1 ).length == 3 ); assertEquals( "getAge()>10", dt.getValueList( c1 )[0] ); assertEquals( "getAge()>20", dt.getValueList( c1 )[1] ); assertEquals( "getAge()>30", dt.getValueList( c1 )[2] );