[rules-users] and/or connectives using DSL

mpturkia mturki at acxiom.com
Wed Apr 2 16:12:33 EDT 2008


Hey everyone,

I've been trying to figure out a way to use the OR connective in a similar
manner as the AND connective using the DSL definition, but can't quite
figure out how this could be done. Currently I can do the following:

rule "Rule1"
    when
        MyObject
        - value1 equals 5
        - value2 equals 10
        - value3 equals 15
    then
        System.out.println("Value1 is 5 and value2 is 10 and value3 is
15.");
end

DSL file looks like:
[when][]{obj}=$obj : {obj}()
[when][]- {var} equals {value}={var} == {value}

This results in the rule as:

rule "Rule1"
    when
        $obj : MyObject(value1 == 5, value2 == 10, value3 == 15)
    then
        System.out.println("Value1 is 5 and value2 is 10 and value3 is
15.");
end

What I would like to do is use OR as well instead of just and. So I would
like the rule to look like:

rule "Rule1"
    when
        MyObject
        - value1 equals 5
        - value2 equals 10
        OR value3 equals 15
    then
        System.out.println("Value1 is 5 and value2 is 10 or value3 is 15.");
end

This I'd like to result in a rule like:

rule "Rule1"
    when
        $obj : MyObject(value1 == 5, value2 == 10 || value3 == 15)
    then
        System.out.println("Value1 is 5 and value2 is 10 or value3 is 15.");
end

I don't want to use the 'or' command since that splits the rule into two
rules. I'd like to use the connective or '||' with the DSL syntax. Does
anybody know a work-around to get this working?

I've tried using sentence fragments to get it done, but the parser doesn't
match the patterns quite like I need them to match.

And of course, if there's a syntax already available (',' = '-', '||' = ??)
I'd be thrilled if someone pointed it out to me :)

Thanks!
Markus

-- 
View this message in context: http://www.nabble.com/and-or-connectives-using-DSL-tp16448654p16448654.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list