public void addLhsItem( final IPattern pat, boolean append ) { this.addLhsItem( pat, append ? this.lhs.length : 0 ); }
public RuleModelVisitor( IPattern pattern, Map<InterpolationVariable, Integer> vars ) { this.vars = vars; this.model.addLhsItem( pattern ); }
public void addLhsItem( final IPattern pat ) { this.addLhsItem( pat, true ); }
private int parseDslInLhs(RuleModel m, ExpandedDRLInfo expandedDRLInfo, int lineCounter) { if ( expandedDRLInfo.hasDsl ) { String dslLine = expandedDRLInfo.dslStatementsInLhs.get( lineCounter ); while ( dslLine != null ) { m.addLhsItem( toDSLSentence( expandedDRLInfo.lhsDslPatterns, dslLine ) ); dslLine = expandedDRLInfo.dslStatementsInLhs.get( ++lineCounter ); } } return lineCounter; }
private void addNewDSLLhs( final DSLSentence sentence, int position ) { model.addLhsItem( sentence.copy(), position ); }
private void addNewCE( String s, int position ) { this.model.addLhsItem( new CompositeFactPattern( s ), position ); }
private void addNewFact( String itemText, int position ) { this.model.addLhsItem( new FactPattern( itemText ), position ); }
private int parseFreeForm(RuleModel m, ExpandedDRLInfo expandedDRLInfo, int lineCounter) { String freeForm = expandedDRLInfo.freeFormStatementsInLhs.get( lineCounter ); while ( freeForm != null ) { FreeFormLine ffl = new FreeFormLine(); ffl.setText( freeForm ); m.addLhsItem( ffl ); freeForm = expandedDRLInfo.freeFormStatementsInLhs.get( ++lineCounter ); } return lineCounter; }
private List<IPattern> cloneDefinition( List<IPattern> definition ) { RuleModelCloneVisitor visitor = new RuleModelCloneVisitor(); RuleModel rm = new RuleModel(); for ( IPattern pattern : definition ) { rm.addLhsItem( pattern ); } RuleModel rmClone = visitor.visitRuleModel( rm ); List<IPattern> clone = new ArrayList<IPattern>(); for ( IPattern pattern : rmClone.lhs ) { clone.add( pattern ); } return clone; }
private List<IPattern> cloneDefinition( List<IPattern> definition ) { RuleModelCloneVisitor visitor = new RuleModelCloneVisitor(); RuleModel rm = new RuleModel(); for ( IPattern pattern : definition ) { rm.addLhsItem( pattern ); } RuleModel rmClone = visitor.visitRuleModel( rm ); List<IPattern> clone = new ArrayList<IPattern>(); for ( IPattern pattern : rmClone.lhs ) { clone.add( pattern ); } return clone; }
private Map<String, String> parseLhs( RuleModel m, AndDescr lhs, ExpandedDRLInfo expandedDRLInfo ) { Map<String, String> boundParams = new HashMap<String, String>(); int lineCounter = -1; for ( BaseDescr descr : lhs.getDescrs() ) { lineCounter = parseNonDrlInLhs(m, expandedDRLInfo, lineCounter); m.addLhsItem( parseBaseDescr( descr, boundParams ) ); } parseNonDrlInLhs(m, expandedDRLInfo, lineCounter); return boundParams; }
public void execute() { model.addLhsItem( new FreeFormLine(), Integer.parseInt( positionCbo.getValue( positionCbo.getSelectedIndex() ) ) ); hide(); } } );
@Test public void testInvalidComposite() throws Exception { RuleModel m = new RuleModel(); CompositeFactPattern com = new CompositeFactPattern( "not" ); m.addLhsItem( com ); String s = BRDRLPersistence.getInstance().marshal( m ); assertNotNull( s ); m.addLhsItem( new CompositeFactPattern( "or" ) ); m.addLhsItem( new CompositeFactPattern( "exists" ) ); s = BRDRLPersistence.getInstance().marshal( m ); assertNotNull( s ); }
@Test public void testGetVariableNameForRHS() { RuleModel m = new RuleModel(); m.name = "blah"; FactPattern pat = new FactPattern( "Person" ); pat.setBoundName( "pat" ); m.addLhsItem( pat ); List l = m.getAllVariables(); assertEquals( 1, l.size() ); assertEquals( "pat", l.get( 0 ) ); }
@Test public void testBasics() { String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsert( new Report() );\nend\n"; RuleModel m = new RuleModel(); m.addLhsItem( new FactPattern( "Person" ) ); m.addLhsItem( new FactPattern( "Accident" ) ); m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); m.addRhsItem( new ActionInsertFact( "Report" ) ); m.name = "my rule"; checkMarshallUnmarshall( expected, m ); }
@Test public void testInsertLogical() { String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsertLogical( new Report() );\nend\n"; final RuleModel m = new RuleModel(); m.addLhsItem( new FactPattern( "Person" ) ); m.addLhsItem( new FactPattern( "Accident" ) ); m.addAttribute( new RuleAttribute( "no-loop", "true" ) ); m.addRhsItem( new ActionInsertLogicalFact( "Report" ) ); m.name = "my rule"; checkMarshallUnmarshall( expected, m ); }
private RuleModel getModelWithNoConstraints() { final RuleModel m = new RuleModel(); m.name = "Complex Rule"; final FactPattern pat = new FactPattern( "Person" ); pat.setBoundName( "p1" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldBinding( "f1" ); con.setFieldName( "age" ); // con.operator = "<"; // con.value = "42"; pat.addConstraint( con ); m.addLhsItem( pat ); return m; }
@Test public void textIsNullOperator() { final RuleModel m = new RuleModel(); m.name = "IsNullOperator"; final FactPattern pat = new FactPattern( "Person" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldName( "age" ); con.setOperator( "== null" ); pat.addConstraint( con ); m.addLhsItem( pat ); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "Person( age == null )" ) != -1 ); checkMarshallUnmarshall( s, m ); }
@Test public void textIsNotNullOperator() { final RuleModel m = new RuleModel(); m.name = "IsNotNullOperator"; final FactPattern pat = new FactPattern( "Person" ); final SingleFieldConstraint con = new SingleFieldConstraint(); con.setFieldName( "age" ); con.setOperator( "!= null" ); pat.addConstraint( con ); m.addLhsItem( pat ); String s = BRDRLPersistence.getInstance().marshal( m ); assertTrue( s.indexOf( "Person( age != null )" ) != -1 ); checkMarshallUnmarshall( s, m ); }
@Test public void testPredicateConstraint() { RuleModel m = new RuleModel(); m.name = "yeah"; FactPattern p = new FactPattern( "Goober" ); SingleFieldConstraint con = new SingleFieldConstraint(); con.setConstraintValueType( SingleFieldConstraint.TYPE_PREDICATE ); con.setValue( "field soundslike \"poo\"" ); p.addConstraint( con ); m.addLhsItem( p ); String expected = "rule \"yeah\" " + "\tdialect \"mvel\"\n when " + "Goober( eval( field soundslike \"poo\" ) )" + " then " + "end"; checkMarshallUnmarshall( expected, m ); }