Many rulebases have a need for reference data; that is, data that should ideally be available to the rules but for whatever reason cannot be hard-coded into the rules themselves. For example, large tables of data are easier to write rules for, if they are structured as attributes in entities.
The supplied example is a Rulebase Listener that reads data from a CSV (comma-separated values) file located in the project’s “include” directory, and uses the data to pre-populate sessions that are created with the rulebase.
The CSV file is named after the entity for which it contains data; for example, income-bracket.csv.
The first row in the CSV file contains the public names of attributes, and each of the following rows define an entity instance with the attribute values of that row.
The CSV file and compiled rulebase listener is packaged inside the compiled rulebase zip file, so the rulebase remains self-contained.
The ReferenceDataListener class contains the main logic and the class implements RulebaseListener as follows:
The ReferenceDataCSVParser class handles number, boolean, date/datetime and text values. If a row has too many values, an exception is thrown and if a row has too few values, the extra attributes are set as uncertain.
The example has the following limitations:
For the sample source code and rulebase required to run this example, go to:
Java:
examples\determinations-engine\reference-data\java in Java runtime zip
C#:
examples\determinations-engine\reference-data\csharp in .NET runtime zip