Package org.drools.rule

Examples of org.drools.rule.Pattern


    public void testEmptyIterator() {
        final InternalReadAccessor extractor = store.getReader( Cheese.class,
                                                                "type",
                                                                getClass().getClassLoader() );

        final Pattern pattern = new Pattern( 0,
                                             new ClassObjectType( Cheese.class ) );

        final Declaration declaration = new Declaration( "typeOfCheese",
                                                         extractor,
                                                         pattern );
View Full Code Here


    }

    @Test
    @Ignore
    public void test1() {
        Pattern p = new Pattern();
        QueryElement qe = new QueryElement( p,
                                            "queryName1",
                                            new Object[]{Variable.v, "x1", Variable.v, "x3", "x4",Variable.v,"x6",},
                                            new Declaration[0],
                                            new int[0],
View Full Code Here

        final ObjectType list1ObjectType = new ClassObjectType( String.class );
        final ObjectType list2ObjectType = new ClassObjectType( String.class );

        final Rule rule = new Rule( "rule-1" );

        final Pattern list1Pattern = new Pattern( 0,
                                               list1ObjectType,
                                               "s1" );
        final Pattern list2Pattern = new Pattern( 1,
                                               list2ObjectType,
                                               "s2" );

        rule.addPattern( list1Pattern );
        rule.addPattern( list2Pattern );
View Full Code Here

        final Rule rule = new Rule( "assignFirstSeat" );

        // -----------
        // context : Context( state == Context.START_UP )
        // -----------
        final Pattern contextPattern = new Pattern( 0,
                                                    this.contextType,
                                                    "context" );

        contextPattern.addConstraint( getLiteralConstraint( contextPattern,
                                                            "state",
                                                            Context.START_UP,
                                                            this.integerEqualEvaluator ) );

        rule.addPattern( contextPattern );

        final Declaration contextDeclaration = rule.getDeclaration( "context" );

        // -----------
        // guest: Guest()
        // -----------
        final Pattern guestPattern = new Pattern( 1,
                                                  this.guestType,
                                                  "guest" );

        rule.addPattern( guestPattern );

        final Declaration guestDeclaration = rule.getDeclaration( "guest" );

        // ------------
        // count : Count()
        // ------------
        final Pattern countPattern = new Pattern( 2,
                                                  this.countType,
                                                  "count" );

        rule.addPattern( countPattern );
View Full Code Here

        final Rule rule = new Rule( "findSeating" );

        // ---------------
        // context : Context( state == Context.ASSIGN_SEATS )
        // ---------------
        final Pattern contextPattern = new Pattern( 0,
                                                    this.contextType,
                                                    "context" );

        contextPattern.addConstraint( getLiteralConstraint( contextPattern,
                                                            "state",
                                                            Context.ASSIGN_SEATS,
                                                            this.integerEqualEvaluator ) );

        rule.addPattern( contextPattern );

        final Declaration contextDeclaration = rule.getDeclaration( "context" );

        // -------------------------------
        // Seating( seatingId:id, seatingPid:pid, pathDone == true
        // seatingRightSeat:rightSeat seatingRightGuestName:rightGuestName )
        // -------------------------------
        final Pattern seatingPattern = new Pattern( 1,
                                                    this.seatingType );

        setFieldDeclaration( seatingPattern,
                             "id",
                             "seatingId" );

        setFieldDeclaration( seatingPattern,
                             "pid",
                             "seatingPid" );

        seatingPattern.addConstraint( getLiteralConstraint( seatingPattern,
                                                            "pathDone",
                                                            true,
                                                            this.booleanEqualEvaluator ) );

        setFieldDeclaration( seatingPattern,
                             "rightSeat",
                             "seatingRightSeat" );

        setFieldDeclaration( seatingPattern,
                             "rightGuestName",
                             "seatingRightGuestName" );

        rule.addPattern( seatingPattern );

        final Declaration seatingIdDeclaration = rule.getDeclaration( "seatingId" );
        final Declaration seatingPidDeclaration = rule.getDeclaration( "seatingPid" );
        final Declaration seatingRightGuestNameDeclaration = rule.getDeclaration( "seatingRightGuestName" );
        final Declaration seatingRightSeatDeclaration = rule.getDeclaration( "seatingRightSeat" );
        // --------------
        // Guest( name == seatingRightGuestName, rightGuestSex:sex,
        // rightGuestHobby:hobby )
        // ---------------
        final Pattern rightGuestPattern = new Pattern( 2,
                                                       this.guestType );

        rightGuestPattern.addConstraint( getBoundVariableConstraint( rightGuestPattern,
                                                                     "name",
                                                                     seatingRightGuestNameDeclaration,
                                                                     this.objectEqualEvaluator ) );

        setFieldDeclaration( rightGuestPattern,
                             "sex",
                             "rightGuestSex" );

        setFieldDeclaration( rightGuestPattern,
                             "hobby",
                             "rightGuestHobby" );

        rule.addPattern( rightGuestPattern );

        final Declaration rightGuestSexDeclaration = rule.getDeclaration( "rightGuestSex" );
        final Declaration rightGuestHobbyDeclaration = rule.getDeclaration( "rightGuestHobby" );

        // ----------------
        // Guest( leftGuestName:name , sex != rightGuestSex, hobby ==
        // rightGuestHobby )
        // ----------------
        final Pattern leftGuestPattern = new Pattern( 3,
                                                      this.guestType );

        setFieldDeclaration( leftGuestPattern,
                             "name",
                             "leftGuestName" );

        leftGuestPattern.addConstraint( getBoundVariableConstraint( rightGuestPattern,
                                                                    "hobby",
                                                                    rightGuestHobbyDeclaration,
                                                                    this.objectEqualEvaluator ) );

        leftGuestPattern.addConstraint( getBoundVariableConstraint( leftGuestPattern,
                                                                    "sex",
                                                                    rightGuestSexDeclaration,
                                                                    this.objectNotEqualEvaluator ) );

        rule.addPattern( leftGuestPattern );
        final Declaration leftGuestNameDeclaration = rule.getDeclaration( "leftGuestName" );

        // ---------------
        // count : Count()
        // ---------------
        final Pattern count = new Pattern( 4,
                                           this.countType,
                                           "count" );

        rule.addPattern( count );

        final Declaration countDeclaration = rule.getDeclaration( "count" );

        // --------------
        // not ( Path( id == seatingId, guestName == leftGuestName) )
        // --------------
        final Pattern notPathPattern = new Pattern( 5,
                                                    this.pathType );

        notPathPattern.addConstraint( getBoundVariableConstraint( notPathPattern,
                                                                  "id",
                                                                  seatingIdDeclaration,
                                                                  this.integerEqualEvaluator ) );

        notPathPattern.addConstraint( getBoundVariableConstraint( notPathPattern,
                                                                  "guestName",
                                                                  leftGuestNameDeclaration,
                                                                  this.objectEqualEvaluator ) );
        final GroupElement notPath = GroupElementFactory.newNotInstance();
        notPath.addChild( notPathPattern );
        rule.addPattern( notPath );
        // ------------
        // not ( Chosen( id == seatingId, guestName == leftGuestName, hobby ==
        // rightGuestHobby ) )
        // ------------
        final Pattern notChosenPattern = new Pattern( 6,
                                                      this.chosenType );

        notChosenPattern.addConstraint( getBoundVariableConstraint( notChosenPattern,
                                                                    "id",
                                                                    seatingIdDeclaration,
                                                                    this.integerEqualEvaluator ) );

        notChosenPattern.addConstraint( getBoundVariableConstraint( notChosenPattern,
                                                                    "guestName",
                                                                    leftGuestNameDeclaration,
                                                                    this.objectEqualEvaluator ) );

        notChosenPattern.addConstraint( getBoundVariableConstraint( notChosenPattern,
                                                                    "hobby",
                                                                    rightGuestHobbyDeclaration,
                                                                    this.objectEqualEvaluator ) );

        final GroupElement notChosen = GroupElementFactory.newNotInstance();
View Full Code Here

        final Rule rule = new Rule( "makePath" );

        // -----------
        // context : Context( state == Context.MAKE_PATH )
        // -----------
        final Pattern contextPattern = new Pattern( 0,
                                                    this.contextType );

        contextPattern.addConstraint( getLiteralConstraint( contextPattern,
                                                            "state",
                                                            Context.MAKE_PATH,
                                                            this.integerEqualEvaluator ) );

        rule.addPattern( contextPattern );

        // ---------------
        // Seating( seatingId:id, seatingPid:pid, pathDone == false )
        // ---------------
        final Pattern seatingPattern = new Pattern( 1,
                                                    this.seatingType );

        setFieldDeclaration( seatingPattern,
                             "id",
                             "seatingId" );

        setFieldDeclaration( seatingPattern,
                             "pid",
                             "seatingPid" );

        seatingPattern.addConstraint( getLiteralConstraint( seatingPattern,
                                                            "pathDone",
                                                            false,
                                                            this.booleanEqualEvaluator ) );

        rule.addPattern( seatingPattern );

        final Declaration seatingIdDeclaration = rule.getDeclaration( "seatingId" );
        final Declaration seatingPidDeclaration = rule.getDeclaration( "seatingPid" );

        // -----------
        // Path( id == seatingPid, pathGuestName:guestName, pathSeat:seat )
        // -----------
        final Pattern pathPattern = new Pattern( 2,
                                                 this.pathType );

        pathPattern.addConstraint( getBoundVariableConstraint( pathPattern,
                                                               "id",
                                                               seatingPidDeclaration,
                                                               this.integerEqualEvaluator ) );

        setFieldDeclaration( pathPattern,
                             "guestName",
                             "pathGuestName" );

        setFieldDeclaration( pathPattern,
                             "seat",
                             "pathSeat" );

        rule.addPattern( pathPattern );

        final Declaration pathGuestNameDeclaration = rule.getDeclaration( "pathGuestName" );
        final Declaration pathSeatDeclaration = rule.getDeclaration( "pathSeat" );
        // -------------
        // (not Path( id == seatingId, guestName == pathGuestName )
        // -------------
        final Pattern notPathPattern = new Pattern( 3,
                                                    this.pathType );

        notPathPattern.addConstraint( getBoundVariableConstraint( notPathPattern,
                                                                  "id",
                                                                  seatingIdDeclaration,
                                                                  this.integerEqualEvaluator ) );
        notPathPattern.addConstraint( getBoundVariableConstraint( notPathPattern,
                                                                  "guestName",
                                                                  pathGuestNameDeclaration,
                                                                  this.objectEqualEvaluator ) );

        final GroupElement not = GroupElementFactory.newNotInstance();
View Full Code Here

        final Rule rule = new Rule( "pathDone" );

        // -----------
        // context : Context( state == Context.MAKE_PATH )
        // -----------
        final Pattern contextPattern = new Pattern( 0,
                                                    this.contextType,
                                                    "context" );

        contextPattern.addConstraint( getLiteralConstraint( contextPattern,
                                                            "state",
                                                            Context.MAKE_PATH,
                                                            this.integerEqualEvaluator ) );

        rule.addPattern( contextPattern );
        final Declaration contextDeclaration = rule.getDeclaration( "context" );

        // ---------------
        // seating : Seating( pathDone == false )
        // ---------------
        final Pattern seatingPattern = new Pattern( 1,
                                                    this.seatingType,
                                                    "seating" );

        seatingPattern.addConstraint( getLiteralConstraint( seatingPattern,
                                                            "pathDone",
                                                            false,
                                                            this.booleanEqualEvaluator ) );

        rule.addPattern( seatingPattern );
View Full Code Here

        final Rule rule = new Rule( "areWeDone" );

        // -----------
        // context : Context( state == Context.CHECK_DONE )
        // -----------
        final Pattern contextPattern = new Pattern( 0,
                                                    this.contextType,
                                                    "context" );

        contextPattern.addConstraint( getLiteralConstraint( contextPattern,
                                                            "state",
                                                            Context.CHECK_DONE,
                                                            this.integerEqualEvaluator ) );

        rule.addPattern( contextPattern );
        final Declaration contextDeclaration = rule.getDeclaration( "context" );

        // ---------------
        // LastSeat( lastSeat: seat )
        // ---------------
        final Pattern lastSeatPattern = new Pattern( 1,
                                                     this.lastSeatType );

        setFieldDeclaration( lastSeatPattern,
                             "seat",
                             "lastSeat" );

        rule.addPattern( lastSeatPattern );
        final Declaration lastSeatDeclaration = rule.getDeclaration( "lastSeat" );
        // -------------
        // Seating( rightSeat == lastSeat )
        // -------------
        final Pattern seatingPattern = new Pattern( 2,
                                                    this.seatingType,
                                                    null );

        seatingPattern.addConstraint( getBoundVariableConstraint( seatingPattern,
                                                                  "rightSeat",
                                                                  lastSeatDeclaration,
                                                                  this.integerEqualEvaluator ) );

        rule.addPattern( seatingPattern );
View Full Code Here

        final Rule rule = new Rule( "continueProcessng" );

        // -----------
        // context : Context( state == Context.CHECK_DONE )
        // -----------
        final Pattern contextPattern = new Pattern( 0,
                                                    this.contextType,
                                                    "context" );

        contextPattern.addConstraint( getLiteralConstraint( contextPattern,
                                                            "state",
                                                            Context.CHECK_DONE,
                                                            this.integerEqualEvaluator ) );

        rule.addPattern( contextPattern );
View Full Code Here

        final Rule rule = new Rule( "alldone" );

        // -----------
        // context : Context( state == Context.PRINT_RESULTS )
        // -----------
        final Pattern contextPattern = new Pattern( 0,
                                                    this.contextType );

        contextPattern.addConstraint( getLiteralConstraint( contextPattern,
                                                            "state",
                                                            Context.PRINT_RESULTS,
                                                            this.integerEqualEvaluator ) );

        rule.addPattern( contextPattern );
View Full Code Here

TOP

Related Classes of org.drools.rule.Pattern

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.