No viable alternative at input 'or' in rule

397 views
Skip to first unread message

Jonathan MERCIER

unread,
Sep 16, 2015, 7:43:30 AM9/16/15
to Drools Usage
rule "Foo"
when
    $k
:= PriorKnowledge( )
    $tt
: TruthTable( logic == $k.logic )
    $child1
: PriorKnowledge( $k memberOf partOf, presence != $k.presence )
    $csp1
: StatePriority( state == $child1.presence, logic == $k.logic ) from $tt.priorities
   
(
       
or
       
not ( PriorKnowledge( this != $child1, $k memberOf partOf, presence != $k.presence ) )
       
not(
           
and      
            $child2
: PriorKnowledge( this != $child1, $k memberOf partOf, presence != $k.presence )
           
StatePriority( state == $child2.presence, logic == $k.logic, priority > $csp1.priority ) from $tt.priorities
       
)
   
)
then
    modify
( $k ){
        presence
= $child1.presence;
   
}
end

Dear,

I am trying to group two case in one rules with the same consequence but that fail ...
Line 19:8 no viable alternative at input 'or' in rule


I tried to tell
If they are no PriorKnowledge who are a child of $k
or 
it do not exist a child with an object StatePrioty greater than the first child selected

I have not used named consequence as if case 1 or 2 are true is the same consequence

Thanks for you help

Jonathan MERCIER

unread,
Sep 16, 2015, 8:28:41 AM9/16/15
to Drools Usage
Some examples:

the code who fails:

rule "Foo"
when
    $k :=       PriorKnowledge( )
    $tt:=       TruthTable( logic == $k.logic )
    $child1:=   PriorKnowledge( $k memberOf partOf, presence != $k.presence )
    $csp1:=     StatePriority( state == $child1.presence, logic == $k.logic ) from $tt.priorities
    (or
    (and
    $child2:    PriorKnowledge( this != $child1, $k memberOf partOf, presence != $k.presence )
    $csp2:      StatePriority( state == $child2.presence, logic == $k.logic, priority <= $csp1.priority ) from $tt.priorities
    )
    not ( PriorKnowledge( this != $child1, $k memberOf partOf, presence != $child1.presence ) )
    )
then
    modify( $k ){
        presence = $child1.presence;
    }
end

That work with 2 rules:

rule "Foo 1"

when
    $k
:=       PriorKnowledge( )

    $tt
:=       TruthTable( logic == $k.logic )
    $child1
:=   PriorKnowledge( $k memberOf partOf, presence != $k.presence )
    $csp1
:=     StatePriority( state == $child1.presence, logic == $k.logic ) from $tt.priorities
    $child2
:    PriorKnowledge( this != $child1, $k memberOf partOf, presence != $k.presence )
    $csp2
:      StatePriority( state == $child2.presence, logic == $k.logic, priority <= $csp1.priority ) from $tt.priorities
then
    modify
( $k ){
        presence
= $child1.presence;
   
}
end



rule
"Foo 2"

when
    $k
:=       PriorKnowledge( )

    $tt
:=       TruthTable( logic == $k.logic )
    $child1
:=   PriorKnowledge( $k memberOf partOf, presence != $k.presence )
    $csp1
:=     StatePriority( state == $child1.presence, logic == $k.logic ) from $tt.priorities
   
not ( PriorKnowledge( this != $child1, $k memberOf partOf, presence != $child1.presence ) )

then
    modify
( $k ){
        presence
= $child1.presence;
   
}
end

is it possible to merge these 2 rules?

Marian Buenosayres

unread,
Sep 23, 2015, 8:50:28 PM9/23/15
to Drools Usage
I think the problem here is that you're placing the 'or' in the wrong place. You're writing (or exp1 exp2) when it should be (exp1 or exp2). The same for the 'and' nested inside.

Mark Proctor

unread,
Sep 23, 2015, 8:57:24 PM9/23/15
to drools...@googlegroups.com
We are suppose to support either infix or postfix and/or notations. This was partly due to the two disciplines - whether you come form Lisp (Jess/Clips) or Java.

Most likely there is parser error when using prefix with a child not or exists - but we’d need a unit test to be sure.

For now Marian's work around is good approach.

Please do submit a unit test for this :)


Mark


--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-usage/c243d913-3d4d-42a8-bbb2-c1e53074d1ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages