Wednesday, May 30, 2007

Cleaning up the ANTLR DRL grammar (Edson Tirelli)

Yesterday I had the pleasure to work with Terence Parr on cleaning up the DRL grammar. All I can say is that I can't recommend him enough. He is an awesome person, extremely professional and knows about what he is talking.

The tasks he accomplished were:

1. He started solving ambiguities in the grammar rules to turn the backtracking option off, since that makes the parsing process a bit lighter. To do that, some of Terence's magic was required, but it all looks great after he did.

2. Then, he moved on to fix some keyword clashes we still had in the DRL files. In the end, we basically reduced the set of reserved keywords to:
  • and
  • or
  • not
  • exists
  • eval
  • forall
So, be aware... do not use any of the above keywords in your fields, package names, etc, otherwise you will end up with parsing errors.

3. Third task of the day was a wish from Mark to have DRL syntax to support prefixed "or" and "and" for patterns. So now you will be able to write:

rule X
when
A() or B() and C() or D()
then
// do something
end

Or, if you are a LISPer, you may prefer:

rule X
when
(and (or A() B()) (or C() D()))
then
// do something
end

Both syntax are equivalent.

4. Fourth item was to design a strategy to improve exception handling. This is a very difficult task when the parser is used by an IDE that requires incomplete ASTs to be built, error recovery and absolute friendly messages. Terence gave us some suggestion and showed some features ANTLR offers. That will still require a good amount of work to get it right.

5. The fifth item was the discussion of how to improve the parsing process to provide more information for tools using it, like the eclipse plugin and the BRMS. Terence mentioned that incremental parsing is in the pipeline for new ANTLR versions, but not available yet. On our side (Drools), we will put some effort on adding support for that in the grammar after 4.0 release.

6. Finally, Terence went over our whole grammar and did a complete analysis, highlighting problems and providing suggestions on how to fix them. Most is manual work, since the real ambiguity problems he had already fixed. The problems left were eventual use of deprecated syntax or rules that we could have written in a more succinct way.

All in all, nothing is better than having the expert advising us on how things should be.

If you use ANTLR as your parser and wants some help, go straight to the source and buy support. You will not regret. And surely Drools users will be able to see that in the versions to come.

Happy Drooling
Edson

[edit: added info about incremental parsing]

Saturday, May 26, 2007

Dynamic Salience Expressions

The other week in the mailing list someone was asking about whether it's possible to have the salience's value derived from the matched facts. Which got me thinking as I haven't seen that in any other rule engines - I only know a few engines, so someone with more experience care to verify that?

Anyway a few weeks later and a bored friday night dynamic salience expressions are born :) The salience value can now be derived from an expression that has full access to the variables bindings, ofcourse integer values can still be specified. Before, during conflict resolution, the salience value was read directly from the rule on each comparison, now when the Activation is created the salience value is determined once and stored in the Activation for comparison during conflict resolution. So now you can write things like have rules with the highest priced items combined with the shoppers bonus rating fire first:
rule "high value fires first"
salience (person.bonus * item.price)
when
person : Person()
item : Item()
then
...
end


MVEL is used for the salience expressions, as part of the pluggeable dialect system we have just built - I'll blog on pluggeable dialects and parsers next week.

Update -- Thanks to Johan Lindberg, who has pointed out that Clips and Jess allow the salience to be set via function calls in Jess/Clips.

Thursday, May 24, 2007

Quick Start tutorial/movie for BRMS (Michael Neale)

I have created the first Quick Start movie, which is an introductory tutorial to the BRMS.

This is my first attempt using "Wink" - and I realized that I had the screen resolution set too high after the fact, so consider this a practice run. I would appreciate any feedback on this. Click the image below to display the window in a popup.





Those having problems with the popup window can use this url directly:
http://wiki.jboss.org/wiki/_Files/RulesRepository/QuickStart.swf

Wednesday, May 23, 2007

Working with JBoss Rules and Web Services

I've recently just done a project where JBoss Rules was used via web services. So thought I'd detail parts of what I did.

With this particular project only the root object from the payload was asserted, the payload was not split into smaller relational objects and asserted, which is generally considered best practice; however we do show you here how to effectively work with nested XML payloads using 'from'.

The steps I undertook can roughly be defined as:
  1. Create an XSD for your model.
  2. Generate the classes using JAXB's XJC, command line seems to have less issues.
  3. Unmarshal in your XML payload and assert the root object.
  4. Use from in your rules for model navitation.
  5. Retrieve the modified model and marshal.

Create an XSD for your model
First you need an XSD that describes your mode, this will look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="creditscore" targetNamespace="creditscore">
<xs:complexType name="root">
<xs:sequence>
<xs:element name="division" type="xs:string"/>
<xs:element name="occupancy" type="xs:string"/>
<xs:element name="occupancyAdjustment" type="xs:double"/>
<xs:element name="creditScore" type="CreditScore" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="CreditScore">
<xs:sequence>
<xs:element name="programGroup" type="xs:string"/>
<xs:element name="lienType" type="xs:string"/>
<xs:element name="division" type="xs:string"/>
<xs:element name="score" type="xs:double"/>
</xs:sequence>
</xs:complexType>

<xs:element name="Root" type="root"/>
</xs:schema>
Generate the classes using JAXB's XJC
The pojo model can now be created using JAXB's XJC. Get the latest JAXB reference implementation from sun, https://jaxb.dev.java.net/, I used jaxb 2.1.3. And execute the following from the command line:
jaxb-ri-20070413\bin\xjc -p org.domain -d c:\folder MyModel.xsd
This creates three objects, the ObjectFactory plus the two classes that represent Root and CreditScore, which look like this:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "root", propOrder = {"division", "occupancy", "occupancyAdjustment", "creditScore1", "creditScore2"})
public class Root {
@XmlElement(required = true)
protected String division;
@XmlElement(required = true)
protected String occupancy;
protected double occupancyAdjustment;
protected CreditScore creditScore1;
protected List creditScore2;

public String getDivision() {
return division;
}

public void setDivision(String value) {
this.division = value;
}

public String getOccupancy() {
return occupancy;
}

public void setOccupancy(String value) {
this.occupancy = value;
}

public double getOccupancyAdjustment() {
return occupancyAdjustment;
}

public void setOccupancyAdjustment(double value) {
this.occupancyAdjustment = value;
}

public CreditScore getCreditScore1() {
return creditScore1;
}

public void setCreditScore1(CreditScore value) {
this.creditScore1 = value;
}

public List getCreditScore2() {
if ( creditScore2 == null ) {
creditScore2 = new ArrayList();
}
return this.creditScore2;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "CreditScore", propOrder = {"programGroup", "lienType", "division", "score"})
public class CreditScore {

@XmlElement(required = true)
protected String programGroup;
@XmlElement(required = true)
protected String lienType;
@XmlElement(required = true)
protected String division;
protected double score;

public String getProgramGroup() {
return programGroup;
}

public void setProgramGroup(String value) {
this.programGroup = value;
}

public String getLienType() {
return lienType;
}

public void setLienType(String value) {
this.lienType = value;
}

public String getDivision() {
return division;
}

public void setDivision(String value) {
this.division = value;
}

public double getScore() {
return score;
}

public void setScore(double value) {
this.score = value;
}
}
Unmarshal in your XML payload and assert the root object
You can now use JAXB to unmarshal your XML payloads, this example just takes the payload from disk:
JAXBContextImpl jc = (JAXBContextImpl) JAXBContext.newInstance( "org.domain" );
Unmarshaller unmarshaller = jc.createUnmarshaller();
JAXBElement element = ( JAXBElement ) unmarshaller.unmarshal( new File( XML_FILE ) );
Root root = ( Root ) element.getValue();
Use from in your rules for model navitation
'from' is a new element in JBoss Rules 4.0 that allows a rule to localy reason over data not asserted into the working memory. We can use 'from' to navigate to sub objects in the model.
package creditscore

import creditscore.CreditScore

rule "Credit_Score_Adjustments_0"
dialect "mvel"
no-loop true
when
r : Root( division=="wholesale",
occupancy=="Investors" )
cs : CreditScore( programGroup=="ACMEPowerBuyerGroup",
lienType=="FIRST_TD; SECOND_TD",
division=="Wholesale",
score >= 500,
score <= 579) from r.creditscore
then
cs.score = cs.score + 1;
modify(cs);
end

Retrieve the modified model and marshal
 RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );

StatelessSession session = ruleBase.newStatelessSession();

StatelessSessionResult results = session.executeWithResults( new Object[] { root } );

Root returnedRoot = ( Root ) results.iterateObjects().next();
Marshaller marshaller = jc.createMarshaller();
marshaller.marshal( new JAXBElement( new QName("org.domain", "Root"), returnedRoot.getClass(), returnedRoot ), System.out );

Whats new in JBoss Rules 4.0 (link now fixed)

Today I had to give a 20 minute presentation on what's new in JBoss Rules 4.0. Obviously we have so much stuff we can't possibly get all of that across in 20 minutes, but I hope that I got the main points of interest in there. Anyway I thought others might be interested in the presentation, enjoy.

Whats new in JBoss Rules 4.0.pdf

Mark

Update 23-may-07
Sorry the link for this page was broken, it's now fixed.

Monday, May 21, 2007

Why the MVEL scipting language for JBoss Rules

I'm currently working hard to finish off the pluggeable dialect system, this is similar to the semantic modules we had in Drools 2.0. With this people will be able to write drl dialect implementatinos for any language they like and then users can use that language to author their predicates, return values, evals and consequences. We will be supporting two dialect implementations one for Java and another for MVEL, http://mvel.codehaus.org/. So of couse the first thing people ask is why MVEL, why not Groovy, Jython etc, so I put the following together:
  • Reflection/bytecode(JIT) compilation and execution modes.
    • For huge systems we need to be able to avoid excessive bytecode generation, but still have the option for bytecode JIT for performance sensitive areas.
  • Fast reflection mode.
    • We originally started with our own language JFDI, which was designed to be a simple and fast reflection based language, the idea is all work is done at compile time so runtime is just a series of reflection invokers. This design has been carried through to MVEL, so that it has good enough reflection performance. Where as other languages have to drop reflection mode and use bytecode to get any reasonable level of performance.
  • Pluggeable resolvers.
    • Dictionary population is too slow, MVEL can resolve it's variable direct from the provided resolvers, which we make array based for performance.
  • Size.
    • MVEL is currently < 350K
  • Custom language extensions.
    • MVEL is extending the language to support rule friendly constructs, in particular block setters. So I can do "modify (person) ( age += 1, location = "london" )" with the ability to treat that as a transaction block so I can run before and after interceptors on the entire block. This is made easier through the use of macros, so we can define our own keywords and have them expanded into mvel code.
  • Static/Inferred typed or dynamic modes.
    • Variables can be untyped and totally dynamic.
    • Variables can be statically typed or type can be inferred, casting is supported.
    • Optional verifier for "typed mode", disallows dynamic variables and ensures all types and method calls are correct. Which helps with.
      • Authoring time validation.
      • Code completion.
      • Refactoring.
  • Configurable language feature support.
    • Language features can be turned off.
    • We don't want imperative flow structures in the "then" part, no 'if' 'switch' etc. Rules should be declarative, "when this do that" not "when this maybe do that".
MVEL is BSF compliant and will soon support EL too. MVEL is already a superset of EL, but it doesn't yet support some of the esoteric features like having different ways to express equality.

Saturday, May 19, 2007

Making decisions with Rule Flow and more wonderful screenshots :)

Kris has worked his magic again and it's now possible to make decisions on 'split' and 'join' nodes in Rule Flow. 'split' nodes now support 'and', 'or' and 'xor' type decisions while 'join' supports 'and' and 'or'. The beautiful part of this is its fully tooled and the decisions are specialised rules, so you can leverage the facts in the working memory and our powerful rule language.

The first screenshot (click to enlarge) shows the Constraint Editor on a 'split' node with an entry for each branch. At the bottom you will see the standard properties editor with the properties for the 'split' node, the node type is 'xor' and if you click the dotted builder icon on the constraints property it opens the Constraint Editor.

This screenshot (click to enlarge) shows the form used while editing the constraints for a particular branch. Note how you can use standard left hand side (LHS) language statements. We still have to get context assist and code highlighting into the editor, but that will be coming soon, I just have to persuade Kris to give up sleep this weekend :)

JBoss Rules expressiveness goes to the next level

Edson has been doing great work on the expressiveness of rules, it's now possible to use && and || on field values and between fields themselves inside of a Pattern:

Person( age > 30 && < 40 || hair =="black" )
Note the || here is different than the 'or' conditional element, which works on patterns and results in subrule generation, where each logical outcome is generated as a rule.

As part of Milestone Release 2 we already have autovivification of the field names inside of predicates and return value statemets to reduce the number of field variable declarations, which causes clutter in rules.

Cheese( oldPrice : oldPrice, newPrice == ( oldPrice * 1.10 ) )
Can now be written as:

Cheese( newPrice == ( oldPrice * 1.10 ) )
Next we are reducing created declarations for variable bindings by allowing direct access to the properties on a pattern binding declaration, note this does not include nested properties or the direct properties of a field declaration, this should further help with the readabilty of rules:

p : Person(personId : id)
i : Item(id == personId, value > 100 )
Will soon be able to write as:

p : Person()
i : Item(id == p.id, value > 100 )
The final change we hope to do in time for 4.0, which is our most requested feature, is to allow nested properties, array and hashmap access to be expressed as field constraints rather than as predicates, return value or evals. I should mention at this stage that there are a number of complications and issues with regards to nested properties, arrays and hashmaps in rule engines that many users are not aware of; the issue is similar to hashmap keys where the hashcode or fields are changed making the key and its object irretrievable and thus causing memory leaks. Internally what will really happen is that we will rewrite these expressions as an eval and execute using MVEL.

Person($pets:pets)
eval($pets['rover'].type == "dog")
Will soon be able to write as:
Person( pets['rover'].type == "dog" )
This puts JBoss Rules firmly on the road to being one of the most expressive rule engines :)

Friday, May 18, 2007

Antlr 3.0 Released

Antlr 3.0 has been released, see the announcement at TSS. I can't say enough about this fanastic tool, it's work like this that will be the underpinnings on the next generation languages. Terence, here's to another 4 years of Antlr development, I can't wait for incremental parsing and for someone to port AntlrWorks to Eclipse :)

Saturday, May 12, 2007

Phoenix JUG: JBoss Rules - Apollo Group Inc

Tim Shadel, an IT Manager at Apollo Group Inc, did a JBoss Rules presentation for the Pheonix JUG and made the pdf available in his blog, which I have also made available here. Apollo Group Inc is a S&P 500 company that provides adult education services. The stats he provides in the presentation make for interesting read so I've reproduced them below.

Background: National Qualiyfing Centre

  • 200,000+ phone calls per day
  • ~400 qualifying specialists
  • 70+ ground campuses
  • ~6,000 enrollment counselors
  • ~500 specialized groups
    • Geography
    • Program
    • Bachkelor's, Master's, etc.
Rules are used for:
  • Routing
  • Managing the call script
Setup
  • 700+ routing rules
  • ~450,000 test scenarios
  • ~2.5mins test execution
  • => ~3,000 scnearios/second (3 scenarios/millisecond)

Friday, May 11, 2007

The BRMS has landed - with Screenshots :) (Michael Neale)

The BRMS (Business Rule Management System) has been in the works for sometime. Well, finally, there is something you can use, which works end to end. This is now part of the JBoss Rules 4 Milestone releases, so please, go ahead and start testing it ! There has been great work going on elsewhere in Drools, with respect to the language features, core engine enhancements and the IDE as well (see previous posts).

For a very interim user guide, you can refer to the wiki Quick Start for BRMS. Much more documentation, tutorials etc is on the way.

You can use the milestone releases, or ideally the snapshots (as found here, referring to the wiki link above to make sure you have the latest info, also keep an eye on this blog).

The best way to get going is to take a look at the quick start guide (linked above) and also have some ideas for a model that you want to write rules over (as one of the first things you will do is configure a package).

As always, you can contribute: helpful bug reports are appreciated, as are contributing some specific examples. The wiki is also available to record notes/tips, which can feed into the manual/documentation. I plan on working on a flash based tutorial (a few tutorials will be needed to introduce the concept).

So, the whet the appetite, some screen shots, which show some of the new rule authoring capabilities, as well as the life cycle management are shown (they are not in any particular order, but you can guess what most of them are showing !).





Eclipse VE has become dormant

Seems Eclipse Visual Editor (VE) has hit hard times, see David Orme's blog, this is a very sad place for Eclipse to be with no FOSS alternative to Netbeans Matisee; I don't think the importance of a high quality FOSS GUI builder for SWT and JFACE should be underestimated. There is still the excellent commercial tool from Instantians, maybe IBM could acquire them and roll their tooling into Eclipse - this would help create a world class GUI platform for Eclipse.

JBoss Rules SNAPSHOT Builds

Hudson is currently running internally at JBoss, polling every 12 minutes, we hope to eventually make this box external. The results of every successful build are however made public and can currently be found at this url http://cruisecontrol.jboss.com/cc/artifacts/jboss-rules.

So now you can always enjoy the latest JBoss Rules goodness - enjoy :)

Wednesday, May 09, 2007

JBoss Rules 4.0 Milestone Release 2 is now available

JBoss Rules 4.0 Milestone Release 2 is now available. It includes the new BRMS system and Rule Flow.

Downloads
Release Notes

Sunday, May 06, 2007

Event Stream Processing, Complex Event Processing and Rules Engines (Edson Tirelli)

(content originally posted at my personal blog)

For those wondering why I finally decided to create my own blog, it all started in my last class of Non-Classic Logics at USP. The teacher was explaining about one of the temporal logics that were formalized, known as Logic US (that stands for Until/Since).

At that moment, something clicked and I remembered Mark commenting about supporting CEP/ESP as an extension to the Rete engine we have implemented in JBoss Rules. It seemed a perfect match: supporting temporal logic would give us all we need to also reason over stream of events. I wish it was that simple.

Yesterday I spent the day looking for information about possible research that might have been done and what is the state of the art in the field. I confess, besides having a reasonable knowledge of Rete, I have no experience in ESP/CSP.

As you can imagine, there is a huge amount of information about it in the internet and I couldn't find/read it all, but so far, the following is what I was able to gather (trying a top-down approach).

Event Driven Architecture

First thing I tried to understand is the terminology, the use cases and state of the art in the ESP/CEP field, and I ended up reading this excellent post by Brenda Michelson, where she provides an overview of the terminology and how they relate to each other. I will not repeat here all what she says, but I found specially interesting the Event Driven Architecture she describes there. From it, I was able to define the boundaries of my current research.
What I'm interested is in how we can leverage the features of a rules engine, more specifically a Rete implementation, to handle CEP and ESP. In other words, from the reference architecture she mentions, I'm interested in the Event Processing Engine component.

ESP and CEP

ESP and CEP have quite a lot of information published. From David Luckham's excellent site, to university research projects, to products developed to do it, like Esper and StreamCruncher. A very prolific field.

Rules Engines

Besides all that information, I found just a few mentions about leveraging Rete to do it. James Taylor has three posts about it ([1], [2], [3]) and they are all 1+ years old.

I found a recent post (April, 2007) in a blog by Ashwin Jayaprakash where he addresses the issue. In his words:

The tenets of Event Processing

A facility to consume the state(s) of a System as discrete Events, a language or User Interface to specify the conditions/properties to look for in those Events from one System or across Systems (Co-relation) and provide actions to be performed when such situations arise.

It is no accident that Event Processing looks like a cross between Database Query processing and Rule Engines. There is no denying that the technology evolved from existing technologies. However the distinguishing characteristics of Event Processing technology are - the constructs it provides to specify Time based boundaries, fixed size moving Windows, Aggregation and Partitioning/Grouping Events - on a stream of incoming Events and a facility to continuously scan these Events for telltale signs, all this expressed as a concise Query.

Database Triggers which in turn execute SQL/Stored Procedures every time an Event/Row is inserted can provide rudimentary Event Processing functionality. Rule Engines can be used to discern information from Facts being asserted. But none of these technologies alone provide a concise and yet very expressive Domain Specific Language along with a platform, specifically built to constantly monitor/process live streams of Events.


I specially agree with Ashwin's statement that a Rules Engine as we know them, alone, can not provide a concise and yet expressive DSL to handle ESP and CEP. Although, I prefer to think (I guess in a similar fashion to what James Taylor says) that we can leverage a Rete Engine to address such requirements. We all know that Rete Engines excel at pattern matching tasks, so basically what is missing is the capability to handle streams of events where just some of them are really "interesting" for the processing (a "select"-kind feature) and even those selected events get old quickly and must be discarded (sliding window and temporal logic support) in a way to scale the solution. The expressiveness of the language I guess is a consequence of the addition of the mentioned features.
This may be an over simplification of the subject, but that is how I see it so far.

Current Approaches

The few current approaches I was able to read about since yesterday are extensions to the relational engines to handle temporal constraints and extensions to the SQL language to allow for querying such engines (I didn't read documentation about proprietary solutions like Coral8 and StreamBase yet).

  • StreamCruncher for instance implements and engine that is backed by a relational database and leverages it to handle ESP/CEP.
  • Esper on the other hand, seems to implement its own relational engine, but the language is also an extension of SQL.
While both approaches seems good to me, it itches me even more to understand how a Rules Engine approach would do in comparison with the existing ones.

Floyd Marinescu posted last year an article to InfoQ talking about the Esper release where he says that "The rules engines proved cumbersome and slow for this use case". He also quotes Alexandre Vasseur:

[Esper] is not to be confused with classical rules engines...The internals of Esper are made up of fairly complex algorithms primarily relying on state machines and delta networks in which only changes to data are communicated across object boundaries when required.

On the proprietary software side, I found a post about TIBCO, stating it uses "a modern compiled variant of the Rete algorithm for class-leading performance". It only mentions CEP though and I'm not sure it is used as a synonym for ESP or not.

In this comment, Daniel speaks about the CEP capabilities of ILog JRules, but not about ESP.

Given all the mentioned above, I guess that in order to believe, I need to see it myself.

Event Stream Processing Requirements

From my readings, I was able to draft a list of requirements, that in my opinion, a Rete engine would need to comply to be able to handle ESP and CEP tasks. They would be:

  • Support for events as a special type of facts: while facts are long living pieces of information, events have special temporal requirements and the engine must be able to work with both at the same time, inside the same working memory.
  • Support asynchronous multi-thread feeding: events may arrive at any time and from multiple sources (or channels), so the engine must support asynchronous, multi-thread feeding of events.
  • Support event selection: only a subset of the events going through the event stream are interesting for a given set of rules. The engine must be able to identify (select) such events and ignore the others.
  • Support events garbage collection: events grow old, quickly or slow, but they do grow old. The engine must be able to identify the events that are no longer needed and dispose them as a way of scaling. It is simply impossible to hold events indefinitely. Ideally, the identification and disposal would be automatically, using the results of rules compile time analytics.
  • Support temporal relative constraints: one way of defining the window of interest in a stream of events is do define patterns of events that start and close each window. Such windows would be defined through the use of temporal constraints with operators like "since" and "until". One example of a rule using such constraints would be: "Since the stock price went under US$ X, watch for any buyers of more than 1% of total stocks, until the day is over". The above rule will start to watch for any buyers when the stock price drops under a threshold, but once it happens, will continue watching them until the end of the day, even if the stock price goes over the threshold again.
  • Support temporal absolute constraints: the rules engine must implement a pseudo-clock, that may or may not (depending on the use case) be synchronized with the real clock and allow for constraints to be defined over the sliding time window relative to the pseudo-clock. Events outside the time window are old and should be discarded.
  • Support reasoning over absence of events: the engine must support the definition of rules that will fire over the absence of events in the expected time-frame (relative or absolute). Example: "If the temperature goes over the threshold and no contention measure is taken within 10 seconds, then sound the alarm".
  • Support to common mathematical accumulations of the events in the streams, like average, max, min, etc.

The whole event matching and correlation requirements are already provided by the rules engine. The main question though is:

Is it possible to implement all the above functional requirements as an extension to a Rete engine and still comply to the non-functional requirements, specially performance?

That is what I will try to understand over the next few weeks. Stay tunned and please, I do appreciate feedback, suggestions and critics.

JBoss Rules even slimmer

So the diet has gone well for JBoss Rules which is now even slimmer. If you remember from a previous blog we already removed a lot of dependencies by inlining JCI and removing the uneeded code and the dependencies they needed, you can read about that here.

This time we have removed the need for Antlr 2.77 and StringTemplate 3.0; we already use antlr 3.0 for our parser so it was a little annoying that our choice of template systems required another antlr jar adding to the dependency bloat. As it happens MVEL, the new scripting language we are adopting, has its own templating system, so we can use that and drop two further dependencies - eventually we'll inline MVEL itself as its only 300kb, removing another dependency.

Initially MVEL wasn't quite as powerful as we needed but a day or two of hacking on MVEL brought it up to scratch so that we could migrate. The main missing features, which are important for code generations are multiple list iteration with seperators and nested templates.

Using multiple list iterations, with seperators, you can do following:
myMethod(@foreach{types, identifiers as type, identifier}type, identifier@end{","})
This allows you to have two lists or arrays where one contains the list of types and the other the list of identifiers and you need to iterate over these together in sequence. Further to that it will add in the seperator string, specified inside the @end marker, after the first value and before the last. This is something that StringTemplate already had but I don't believe that Velocity or Freemarker have this powerful feature.

We also added nested templates, although this is something all the other templating systems, when calling a template you must pass down the needed variables. Templates can be nested by using the @includeByRef marker:
@includeByRef{myTemplate(var1 = "string1", var2 = someOtherVar)}
The README has been updated to detail the current needed dependencies for the project. Part of the document, for core and compiler, has been reproduced below:

CORE RUNTIME
Runtime assumes that you are "compiling" rules using drools-compiler.
  • drools-core - the rule engine itself.
  • mvel14-1.2beta16
  • optional packages:
    • xpp3-1.1.3.4.O, xstream-1.1.3 - if you are using the file based audit feature
Note you can use the drools-core stand-alone if you are compiling "outside" your runtime application, and deploying serialized Package or RuleBase? objects.

COMPILER - rule assembly time
Rule compiler takes rules in some textual format and prepares binary Packages of rules for deployment. This depends on the CORE RUNTIME.
  • drools-core
  • drools-compiler - the rule compiler itself.
  • antlr3-3.0b7
  • xerces-2.4.0, xml-apis-1.0.b2 - only if you are using XML rules, if DRL only, can skip this.
  • eclipse-jdt-core-3.2.1.v_677_R32x - only if you want to compile with eclipse
  • janino-2.5.6 - only if you want to compile with janino

Saturday, May 05, 2007

JBRSTab Visual Authoring of Complex Spatial Simulation scenarios

A new release of JBRSTab is out. From the website:
JBRSTab is a tab plug-in to the open source ontology editor Protege (http://protege.stanford.edu/). It uses the open source geo-information system Java library OpenMap (http://openmap.bbn.com/) and the open source Java RETE rule engine JBoss Rules (http://labs.jboss.com/portal/jbossrules/).
It can be used for visual authoring of complex spatial simulation scenarios
and general rule base authoring.
It includes two demos:

  • complex scenario of collision between two ships leading to environment pollution and following rescue operation.

  • classic rule-based expert system for sea traffic control.