private FromCompositeFactPattern visitFromCompositeFactPattern(FromCompositeFactPattern pattern) { FromCompositeFactPattern clone = new FromCompositeFactPattern(); clone.setExpression( (ExpressionFormLine) visit( pattern.getExpression() ) ); clone.setFactPattern( (FactPattern) visit( pattern.getFactPattern() ) ); return clone; }
public void visitFromCompositeFactPattern( FromCompositeFactPattern pattern, boolean isSubPattern ) { buf.append( indentation ); if ( !isSubPattern && isDSLEnhanced ) { // adding passthrough markup buf.append( ">" ); } if ( pattern.getFactPattern() != null ) { generateFactPattern( pattern.getFactPattern() ); } buf.append( " from " ); renderExpression( pattern.getExpression() ); buf.append( "\n" ); }
@Test public void testCompositeFactPatternWithFromWithDSL() { final RuleModel m = new RuleModel(); m.name = "model"; final DSLSentence sen = new DSLSentence(); sen.setDefinition( "A DSL phrase" ); m.addLhsItem( sen ); final FactPattern fp1 = new FactPattern( "Data" ); fp1.setBoundName( "$d" ); m.addLhsItem( fp1 ); final CompositeFactPattern cp = new CompositeFactPattern( CompositeFactPattern.COMPOSITE_TYPE_NOT ); final FactPattern fp2 = new FactPattern( "Person" ); final FromCompositeFactPattern ffp1 = new FromCompositeFactPattern(); ffp1.setExpression( new ExpressionFormLine( new ExpressionVariable( fp1 ) ) ); ffp1.setFactPattern( fp2 ); cp.addFactPattern( ffp1 ); m.addLhsItem( cp ); final String actual = BRDRLPersistence.getInstance().marshal( m ); final String expected = "rule \"model\"\n" + "dialect \"mvel\"\n" + "when\n" + "A DSL phrase\n" + ">$d : Data( )\n" + ">not ( Person( ) from $d\n" + ")\n" + "then\n" + "end\n"; assertEqualsIgnoreWhitespace( expected, actual ); }
/** * This will return a List<String> of all FactPattern bindings * * @return The bindings or an empty list if no bindings are found. */ public List<String> getLHSBoundFacts() { if ( this.lhs == null ) { return Collections.emptyList(); } final List<String> list = new ArrayList<String>(); for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null ) { list.add( p.getBoundName() ); } } } return list; }
final FromCompositeFactPattern fcfp = new FromCompositeFactPattern(); final FactPattern x = new FactPattern( "Car" ); x.setBoundName( "x" ); a.setFieldType( "String" ); x.addConstraint( a ); fcfp.setFactPattern( x );
public void visitFromCompositeFactPattern( FromCompositeFactPattern pattern, boolean isSubPattern ) { buf.append( indentation ); if ( !isSubPattern && isDSLEnhanced ) { // adding passthrough markup buf.append( ">" ); } if ( pattern.getFactPattern() != null ) { generateFactPattern( pattern.getFactPattern() ); } buf.append( " from " ); renderExpression( pattern.getExpression() ); buf.append( "\n" ); }
/** * This will return a List<String> of all FactPattern bindings * * @return The bindings or an empty list if no bindings are found. */ public List<String> getLHSBoundFacts() { if ( this.lhs == null ) { return Collections.emptyList(); } final List<String> list = new ArrayList<String>(); for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null ) { list.add( p.getBoundName() ); } } } return list; }
private FromCompositeFactPattern visitFromCompositeFactPattern(FromCompositeFactPattern pattern) { FromCompositeFactPattern clone = new FromCompositeFactPattern(); clone.setExpression( (ExpressionFormLine) visit( pattern.getExpression() ) ); clone.setFactPattern( (FactPattern) visit( pattern.getFactPattern() ) ); return clone; }
private void visitFromCompositeFactPattern(FromCompositeFactPattern pattern) { visit( pattern.getFactPattern() ); parseStringPattern( pattern.getExpression().getText() ); }
/** * This will return the FactPattern that a variable is bound Eto. * * @param var * The bound fact variable (NOT bound field). * @return null or the FactPattern found. */ public FactPattern getLHSBoundFact(final String var) { if ( this.lhs == null ) { return null; } for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null && var.equals( p.getBoundName() ) ) { return p; } } } return null; }
FromCompositeFactPattern fp0 = new FromCompositeFactPattern(); ExpressionFormLine efl0 = new ExpressionFormLine(); efl0.setBinding( "$efl0" ); ExpressionText efl0p0 = new ExpressionText( "efl0p0" ); efl0.appendPart( efl0p0 ); fp0.setExpression( efl0 ); FactPattern fp0FactPattern = new FactPattern( "fp0FactPattern" ); fp0.setFactPattern( fp0FactPattern ); assertNotSame( fp0.getExpression(), fp0Clone.getExpression() ); assertNotNull( fp0Clone.getExpression() ); assertTrue( fp0Clone.getExpression() instanceof ExpressionFormLine ); ExpressionFormLine efl0Clone = (ExpressionFormLine) fp0Clone.getExpression(); fp0Clone.getExpression().getParts().size() ); assertTrue( fp0Clone.getExpression().getParts().get( 0 ) instanceof ExpressionText ); ExpressionText efl0p0Clone = (ExpressionText) fp0Clone.getExpression().getParts().get( 0 ); assertEquals( efl0p0.getClassType(), efl0p0Clone.getClassType() ); assertNotSame( fp0.getFactPattern(), fp0Clone.getFactPattern() ); assertNotNull( fp0Clone.getFactPattern() ); assertTrue( fp0Clone.getFactPattern() instanceof FactPattern ); FactPattern fp0FactPatternClone = (FactPattern) fp0Clone.getFactPattern(); assertEquals( fp0FactPattern.getBoundName(), fp0FactPatternClone.getBoundName() );
private void visitFromCompositeFactPattern(FromCompositeFactPattern pattern) { visit( pattern.getFactPattern() ); parseStringPattern( pattern.getExpression().getText() ); }
/** * This will return the FactPattern that a variable is bound Eto. * * @param var * The bound fact variable (NOT bound field). * @return null or the FactPattern found. */ public FactPattern getLHSBoundFact(final String var) { if ( this.lhs == null ) { return null; } for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null && var.equals( p.getBoundName() ) ) { return p; } } } return null; }
/** * This will return the FieldConstraint that a variable is bound to. * * @param var * The bound field variable (NOT bound fact). * @return null or the FieldConstraint found. */ public FieldConstraint getLHSBoundField(final String var) { if ( this.lhs == null ) { return null; } for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; for ( int j = 0; j < p.getFieldConstraints().length; j++ ) { FieldConstraint fc = p.getFieldConstraints()[j]; List<String> fieldBindings = getFieldBinding( fc ); if ( fieldBindings.contains( var ) ) { return fc; } } } } return null; }
/** * This will return the FieldConstraint that a variable is bound to. * * @param var * The bound field variable (NOT bound fact). * @return null or the FieldConstraint found. */ public FieldConstraint getLHSBoundField(final String var) { if ( this.lhs == null ) { return null; } for ( int i = 0; i < this.lhs.length; i++ ) { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; for ( int j = 0; j < p.getFieldConstraints().length; j++ ) { FieldConstraint fc = p.getFieldConstraints()[j]; List<String> fieldBindings = getFieldBinding( fc ); if ( fieldBindings.contains( var ) ) { return fc; } } } } return null; }
/** * @param idx * Remove this index from the LHS. returns false if it was NOT * allowed to remove this item (ie it is used on the RHS). */ public boolean removeLhsItem(final int idx) { final IPattern[] newList = new IPattern[this.lhs.length - 1]; int newIdx = 0; for ( int i = 0; i < this.lhs.length; i++ ) { if ( i != idx ) { newList[newIdx] = this.lhs[i]; newIdx++; } else { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null && isBoundFactUsed( p.getBoundName() ) ) { return false; } } } } this.lhs = newList; return true; }
/** * @param idx * Remove this index from the LHS. returns false if it was NOT * allowed to remove this item (ie it is used on the RHS). */ public boolean removeLhsItem(final int idx) { final IPattern[] newList = new IPattern[this.lhs.length - 1]; int newIdx = 0; for ( int i = 0; i < this.lhs.length; i++ ) { if ( i != idx ) { newList[newIdx] = this.lhs[i]; newIdx++; } else { IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern(); } if ( pat instanceof FactPattern ) { final FactPattern p = (FactPattern) pat; if ( p.getBoundName() != null && isBoundFactUsed( p.getBoundName() ) ) { return false; } } } } this.lhs = newList; return true; }
IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern();
IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern();
IPattern pat = this.lhs[i]; if ( pat instanceof FromCompositeFactPattern ) { pat = ((FromCompositeFactPattern) pat).getFactPattern();