RuleSet <nameOfRuleSet> ( <Processing Options Statement>* // Zero or more statements . . . ) |
Ruleset processing options statements:
Some of the statements give you control over the inference engine while it is evaluating rules, while other statements let you define your own data types or let you import functions that can be called from your rules.
Processing options statements...
For rulesets containing fuzzy variables and rules, specifies the manner in which a solution variable's fuzzy representation is updated.
For rulesets with no fuzzy variables and rules, specifies the type of inferencing to be performed.
If left unspecified, the default InferenceMethod is Script.
The specified InferenceMethod applies only to the Main rule block. All other rule blocks are processed with the Script engine.
Syntax
InferenceMethod ( FuzzyAdd | MinMax | ProductOr )1 InferenceMethod ( Script | Forward | Forward2 | Forward3 | Mixed | Predicate | Backward )2
Parameters
This chart shows the degree of support that each inferencing engine provides for specific Able Rule Language features. Any feature marked NS is Not Supported, meaning the inferencing engine tolerates the presence of the feature in a ruleset but will not process it. These features will produce warnings. The presence of any feature marked NO will prevent a ruleset from executing so an error will be issued when the ruleset parses.
ARL Feature | All ruleblocks | Main ruleblock1 | |||||
---|---|---|---|---|---|---|---|
Inferencing method | Script | Fuzzy2 | Forward | Forward2 | Forward3 | Backward3 | Predicate3 |
Assertion rule | yes | yes | yes | yes | yes | yes | yes |
If/Then If/Then/Else If/Then{} rules4 | yes | yes | Else clause not supported | NS | NS | Else clause / multiple consequents not supported | Else clause / multiple consequents not supported |
While/Do or Until/Do loop rule | yes | yes | NS | NS | NS | NS | NS |
When/Do pattern match rule | yes | no | NS | yes | yes | NS | NS |
Predicate rule | no | no | no | no | no | no | yes |
Fuzzy variable | no | yes | no | no | no | no | no |
Processing order5 |
assertions, then sequential | assertions, then sequential | assertions, then sequential | assertions, priority, sequential | assertions, priority, sequential | assertions, then sequential | assertions, priority, sequential |
1 Some inferencing methods are used only in the main ruleblock. The Script inferencing method is used to process other ruleblocks for these inferencing engines.
2 ProductOr, MinMax and FuzzyAdd inferencing methods.
3 At runtime, Backward chaining and Predicate inferencing require a GoalVariable or GoalPredicate respectively. A warning is issued when the ruleset is parsed if no variable is provided. The variable may be set via API before the ruleset is processed.
4 If/Then conditional rules have three variants:
Simple | if x == 0 then y = 1 |
Else | if x == 0 then y = 1 else y = 2 |
Multiple consequents | if x==0 then y=0 z=1 else y=1 z=1 |
5 Rule processing order is generally assertions first, then rule priority (if supported), and finally in the sequence provided by the ruleset. See the JavaDoc for the appropriate inferencing engine for more details.
Examples
RuleSet <nameOfRuleSet> ( InferenceMethod ( FuzzyAdd ) // For a ruleset with // fuzzy (and other) variables. InferenceMethod ( Forward ) // For a ruleset with // NO fuzzy variables. . . . ) |
1 Rulesets with fuzzy variables and rules.
2 Rulesets with no fuzzy variables or rules.
For rulesets with fuzzy clauses, specifies the threshold at which truth values become insignificant. If the truth value of any antecedent clause falls below the alphacut when the clause is evaluated, the inference engine stops evaluating the rule in which the clause appears.
If left unspecified, the default AlphaCut value is 0.1.
Syntax
AlphaCut ( <numericValue> )
Parameters
Example
RuleSet <nameOfRuleSet> ( AlphaCut ( 0.20 ) . . . ) |
For rulesets with fuzzy clauses, specifies the manner in which a rule's consequent fuzzy region is correlated with the rule's antecedent fuzzy truth value.
If left unspecified, the default CorrelationMethod is Product.
Syntax
CorrelationMethod ( Product | Minimum )
Parameters
Example
RuleSet <nameOfRuleSet> ( CorrelationMethod ( Minimum ) . . . ) |
For rulesets with fuzzy clauses, specifies the manner in which a fuzzy set is turned into a crisp numeric value.
If left unspecified, the default DefuzzifyMethod is Centroid.
Syntax
DefuzzifyMethod ( Centroid | MaxHeight )
Parameters
Example
RuleSet <nameOfRuleSet> ( DefuzzifyMethod ( Centroid ) . . . ) |
When InferenceMethod is predicate, specifies the names of predicates used in rules. All predicates referenced in rules must be pre-declared in this section. Multiple statements may be used; they are cumulative.
This statement should not be used with other inference methods.
Syntax
Predicates ( <predicateName>* )
Parameters
Example
RuleSet <nameOfRuleSet> ( InferenceMethod(Predicate) Predicates ( father, mother, sister ) Predicate (brother) Predicates (aunt uncle) . . . ) |
When InferenceMethod is predicate, specifies the goal(s) of the predicate inference engine.
This statement, if used, must immediately follow the last Predicates statement.
Syntax
GoalPredicates ( <predicateClause>* )
Parameters
Example
RuleSet <nameOfRuleSet> ( InferenceMethod(Predicate) Predicates(male, female) Predicates(father mother parent) Predicates(son, daughter, brother) GoalPredicate ( brother(milcah,X) ) // Who is the brother of Milcah? . . . ) |
Allows you to import all the public methods in the specified classes (or libraries) as user-defined functions without having to declare each method explicitly. Imported methods then become available to be called from rules. Note that if two or more imported classes contain duplicate method names with an identical number of arguments, the last method imported is the method that is available to your rules. Also, when using imported methods in rules, you must use the number and types of arguments expected by the method. No checking is done, and improper use will result in runtime errors during ruleset processing. Remember that all numbers used in the rules package are implemented as doubles.
See also the UserDefinedFunctions statement.
See also the general section on interacting with functions. Among other things, the section describes some built-in method libraries that are available.
Note that built-in functions always take precedence over imported functions of the same name and arity.
Syntax
Import ( "fully.Qualified.ClassName", ...)
Parameters
Examples
RuleSet <nameOfRuleSet> ( Import( "com.binford.Hammers", "com.binford.Saws" ) Import( "com.tooltime.FirstAid" ) . . . ) |
The first statement imports all the public methods in both Hammers and Saws. The second statement additionally imports all the public methods in FirstAid. If the Hammers library contains the public method driveNail(), for example, then a rule such as the following can be coded:
rule: if nail_length == 6 then rc = driveNail() |
Allows you to define your own data types so that you can declare and manipulate variables of those types. Each type you declare must be equated to a public Java class.
You can declare multiple types in one UserTypes statement, or you can use multiple UserType statements that declare one type each. In either case, the net results are the same.
Syntax
UserTypes ( type : "fully.Qualified.ClassName", ... )
Parameters
Example
RuleSet <nameOfRuleSet> ( UserTypes ( Puzzle : "hanoi.Puzzle", Ring:"hanoi.Ring" ) UserType ( DataLog: "hanoi.Logger") . . . ) |
The first statement equates the data type Puzzle to instances of objects of type "hanoi.Puzzle" and the data type Ring to instances of objects of type "hanoi.Ring." The second statement additionally equates the data type DataLog to instances of objects of type "hanoi.Logger".
These statements then allow the ruleset author to define variables such as shown below. Note that for each variable declaration an instance of the specified class is created and the constructor is passed the arguments in parentheses.
RuleSet <nameOfRuleSet> ( . . . Variables ( easyPuzzle Puzzle("Puzzle1") // Name hardPuzzle Puzzle("Puzzle2") // Name smallRing Ring("RingA", 2) // Name, diameter mediumRing Ring("RingB", 4) // Name, diameter largeRing Ring("RingC", 6) // Name, diameter ) . . . ) |
In the example above, Puzzle (the hanoi.Puzzle class) must have a constructor that takes a string as a parameter. Ring (the hanoi.Ring class) must have a constructor that takes a string and a number as parameters. Variables as declared above will create an instance of the respective class.
Furthermore, depending on whether the Ring class has public members, or at least public getter and setter methods for internal members, rules such as the following might be allowed, where diameter is a publicly accessible member of class Ring.
RuleSet <nameOfRuleSet> ( . . . Rules ( r1: if smallRing.diameter >= mediumRing.diameter then result = someAction(); ) . . . ) |