Drools.Net - 3.0 User and Installation Guide

           
   
User Guide for Drools.NET-3.0
V1.0-Feb 27th  , 2007
  
                                                                                                  
  About this Document

This document is an installation and user guide for Drools.NET - 3.0

REVISION HISTORY
Date
Description
1.       Feb 27th  , 2006
Created
2.        
3.        


 
Table of Contents
 1   EXECUTIVE SUMMARY  4
1.1     Purpose.4
1.2     Business Vision.4
2   Drools.NET Installation 5
2.1     System Requirements.5
2.2     Release Contents.5
2.3     Installation.5
3   Drools.NET Features Description and Usage 6
3.1     Using Basic Features of Drools.6
3.2     Drools.NET Decision Tables.7
3.2.1         Getting Drools.NET Decision Tables working:7
3.2.2         Drools.NET v/s Drools Decision Tables:8
3.2.3         Syntax of Decision Tables:8
3.3     Pre-Compilation Support9
3.4     Support for Multiple .NET languages.9
4   Running Examples 10
5   Rule's Syntax 10
6   Debugging Support10
7   Known Issues 10
8   Future work and Enhancements 10

1          EXECUTIVE SUMMARY 

1.1       Purpose

This document provides a description of the following 

  • Installing Drools.NET-3.0
  • Drools.NET-3.0 Features Description and their Usage
  • Running example applications.
  • Rule's Syntax 
    Each of these will be described in a different section of this document.

1.2       Business Vision

The Drools.NET-3.0 is a .NET version of Jboss-Rules 3.0, which is a Rules Engine implementation based on Charles Forgy's Rete algorithm tailored for the Java language. Drools.NET enables .NET developers/Users to exploit the powerful Rule Engine like Jboss-Rules through a completely managed .NET code base. 

2          Drools.NET Installation 

2.1       System Requirements

Here are the system requirements for using Drools.NET:

2.2       Release Contents

Drools.NET release consists of the following

  • External Libraries:
  • Drools-3.0.dll - The core drools assembly compiled using IKVM (IKVM is a compiler used to compile Java classes and jars into a .NET assembly)
  • Drools-dep.dll - Dependencies required by drools-3.0.dll
  • IKVM.GNU.Classpath.dll - IKVM dependency required by the drools-3.0.dll assembly
  • IKVM.Runtime.dll - IKVM dependency required by the drools-3.0.dll assembly
  • nunit.framework.dll and nunit.core.dll- Assemblies required to create and run NUnit tests
  • Drools.NET Libraries
  • org.drools.dotnet.dll - Drools .NET wrapper classes and .NET semantic layer classes
  • org.drools.dotnet.examples.dll - Drools .NET examples implemented as NUnit tests
  • /rules directory - The example rules definition files that are embedded in the example library (Given here just for reference)
  • The source code for Drools.NET libraries and example drl files can be downloaded from CVS. The module name is 'drools-dotnet' (Provide CVS Download Instructions) 

2.3       Installation

The Drools.NET BRE can be used in an application by referencing the following assemblies:

  • drools-3.0.dll
  • IKVM.GNU.Classpath.dll
  • drools.dotnet.dll

3          Drools.NET Features Description and Usage  

Drools.NET currently supports most of the features supported by Drools-3.0 and more.  

  • Support for Decision Tables
  • Support for Precompiled Rule-Bases - Serialized Rule-Bases can be stored by the user and loaded as required.
  • Support for Multiple .NET languages
  • Support for debugging consequnces a drl file  

3.1       Using Basic Features of Drools

Drools.NET allows you to create, load and execute Rules in the same manner as it is done in Jboss-Rules 3.0. It also exposes underlying Jboss-Rules API to allow greater flexibility to a dotnet user. 
API classes 'PackageBuilder' and 'RuleBaseLoader' provides functions for creating a Rule-Base. 'RuleBaseLoader' is a high level helper class for creating RuleBases from source, while 'PackageBuilder' class provides additional control on how the rulebase is created. 
A basic sequence of steps to use a 'PackageBuilder' or 'RuleBaseLoader" is as follows: 
            //Step 1: include the following namespace

using org.drools.dotnet.compiler;

using org.drools.dotnet.rule;  //Step 2: Use following steps to create a RuleBase
//Approach 1 using RuleBaseLoader
 Stream stream = Assembly.GetAssembly(this.getType()).GetManifestResourceStream("test.drl");
 RuleBase ruleBase = RuleBaseLoader.getInstance.LoadFromStream(stream);
  //Approach 2 using PackageBuilder
 PackageBuilder builder = new PackcageBuilder();
 Stream stream = Assembly.GetAssembly(this.getType()).GetManifestResourceStream("test.drl");
 builder.AddPackageFromDrl("test.drl" , stream);
 Package pkg = builder.getPackage();
 RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
 ruleBase.AddPackage(pkg)
 //Step 3: Get an instance of WorkingMemory for the loaded RuleBase

WorkingMemory workingMemory = ruleBase.NewWorkingMemory(); //Step 4: Assert facts

workingMemory.AssertObject("Hello"); //Step 5: Fire all Rules

workingMemory.FireAllRules();

3.2       Drools.NET Decision Tables

Decision Tables in Drools.NET work similarly to decision tables in Jboss-Rules. Please visit the documentation provided at Jboss Rules website (http://labs.jboss.com/portal/jbossrules/docs) , in order to get an understanding of how decision tables are used in Jboss-Rules.  

3.2.1        Getting Drools.NET Decision Tables working:

Using Drools.NET decision tables is very similar to the regular Drools.NET API. A class called 'DecisionTableLoader' defines functions for using decision-tables in .NET. Following is an example code snippet:

//Get drl string from the spreadsheet
SpreadSheetCompiler converter = new SpreadsheetCompiler();
Stream stream = Assembly.gtAssembly(this.getType()).GtManifestResourceStream("test.xls");
String drl = converter.Compile(stream, InputType.XLS);
//build a rule base
PackageBuilder builder = new PackageBuilder();
builder.AddPackageFromDrl(drl)
//everything from here is just like normal Drools.NET
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.NewRuleBase();
ruleBase.AddPackage(pkg);
WorkingMemory engine = ruleBase.NewWorkingMemory();
TestModel model = new TestModel ();
engine.AssertObject(model);
engine.FireAllRules(); 

       

3.3       Pre-Compilation Support


  • A Rulebase can be persisted and reloaded in an application as required, no recompilation necessary. It is good for people who have very large Rule-Sets. 
    RuleBase class provide API functions to save and reload a RuleBase. The Rulebase is serialized and stored in a System.Stream provided by the user. There are examples provided in the examples library.   

3.4       Support for Multiple .NET languages

  • Drools.Net currently supports C# only. In the future it might support other .NET languages too.

 4          Running Examples 

Drools.NET examples can be found in library 'org.drools.dotnet.examples.dll'. All the examples are implemented as NUnit tests, which can be run directly using NUnit GUI or Console application. They can also run in Visual Studio .NET.  
All of these examples are taken directly from Jboss-Rules-3.0 and have been ported to .NET.    

5          Rule's Syntax  
6          Debugging Support  

7          Known Issues 
TBD 
8          Future work and Enhancements
TBD

                                                                                                                                                                                                                

Labels

 
(None)
  1. Jan 21, 2008

  2. Jan 21, 2008

    Umesh Toranagatti says:

    hi all, from last 8 months i am seeing the same document and waiting for the upd...

    hi all,

    from last 8 months i am seeing the same document and waiting for the updates....

    regards

    Umesh B.Toranagatti