Package org.drools.workbench.models.datamodel.rule

Examples of org.drools.workbench.models.datamodel.rule.DSLSentence


        assertEquals( "$a",
                      pattern.getBoundName() );

        assertTrue( m.rhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslSentence = (DSLSentence) m.rhs[ 0 ];
        assertEquals( dslDefinition,
                      dslSentence.getDefinition() );
        assertEquals( 1,
                      dslSentence.getValues().size() );
        assertTrue( dslSentence.getValues().get( 0 ) instanceof DSLComplexVariableValue );
        DSLComplexVariableValue dslComplexVariableValue = (DSLComplexVariableValue) dslSentence.getValues().get( 0 );
        assertEquals( "Bob",
                      dslComplexVariableValue.getValue() );
        assertEquals( "\\w+ \\w+",
                      dslComplexVariableValue.getId() );
    }
View Full Code Here


        return false;
    }

    private DSLSentence toDSLSentence( final List<String> dslPatterns,
                                       final String dslLine ) {
        DSLSentence dslSentence = new DSLSentence();
        for ( String dslPattern : dslPatterns ) {
            // Dollar breaks the matcher, need to escape them.
            dslPattern = dslPattern.replace( "$",
                                             "\\$" );
            //A DSL Pattern can contain Regex itself, for example "When the ages is less than {num:1?[0-9]?[0-9]}"
            String regex = dslPattern.replaceAll( "\\{.*?\\}",
                                                  "(.*)" );
            Matcher matcher = Pattern.compile( regex ).matcher( dslLine );
            if ( matcher.matches() ) {
                dslPattern = dslPattern.replace( "\\$",
                                                 "$" );
                dslSentence.setDefinition( dslPattern );
                for ( int i = 0; i < matcher.groupCount(); i++ ) {
                    dslSentence.getValues().get( i ).setValue( matcher.group( i + 1 ) );
                }
                return dslSentence;
            }
        }
        dslSentence.setDefinition( dslLine );
        return dslSentence;
    }
View Full Code Here

        return false;
    }

    private DSLSentence toDSLSentence( List<String> dslPatterns,
                                       String dslLine ) {
        DSLSentence dslSentence = new DSLSentence();
        for ( String dslPattern : dslPatterns ) {
            // Dollar breaks the matcher, need to escape them.
            dslPattern = dslPattern.replace( "$", "\\$" );
            //A DSL Pattern can contain Regex itself, for example "When the ages is less than {num:1?[0-9]?[0-9]}"
            String regex = dslPattern.replaceAll( "\\{.*?\\}", "(.*)" );
            Matcher matcher = Pattern.compile( regex ).matcher( dslLine );
            if ( matcher.matches() ) {
                dslPattern = dslPattern.replace( "\\$", "$" );
                dslSentence.setDefinition( dslPattern );
                for ( int i = 0; i < matcher.groupCount(); i++ ) {
                    dslSentence.getValues().get( i ).setValue( matcher.group( i + 1 ) );
                }
                return dslSentence;
            }
        }
        dslSentence.setDefinition( dslLine );
        return dslSentence;
    }
View Full Code Here

        return false;
    }

    private DSLSentence toDSLSentence( final List<String> dslPatterns,
                                       final String dslLine ) {
        DSLSentence dslSentence = new DSLSentence();
        for ( String dslPattern : dslPatterns ) {
            // Dollar breaks the matcher, need to escape them.
            dslPattern = dslPattern.replace( "$",
                                             "\\$" );
            //A DSL Pattern can contain Regex itself, for example "When the ages is less than {num:1?[0-9]?[0-9]}"
            String regex = dslPattern.replaceAll( "\\{.*?\\}",
                                                  "(.*)" );
            Matcher matcher = Pattern.compile( regex ).matcher( dslLine );
            if ( matcher.matches() ) {
                dslPattern = dslPattern.replace( "\\$",
                                                 "$" );
                dslSentence.setDefinition( dslPattern );
                for ( int i = 0; i < matcher.groupCount(); i++ ) {
                    dslSentence.getValues().get( i ).setValue( matcher.group( i + 1 ) );
                }
                return dslSentence;
            }
        }
        dslSentence.setDefinition( dslLine );
        return dslSentence;
    }
View Full Code Here

        }
    }

    private DSLSentence toDSLSentence( List<String> dslPatterns,
                                       String dslLine ) {
        DSLSentence dslSentence = new DSLSentence();
        for ( String dslPattern : dslPatterns ) {
            //A DSL Pattern can contain Regex itself, for example "When the ages is less than {num:1?[0-9]?[0-9]}"
            String regex = dslPattern.replaceAll( "\\{\\s*[\\:\\[\\]\\?\\*\\+\\-\\.\\^\\$\\|\\(\\)\\w]+\\s*\\}", "(.*)" );
            Matcher m = Pattern.compile( regex ).matcher( dslLine );
            if ( m.matches() ) {
                dslSentence.setDefinition( dslPattern );
                for ( int i = 0; i < m.groupCount(); i++ ) {
                    dslSentence.getValues().get( i ).setValue( m.group( i + 1 ) );
                }
                return dslSentence;
            }
        }
        dslSentence.setDefinition( dslLine );
        return dslSentence;
    }
View Full Code Here

        assertNotNull( m );

        assertTrue( m.lhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslSentence = (DSLSentence) m.lhs[ 0 ];
        assertEquals( dslDefinition,
                      dslSentence.getDefinition() );
        assertEquals( 0,
                      dslSentence.getValues().size() );

        DSLSentence dslSentence2 = (DSLSentence) m.lhs[ 1 ];
        assertEquals( dslDefinition2,
                      dslSentence2.getDefinition() );
        assertEquals( 1,
                      dslSentence2.getValues().size() );

        assertTrue( dslSentence2.getValues().get( 0 ) instanceof DSLVariableValue );

        DSLVariableValue dslComplexVariableValue = dslSentence2.getValues().get( 0 );
        assertEquals( "123",
                      dslComplexVariableValue.getValue() );
    }
View Full Code Here

                                                                                             new ArrayList<String>(),
                                                                                             dmo,
                                                                                             new String[]{ dslFile } );

        assertEquals( 1, model.lhs.length );
        DSLSentence dslSentence = (DSLSentence) model.lhs[ 0 ];
        assertEquals( "test", dslSentence.getValues().get( 0 ).getValue() );
        assertEquals( "111", dslSentence.getValues().get( 1 ).getValue() );

    }
View Full Code Here

                                                                                             new ArrayList<String>(),
                                                                                             dmo,
                                                                                             new String[]{ dslFile } );

        assertEquals( 1, model.lhs.length );
        DSLSentence dslSentence = (DSLSentence) model.lhs[ 0 ];

        assertEquals( "Price is ${p}", dslSentence.getDefinition() );
        assertEquals( "111", dslSentence.getValues().get( 0 ).getValue() );

    }
View Full Code Here

        assertNotNull( m );

        assertTrue( m.lhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslSentence = (DSLSentence) m.lhs[ 0 ];
        assertEquals( dslDefinition,
                      dslSentence.getDefinition() );
        assertEquals( 1,
                      dslSentence.getValues().size() );
        assertTrue( dslSentence.getValues().get( 0 ) instanceof DSLComplexVariableValue );
        DSLComplexVariableValue dslComplexVariableValue = (DSLComplexVariableValue) dslSentence.getValues().get( 0 );
        assertEquals( "AA",
                      dslComplexVariableValue.getValue() );
        assertEquals( "ENUM:Applicant.creditRating",
                      dslComplexVariableValue.getId() );
    }
View Full Code Here

        assertEquals( "$a",
                      pattern.getBoundName() );

        assertTrue( m.rhs[ 0 ] instanceof DSLSentence );

        DSLSentence dslSentence = (DSLSentence) m.rhs[ 0 ];
        assertEquals( dslDefinition,
                      dslSentence.getDefinition() );
        assertEquals( 1,
                      dslSentence.getValues().size() );
        assertTrue( dslSentence.getValues().get( 0 ) instanceof DSLComplexVariableValue );
        DSLComplexVariableValue dslComplexVariableValue = (DSLComplexVariableValue) dslSentence.getValues().get( 0 );
        assertEquals( "Bob",
                      dslComplexVariableValue.getValue() );
        assertEquals( "\\w+ \\w+",
                      dslComplexVariableValue.getId() );
    }
View Full Code Here

TOP

Related Classes of org.drools.workbench.models.datamodel.rule.DSLSentence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.