[rules-users] Re: variable 'or' constraints with a DSL

Matt Geis mgeis at yahoo.com
Tue Jul 15 16:42:48 EDT 2008


Hi Reid,
There is a way to do this, but it doesn't involve the "-" (AND) hyphen shortcut.  You would write a regular DSL, and the RHS of your rule would be one line.

It's important to remember that DSL entry order is very important in your file.  The domain-specific code you write can (either intentionally or unintentionally) be expanded many times before it arrives at the DRL language that is fed into the rules engine.  In your case, the RHS of your rule will be tested once for a match against every "condition" entry in your DSL file.

What this means is that you want to first write your rule in standard drools syntax, then work backward to see how expansion of DSL entries slowly moves your DSL rule closer to, and ultimately into, a DRL rule.

You should be able to write something close to 

There is a person with {color} hair or with {color} eyes or that is {height} inches tall or that is {age} years old

You *might* have to use the variable typing feature new to Drools 5.0, but you may not.

A couple approaches that may help you out are...
1.  Write a unit test, and pass your DSL code through the DSLExpander and see what DRL code it generates (which may or may not be valid, but at least you'll see what the DSL engine is doing to your DSL rule).
2.  Download the source and use a step-through debugger with a breakpoint so you can examine the consequences of every match attempted against the RHS of the rule, and the consequent results of the replacement if a match is found.
3.  If you don't want to run a debugger, you could write some AOP code to emit the results of the RHS with each step of the expansion, but this approach would be more work than just running a debugger.

If you'd like to write a self-contained unit test with your DRL rule (the one that looks like the one I provided above, but verified to work), I can take a look at it and see what I'd do DSL-wise. 

Matt



      



More information about the rules-users mailing list