Skip to content
ddossot edited this page Oct 25, 2014 · 14 revisions

General

First Steps

NxBRE does not expose in any way the rules to the development environment: the rules are interpreted by the engine itself. The responsibility of the application is to expose information to the rule engine so it can process the rules.

If you work with the Flow Engine, the information is exposed as pure objects via the engine Context ; if you work with the Inference Engine, the information is exposed as facts (which are basic pieces of data - predicates - related together by a named relationship : eg. "A is the father of B", A and B are predicates and "is the father of" is the fact type).

So the steps an application does are the following:

  • load a rule file in the engine,
    
  • expose information to the engine,
    
  • ask the engine to process,
    
  • analyze the deductions made by the engine. 
    

This only amounts to a few lines of code in NxBRE:

Flow Engine

IFlowEngine bre = new BREImpl();
bre.Init(new XBusinessRulesFileDriver(ruleFile))
bre.RuleContext.SetObject("TestObject", tobj);
bre.Process();
// check the modifications made on tobj

Inference Engine

IInferenceEngine ie = new IEImpl();
ie.LoadRuleBase(new RuleML09NafDatalogAdapter(ruleFile, FileAccess.Read));
ie.Assert(new Fact("is the father of", new Individual("John Smith"), new Individual("Kyle Smith"));
ie.Process();
// query the fact base for deducted facts or directly have the engine affect business objects via events

NB. these code fragments are just a samples, there are factories and other helpers that can be used.

Examples

Running the provided examples (Discount, Login, FraudControl and TelcoRating) requires to pass them a path to the place you have decompressed or SVN synchronized NxBRE.

You will find the command line syntax to use, with the list of parameters to pass, in NxBRE3/RuleFiles/readme.html. Here is a link to the most recent version of this file. Note that it might not match your local version.

The engine runs without any config file: is it useless?

The NxBRE.dll assemblies provided with NxBRE do not need any configuration information to be used in an application.

Configuration information is needed for these two cases:

  • when running the unit tests,
    
  • when using any other values than the default ones for the different configurable parameters (see PDF documentation for more information). 
    

Unit testing NxBRE

Whether you use the pre-compiled assembly provided with the official distribution or you build NxBRE yourself, it is highly recommended to execute the unit tests to certify the engine. Until you will get all green lights in NUnit , you should not use the engine in your project.

Since v3.1.0, the unit tests are located in a friend assembly that is compiled from a different project in the same solution. At run time, you need only to reference NxBRE.dll.

To successfully run the unit tests you must:

  • properly configure the engine under the "Unit Test Config" section: the paths should point to the correct location of test rule bases (file and http sources) and temporary folder,
    
  • have the XML schemas and DTDs copied in the output folder else validation of the rule bases generated during the unit test phase will fail. 
    
Clone this wiki locally