User Guide for Drools.NET-3.0 V1.0-Feb 27 , 2007

abashedwhimsicalΛογισμικό & κατασκευή λογ/κού

2 Νοε 2013 (πριν από 3 χρόνια και 10 μήνες)

397 εμφανίσεις


1















User Guide for Drools.NET
-
3.0

V1.0
-
Feb 27
th


, 200
7















2


A BOUT THI S DOCUMENT

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



3.0

REVISION HISTORY

Date

Description

1.

Feb 27
th


, 2006

Created

2.



3.





3


Table of Cont
ents


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 Content
s
................................
................................
................................
................................
.......

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 Tabl es working:

................................
................................
............
7

3.2.2

Drools.NET v/s Drools Decision Tabl es:

................................
................................
.....................
8

3.2.3

Syntax of Decision Tables:
................................
................................
................................
................
8

3.3

Pre
-
Compilation Support

................................
................................
................................
.......................

8

3.4

Support for Multiple .NET languages

................................
................................
................................

9

4

Running Examples

10

5

Rule’s Syntax

10

6

Debugging Support

10

7

Known Issues

10

8

Future work and Enhancements

10



4



1

EXECUTIVE SUMMARY



1.1

Purpose


This document provides a des
cription of
the following




I
nstall
ing

Drools.NET
-
3.0



Drools.NET
-
3.0

Features

Descript
ion 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.


5



2

Drools.NET

Installation




2.1

System Requirements

Here are the system requirements for using Drools.NET:



Microsoft
.NET Framework 2.0. Drools.NET will NOT run on .NET Framework
1.1 (
http://msdn.microsoft.com/netframework/downloads/updates/
)



IKVM 0.2
8
.0.0 (
http://www.ikvm.net
)

, included with the distribution



NUnit
-
2.2.
6

or above
(
http://www.nunit.org
)
, framework is included with the
distribution


2.2

Release Contents

Drools.NET re
lease
consist
s

of the following



External Libraries:

o

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)

o

Drools
-
dep.dll


Dependencies required by drools
-
3.0.dll

o

IKVM.
GNU.Classpath.dll

-

IKVM dependency required by the drools
-
3.0
.dll assembly

o

IKVM.Runtime.dll

-

IKVM depen
dency required by the drools
-
3.0
.dll
assembly

o

nunit.framework.dll
and nunit.core.dll


Assemblies

required to create and
run NUnit tests



Drools.NET Libr
aries

o

org.drools.dotnet.dll

-

Drools .NET wrapper classes

and .NET semantic
layer classes

o

org.drools.dotnet.examples.dll

-

Drools .NET examples implemented as
NUnit tests

o

/drls directory



The example rules definition files

that are embedded in
the example

library (Given here just for reference)

o

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 a
pplication by referencing the following
assemblies:



drools
-
3.0
.dll



IKVM.GNU.Classpath.dll



drools.dotnet.dll


6


3

Drools.NET

Features

Description and
U
sage



Drools.NET currently supports most of the fe
atures supported by Drools
-
3.0

and more.




Basic features
of Jboss
-
Rules
-
3.0



S
ee the
core
-
engine features at
http://labs.jboss.com/portal/jbossrules
.



The work for Rules Authoring Tool for .Net is underway



Support for Decision Tables



Support for Precompi
led Rule
-
Bases



Serialized Rule
-
Bases can be stored by the
user and loaded as required.



S
up
port for Multiple .NET language
s



Support for debugging consequnces a drl file



3.1

Using Basic Features of Drools


Drools.NET allows you to create, load and execute Ru
les in the same manne
r 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.

‘RuleBaseLoad
er’ 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()).GetMa
nifestResourceStream(“test.drl”);


RuleBase ruleBase = RuleBaseLoader.getInstance.LoadFromStream(stream);




7

//Approach 2 using PackageBuilder


PackageBuilder builder = new PackcageBuilder();


Stream stream =
Assembly.GetAssembly(this.getType()).GetManifest
ResourceStream(“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 RuleB
ase

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
de
cisio
n 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.
Follo
wing 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(st
ream, InputType.XLS);



8

//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.NewRul
eBase();

ruleBase.AddPackage(pkg);



WorkingMemory engine = r
uleBase
.NewWorkingMemory();

TestModel model =
new

TestMode
l (
);

engine.AssertObject(model);

engine.FireAllRules();






3.2.2

Drools.NET v/s Drools Decision Tables:


The only difference between the two

decision tables is the language used for specifying
conditions, consequences, functions etc. For Drools.NET, the language should be a .NET
language, while in Drools Decision Tables it is Java.


3.2.3

Syntax of Decision Tables
:


Decision Table’s syntax in Drool
s.NET is exactly the same as
Decision Tables in Drools
.




NOTE:
If a class from an external library (not current working directory) is being
referenced in a decision table, then its assembly name must be specified in the decision
table with its declaratio
n as follows:


RuleTable
allocateStream(org.drools.dotnet.examples.decisiontables.model.Claim.ASSEMBLY.org.
drools.dotnet.examples claim)


The class name must be a fully classified name followed by string ‘.ASSEMBLY.’ and
then the assembly name. It ensures
that

the class gets loaded correctly.




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.



9

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.



10



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 applicatio
n. 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