# Introduction to the Rules Package

These HTML pages are available in book form as a postscript file.

The Able Rules package has many parts. At the package's heart is the AbleRuleSet class, a Java bean that, when customized, can provide many different types of inferencing to Java applications. If you are new to this package, please take time to read the Overview provided below. If you are looking for detailed information, select one of the other topics listed.

### Index of Related Topics

- Overview of the Rules Package

  A brief look at the `com.ibm.able.rules` package and how it fits into, and can be used outside of, the ABLE environment.

- #### Able Rule Language (ARL) Master Index

  The Able Rule Language is rich and varied. This document describes the structure of source rule language files and explains in detail the capabilities and syntax of ARL.

- #### Able RuleSet Editor Master Index

  The Able RuleSet Editor provides the best way to customize rulesets with rules and inferencing strategies. This document explains how to start the ruleset editor from within the Able Editor or as a stand-alone program, and provides information on how to use the RuleSet Editor's menu items, toolbar buttons, context menus, and other features to customize an Able ruleset.

- #### Able RuleSet XML Documents

  In addition to authoring rulesets in Able Rule Language, rulesets can be described in XML documents. This document explains the XML markup for Able rulesets.

- #### Able RuleSet Examples

  Able ships with many ruleset examples. This document, which is actually a link to Able's `com.ibm.able.examples.rules` package, explains how to view and run the ruleset examples.

Note: This documentation assumes the reader is already familiar with fuzzy logic, fuzzy sets, and other mechanisms of inferencing, such as backward and forward chaining. No attempt is made to explain these concepts or their use. The documentation also assumes a familiarity with Java concepts, including JavaBeans. No attempt is made to explain classpaths, compiling Java programs, manifest files, jar files, or JavaBean design patterns. In short, the documentation is written for the experienced Java programmer who has familiarity with reasoning techniques.

### Overview

The heart of the Able Rules package is the AbleRuleSet class, a Java bean that, when customized, can provide many different types of inferencing to Java applications.

#### The Heart of the Package: The AbleRuleSet Object

Precisely because the AbleRuleSet object is a Java bean, this object comes with its own customizer, the Able RuleSet Editor, that can be used to define rules of inferencing, specify inferencing strategies, and test and debug rules. And, like any Java bean, AbleRuleSet objects also have an Application Programming Interface, or API, that can be used by Java programs to perform the same sort of tasks programmatically. The API is not discussed in this documentation, however, because it is fully documented in the JavaDoc output generated for the AbleRuleSet and its associated classes.

Because the AbleRuleSet object is also derived from both the AbleObject class and the AbleBean interface, AbleRuleSet objects, like any other object derived from these Able classes, can be created, manipulated, customized, and packaged from within Able's Agent Editor Interactive Development Environment, or IDE, meaning that AbleRuleSet objects can be wired to receive (perhaps filtered) input from and write output to managed buffer connections; PropertyChangeListeners can register with them; and, because AbleRuleSet objects are yet another type of Able object, AbleUserDefinedFunctionManager objects, rules you author can call and obtain output from the methods of any external Java object.

#### Creating AbleRuleSet Objects

There are several ways to create AbleRuleSet objects. Bear in mind, though, that a newly created ruleset has no rules or inferencing strategies associated with it; you have to add those later, either by using the customizer (the RuleSet Editor) or programmatically. Techniques to customize an empty ruleset object are described in Customizing AbleRuleSet Objects a little further on.

- The easiest way to create an AbleRuleSet object is to fire up the Agent Editor, select the Rules tab, and then select the ruleset icon. Once a ruleset icon has been placed on the Agent Editor's canvas, you can click on the icon (using mouse button 2) to bring up the ruleset's context menu. Select the Properties... menu item, and when the customizer, or RuleSet Editor, appears, you can begin to customize your ruleset. See Customizing AbleRuleSet Objects below for more information.

- You do not need to use the Agent Editor to create and then customize a ruleset; you can also run the RuleSet Editor as a standalone Java program. Select the `runRsEditor` shell script in Able's `.../bin/` directory to start the ruleset editor. The RuleSet Editor will open on a new, empty ruleset, which you can begin customizing, or you can load an existing ruleset into the editor by using the editor's menus (see Customizing AbleRuleSet Objects below) or by passing the name of an Able Rule Language (ARL) source file via the command line.

- Obviously, AbleRuleSet objects can be created programmatically; for example,
  `AbleRuleSet rs = new AbleRuleSet();`
  Once created, low level methods can be used to create variables and rules, for example,
  `rs.addVariable(new AbleContinuousVariable(1,100,50));`
  or
  `rs.instantiateFrom("mySourceFile.rs");`
  or even
  `rs.instantiateFromXml("mySourceFile.rs_xml");`
  More detail than this is outside the scope of this documentation. See the JavaDoc output.

#### Customizing AbleRuleSet Objects with Rules and Inferencing Strategies

Once you have created a ruleset, you need to customize it by loading it with variables, rules, inferencing strategies, and the like. Fortunately, this is easy to do, and, as always seems true when using Java, there are multiple ways to do it!

- The oft-mentioned Able RuleSet Editor doubles as a customizer for AbleRuleSet objects and as an editor environment for writing, testing and debugging rules. In the editor, you can type source Able Rule Language (ARL) statements, compile them, and test them out. You can also load rules from source files containing ARL statements or XML documents, such as those found in the examples area of Able. When you have the rules to your liking, you can use the editor's actions to save your rules to disk as a source file or an XML document, or, you can save the whole ruleset you just customized as a serialized Java object that can be incorporated into other Java objects.

  The Able Rule Language is documented in a separate document, Rule Language Documentation, and you can learn about the intricacies of the RuleSet Editor in RuleSet Editor Documentation.

- You do not need to use the Able RuleSet Editor to create rule language source files; in fact, any old text editor will do, but you will, of course, lose all the syntax checking capabilites found in the RuleSet Editor. Once you have created a source rule language file, or an XML document, you can create a ruleset object and then tell the ruleset object to instantiate itself from your source or XML file. The ruleset will verify that your rules are correct when it reads them.

- Lastly, you can, of course, customize a ruleset from another Java program by calling the methods that make up the ruleset's API. This is a very tedious process and not recommended. It might be interesting to note, however, that this same API is used by the rule compiler when it verifies a source file or XML document.

When you customize a rule set, you need to decide what type of inferencing you want performed when your rules are processed. The next section discusses the types of inferencing available.

#### Inferencing Algorithms

There are two basic styles of inferencing available: boolean inferencing and fuzzy inferencing, and each of these has subtypes available. For example, boolean inferencing includes traditional backward, forward, and mixed chaining, and of those, forward chaining includes a very simple algorithm using no working memory, to OPS-like pattern matching making use of working memory and rete networks. When using fuzzy rules, the rule language lets the rule author choose different strategies for inferencing, correlating antecedents with consequents, and defuzzifying fuzzy numbers. You can therefore match the tool to the job.

#### Viewing and Running RuleSet Examples

Able ships with many rule examples, with both boolean logic and fuzzy logic. Most of these examples take the form of source ARL files, which you can use to customize an AbleRuleSet object. Just follow the directions above for creating an AbleRuleSet and then customizing it. When the Able RuleSet Editor appears, use one of the many Open... editor actions to load a source rule file or XML document, and then compile (verify, in Able terminology) it. Once the rules are compiled, your ruleset is ready to be run or saved as a serialized Java bean.

Some of the other examples are not source rule files, but Java programs that show you how to create, instantiate, and run a ruleset progammatically. If you process these rulesets from within the Able Editor, you may not see anything happen unless you have the Java console window open.

It is beyond the scope of this overview to document how to run all the rule examples. That information is provided in the `com.ibm.able.examples.rules` package.

#### Next Steps

From here it is suggested you now go and read up on the Able Rule Language, and experiment with the Able RuleSet Editor.

Last modified: Wed Jun 6 10:24:36 CDT 2001