perjantai 15. kesäkuuta 2007

Looking at the AST

I spent last weekend testing JRuby. I found out that some things would be easier using JRuby some things using Java, this was of course to be expected.

First days of this week I used to design a model that would help me to test rules.

JBoss Rules forms an abstract syntax tree (AST) from the rules it gets from rule base. This AST is done using Java, so the problem is that rule engines do not support object-oriented model that well, and as I am mainly using JBoss Rules to find conflicts I need to find another way. So Michael Neale told me to think about relations like the ones used in SQL databases, using this advise I added an identifier to all my objects and information of parent objects so that the relations could be solved. After this I could test small cases that were under And or Or descriptions, but this is not enough, because I would need to form loops to check for conflicts in the entire rule. Loops would be too messy to use, so I needed an other solution.

After some brain work, I realized that if I can get a list of all of the simpler clauses that can be formed from one rule, I can use those clauses to test conflicts inside this rule. Lets look at how this looks in the Rules drl file:

rule “Rule that causes warning”

when
Foo(bar == "baz" && ( xyz =="123" || bar != "baz" ) )
then
# Do something

end


This rule looks for Foo objects from working memory, if object Foo has parameters that match the definitions set inside the brackets it does something.
So all the simpler clauses for definitions inside object Foo would be:
bar == “baz” && xyz == “123”
bar == “baz” && bar != “baz”

This rule has an error because obviously parameter bar can not be equal to “baz” and at the same time be unequal to “baz”. On these kind of situations the RAM could check the rules and inform the user that he or she has a rule that can be true, but has an condition that can never be true. Another warning could be for example: Foo( x > 42 || x < 42 ) this throws a warning that possibility x == 42 is not taken care of. Only problem now is that how can I form all the possible clauses from the AST.

Yesterday and today I'll be looking at how the feed back from rule checks should work. Michael Neale said that the feed back would be in XML and it could then be transformed to for example HTML. Proctor and Neale also suggested some books that could help, so last Tuesday I got Expert Systems: Principles and Programming by Joseph Giarratano and Gary D. Riley, I'll be reading that on next weekend.

torstai 7. kesäkuuta 2007

First Blog Entry

I'll be referring to my project, Rule Analytics Module as RAM. JBoss Rules as Rules and the rules used by JBoss Rules as rules.

On first of June I started by signing to jboss.com as a contributor. Michael Neale had started this project before so I downloaded those codes. Mr. Neale told me that I should probably start from scratch, but these codes could help me on RAM. He also sent me some documents to help me figure out how rule engines work and proposed that I look in to JRuby and how it could be used on my project. JRuby might help to simplify the rule testings.

First day and the first days of this week I spent studying rule engines and JBoss Rules. I had done some test with JBoss Rules before I applied for summer code and some studying after I got this job, but now I had time to go deeper into the functionalities and structure. I also installed JRuby and looked how it works, theres no desicions made if it is actually going to be used yet.

Rest of the week I spent downloading latest Rules codes from SVN and debugging the rule engine to figure out how it handles the rules with java objects. The problem right now is to create objects from rules that RAM could use to validate rulebases. Actual rule parsing from rule textfile is already done by Rules so what I'm going to do is use these objects to form my own model. On Mr. Neales advise I started making rules that check for simple errors and warnings, working my way up from there to create a analysis rule model that would be a flattened version of what Rules uses.

Today and on next week I will continue to plan the analysis rule model.

JBoss Rules developers have been really helpful and they are always ready to answer my questions.