RME-EP Rule Specification Language

Rete engine is the de facto industry standards for rule-based expert system shells. It has been used extensively in various industries for developing expert systems. RME-EP is a Rete engine based on RME (Rule-based Model Evaluation) language with predictive models. RME-EP is based on SQL-99 syntax. The popularity of SQL as the standard database query language has been largely due to its intuitiveness and rich logical expressions. This is very important for especially developing business rules. RME-EP provides a superb language platform for business rule specification. The following sections describe the RME-EP rule specification language in detail. Further details can be found from the accompanying language manual.

Here are coding conventions;

  • Reserved words: Reserved words are used by system as keywords, e.g., IF, THEN, CASE, etc. They can be coded in uppercase capitals or lowercase or in mixed mode.
  • Identifiers: Identifiers are fact names. Identifiers may contain "." and alpha-numeric letters. However white spaces are not allowed. For example, Cust.name, cust.age, etc. Note that identifiers are case sensitive!
  • Quoted identifiers: Identifiers are not allowed to have white spaces and special characters. Quoted identifiers can. For example, "My Special Dog.age", "MyNew.bride", etc. Note that quoted identifiers use double quotes and case sensitive.
  • Literals: Non-numeric literals (or strings) are represented in between two single quotes. Numeric literals without a decimal point are considered as INTEGER. Numbers with a decimal point are considered REAL. For example;
    • STRING: 'My new String', ...
    • INTEGER: 1200, 1563, ...
    • REAL: 1.234, 1.234e23, ...
  • Comments: Line comments can be added after "//". Block comments are enclosed between "/*" and "*/".

Fact names and Data types

Facts are basis of rule inference. Rules are applied based on a set of facts. Facts have a name and a value. With the popularity and support of XML, RME-EP supports dot-notations for fact names. For example, cust, cust.name, cust.age, etc. In addition, quoted identifiers may be used. This is normally used when white spaces are used in names, e.g., "My house.age", "His dog.doctor", etc. Each fact is associated with a data type. Normally one of "INTEGER", "REAL", and "STRING". To define fact data types, the following expressions are used;

   DECLARE ALL AS <data-type> ;
   DECLARE <fact-name> AS <data-type> ;

The first is used to set default fact types. The second is used to define exceptional fact types. The following example shows this. The first line set the all facts as STRING. The others set special numeric data types as exceptions. (Note that STRING is the system default. No need to have the first expression explicitly!)

   DECLARE ALL AS STRING ;
   DECLARE cust.age AS INTEGER ;
   DECLARE cust.income AS INTEGER ;
   DECLARE cust.weight AS REAL ;

Rules

Rules are the grains of RME-EP. Rules have the following syntax;

   RULE <rule-name>: <conditional-expression> ;

Rule names can be numbers or identifiers without white spaces in between letters. In addition, quoted literals may be used as well, e.g., 1, MyRule, "My Rule", etc. Conditional expressions can be one of the followings;

  • IF-THEN-ELSE expressions
  • CASE expressions
  • ON expressions

The followings are examples of RME-EP rules;

RULE 1: IF cust.offer = 'yes' AND cust.gender ='male' THEN THROWEVENT('email', 'Dear Sir ....') END;
RULE 2: IF cust.offer = 'yes' AND cust.gender ='female' THEN THROWEVENT('email', 'Dear Mdm ....') END;
RULE 3: IF cust.age > 40 and cust.income > 50000 THEN SET cust.status AS 'Interested' END;
RULE 4: IF cust.status = 'Interested' THEN SET cust.offer AS 'yes' END;

An Example

The following is a simple working example of RME-EP models;

// declare options;
DECLARE OPTIONS FIREFIRST,ERRORNULL,MAXFIRE(1000) ;

// declare data types;
DECLARE ALL AS STRING;  // set default types;
DECLARE cust.age AS INTEGER;
DECLARE cust.salary AS INTEGER;

RULE 1:
IF cust.age > 20 AND cust.salary > 50000 THEN SET cust.status AS 'interested' END;

RULE 2:
IF cust.status='interested' THEN SET cust.action AS 'send offer' END;

RULE 3:
IF ust.action='send offer' THEN THROWEVENT('email1', 'Dear Mr Blah...') END;

For more, please read Predictive Modeling Software.