-
Get a monthly update on best practices for delivering successful software.
For those not wanting to hemorrhage the $10k plus for a development license of a BRE, there is a way of getting your feet wet with an open source rules engine: Drools
It is a real RETE (RETE OO, but who really cares?) implementation that you can use in your Java applications. There's even a .NET version in BETA.
Rules can be written in several "dialects," such as straight Java
<rule name="Bootstrap 2"> <parameter identifier="f"> <class>Fibonacci</class> </parameter> <java:condition>f.getSequence() == 2</java:condition> <java:condition>f.getValue() == -1</java:condition> <java:consequence> f.setValue( 1 ); System.err.println( f.getSequence() + " == " + f.getValue() ); drools.modifyObject( f ); </java:consequence></rule>
There are also dialects for Groovy, a java-like embedded scripting language, Python, etc. There is no "pseudo-natural language" dialect as yet, though this shouldn't be all that hard. Really, most commercial BRE's just rewrite method calls and expressions using a fairly primitive scheme, i.e. "IF truck.willFit(boxes)" translates to "IF the boxes will fit inside the truck." Of course the GUI IDE for this is a bit harder to write (though not impossible).
For me there's still and open question on whether "pseudo-natural language" is really all that useful, but more on that in a subsequent post.
Note that Drools version 2.x does not support the universal or existential quantifiers of first order logic (see here for why this is important), but it is already useful for many different applications and performs pretty well in comparison to many commercial products. Support for full first order logic is planned for 3.x.
Related posts:
Topics: Business Rules Engines, Open Source
There’s a slight error in your post. Drools 2 is not RETE. It is a simple forward chaining implementation and has major issues at the number of rules goes over 100. Drools 3 is full RETE and does support things like First Order Logic and truth maintenance. The old drools language is also being replaced with a newer CLIPS inspired language.
Pseudo-natural language is useful for narrowly defined domains like regulatory compliance. Things like 1940Act, FSA and other govern regulations. Other areas where pseudo-natural language works well is mortgage and lending scenarios. In those cases though, it’s really just a form of DSL (domain specific language).
It not like other pseudo-natural language attempts like “constrained english” which some researchers are working on.
peter
Comment by Peter Lin, Tuesday, April 4, 2006 @ 3:55 pm
Peter,
I’m not sure you’re correct. I’ve been through the Drools source code. It’s described as RETE-OO in the docs and bears enough resemblance to other RETE implementations I’ve seen to look like RETE. Specifically, it is building a network of conditionals and join nodes and has working memory and conflict resolution and all that good RETE jazz.
I know it has issues and doesn’t support full first order logic. I’ll accept that it might not be a good or complete implementation of RETE. What, though, makes you say that is isn’t RETE at all but instead a “simple forward chaining implementation?”
As for pseudo natural language, I’ll grant you that it can be useful in certain limited circumstances, but I’ve seen it lead to spaghetti code results if used improperly.
Comment by Dietrich Kappe, Tuesday, April 4, 2006 @ 4:12 pm
One reason Drools3 is a complete rewrite is that drools2 was only forward chaining. You can ask Mark and michael to verify that. I spent quite a bit of time in 2004 with Mark to figure out exactly where Drools2 differs from RETE. Drools3 core is based on a clean implementation of RETE I donated in 2005.
There are a couple of differences between drools2 and drools3.
I. drools2 did not store alpha memories. this affects retract and modify performance
II. drools2 beta node performed joins arbitrarily and the design took a list of facts for both left and right input. In drools3, the right input is a single fact and the left is still a list of facts
III. drools2 compiled the rules such that it didn’t follow Forgy’s description of the compilation algorithm. I have an old blog that describes this in detail, but I’m too lazy to dig it up
There are a few other differences which make drools2 a simple forward chaining engine. At one point, Mark revised the documentation on drools website to state drools2 “is inspired RETE, but does not conform to strict RETE.” Once work on Drools3 started, the was revised I believe. I don’t keep track of the website changes, but it was changed several times since december 2004.
One very easy way to prove that drools2 isn’t RETE is to load 200 rules and compare the results to 50 rules. There are actually many engines out there claiming to be RETE, but are not. For example, pychinko, and jena2 both claim to be RETE, but they are not. Neither exhibit the scalability of RETE when the number of rules increase or facts change during the inference cycle. I have several dozen blog entries that explains how and why pychinko and jena2 do not satisfy RETE algorithm.
I hope this clarifies things.
Comment by Peter Lin, Wednesday, April 5, 2006 @ 12:42 pm
I thought this might interest you.
http://woolfel.blogspot.com/2006/03/jess6-vs-drools3-vs-clips-623.html
I did a quick comparison in March between JESS, Clips and Drools3. The results aren’t final, but using the new RETE core, drools3 is now faster than clips6.2.
Comment by Peter Lin, Wednesday, April 5, 2006 @ 12:48 pm
Peter,
thanks for clarrifying this. Clearly my reading of the drools2 source code was superficial. But I think this points out why in fact so many commercial vendors have a hard time implementing RETE properly (or at all).
In their defense, the literature on the RETE algorithm isn’t exactly brimming with charm and friendliness. I have most of Forgy’s papers as well as the various books and articles on Jess and Clips, but I have yet to see one that would make sense to a 12th-grader.
Comment by Dietrich Kappe, Wednesday, April 5, 2006 @ 1:20 pm
Sadly, you’re 100% correct about the literature on RETE. I’ve probably read over 50 research papers on RETE and most of the suck. Many of them gloss over important details like why a betaNode needs to take a list of fact on the left-input and a single fact on the right-input. Doorenbos’ RETE-UL is one of the better papers, though it is still difficult for people to understand. Even though I work on rule engines, I have to read and re-read it to get the subtle details.
I’m generally a loud mouth about RETE for this reason. Many people have a hard time figuring out what RETE really is. Hopefully once I am done with the section on RETE for the new Drools3 manual, it will be a bit easier to understand. Not sure I can accomplish that, but I’m making an attempt.
peter
Comment by Peter Lin, Wednesday, April 5, 2006 @ 1:47 pm
If I have 5000 rules total. But I can group them into 20 or more rule sets. So I can create over 20 working memory and call them at run time.
In that case, which engine is better, drool or jess.
I compared between jess7 and drool 2 with 100 rules and call them 10000 times separately. It turns out drool 2 is faster. Not sure it’s correct result or not
Comment by Which rule is better, Tuesday, November 6, 2007 @ 6:22 pm