[Home: Demos and Tutorials][e2gRuleEngine Mini-Course Index]

Building and Using Expert Systems: a Mini-Course Introducing the e2gRuleEngine Expert System Shell and e2gRuleWriter Decision Table Software

Module 7: Designing and implementing e2gRuleEngine knowledge bases that deliver your  knowledge

Module 7 Index

In this module, we'll use a hypothetical graduate school admission process as a case study to illustrate some ideas about knowledge base design, construction and debugging. A listing of the complete e2gRuleEngine graduate admissions knowledge base is included in the module for reference.

If you haven't already done so, taking a look at Module 6: Introduction to Knowledge Engineering is recommended because it provides supporting material for this discussion. We'll also assume that you have worked the examples in Module 4: Creating your first knowledge base so that you know how to enter a knowledge base and create a Web page that loads the e2gRuleEngine applet to access your rules.

Admissions recommendation logic: The logic for the example expert system is represented by the following flow chart:

Graduate Admissions Recommendation Logic

Framework: An expert system is developed in a conceptual framework that represents the problem domain. This structure supports the knowledge decomposition that leads to the definition of attributes and creation of rules as described in Module 6. Procedural examples like this admissions process are often documented in a flowchart or decision tree format when knowledge engineering begins. It is tempting to develop a rule to represent each path through the flow chart, but additional analysis that identifies and names subconcepts could produce a knowledge base that more clearly supports two of the justifications for using an expert system: the ability to explain why a recommendation was made and the ability to make a recommendation using a minimum amount of factual input.

Expert system outputs: A list of the possible admissions recommendations can be extracted from the flow chart:

  1. Admit with full status
  2. Admit with full status (special decision)
  3. Admit provisionally
  4. Admit provisionally with recommended remedial English coursework
  5. Refer to academic department for decision
  6. Admit conditionally (special decision)
  7. Wait for transcript before making decision
  8. Deny normal admission (could be reviewed)

Recommendations 1-5 are possible for students who have provided a final undergraduate transcript. Recommendations 6-7 are possible for students who have not provided a final undergraduate transcript. Recommendation 8 is possible whether or not the undergraduate degree has been completed.

Expert system inputs: Here is a grouped list of the attributes, identified from the flow chart, for which input PROMPTs will be written:

Certainty factors: Because these inputs are factual rather than opinions, certainty factor input will not be requested for any of the PROMPTs in this knowledge base: the optional CF parameter is not used in the PROMPTs.

Multi-valued attributes: There are four parameters representing special honors, and an applicant could possess any combination of these. The parameters are used in several rules, and the fact that an applicant possesses none of the attributes is also used in several rules. This set of circumstances is efficiently represented in an e2gRuleEngine knowledge base through the combined use of the AllChoice PROMPT along with the MAXVALS and DEFAULT statements:

PROMPT [the applicant] AllChoice
"This applicant is (check all that apply):"
"an honor student"
"an honor graduate"
"a class valedictorian"
"a class salutatorian"

MAXVALS [the applicant] 4
DEFAULT [the applicant] = "not the recipient of special honors"

The AllChoice PROMPT allows the knowledge base user to check any or all of the parameters describing the applicant's special honors. A MAXVALS statement allowing four values of the applicant must be included or values beyond the first one entered will be discarded.

It is often useful for a rule to detect the fact that no value can be found for an attribute. This is accomplished in e2gRuleEngine by employing the DEFAULT statement. The PROMPT for the applicant is the only source of values for this attribute. If none of the values are checked when the PROMPT is issued, the inference engine determines that the value cannot be resolved and the DEFAULT value "not the recipient of special honors" is assigned. Here is an example rule that will only fire for an applicant who has received no special honors:

RULE [Conditional eval, low GRE]
If [the evaluation] = "for a conditional decision" and
[the applicant] = "not the recipient of special honors" and
[the applicant's GRE score] < 1100
Then [the recommendation] = "wait for transcript" and
[the action] = "based on established policy"

Interim constructs: Knowledge bases are sometimes simplified and recommendation justifications clarified by using interim constructs to capture a common theme. The next pair of rules captures the logic in the flow chart that determines the need to examine the applicant's undergraduate GPR:

RULE [Consider undergraduate GPR (no grad credits)]
If [the applicant's graduate status] = "no prior graduate work completed"
Then [the undergraduate GPR should be considered] = true

RULE [Consider undergraduate GPR (grad credits)]
If [the applicant's graduate status] = "prior graduate work completed" and
[the applicant's GPR on prior graduate work] > 2.99
Then [the undergraduate GPR should be considered] = true
The contrived attribute the undergraduate GPR should be considered may then be used in rules like the following:
RULE [Deny because of undergraduate GPR]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] < 2.5
Then [the recommendation] = "deny normal admission" and
[the action] = "based on established policy"
Without this device, the following rules would be required to capture the same logic (and there are several similar rules that must determine whether to evaluate the undergraduate GPR):
RULE [Deny because of undergraduate GPR (no grad credits)]
If [the applicant's graduate status] = "no prior graduate work completed" and
[the applicant's GPR on last 60 undergraduate hours] < 2.5
Then [the recommendation] = "deny normal admission" and
[the action] = "based on established policy"

RULE [Deny because of undergraduate GPR (grad credits)]
If [the applicant's graduate status] = "prior graduate work completed" and
[the applicant's GPR on prior graduate work] > 2.99 and
[the applicant's GPR on last 60 undergraduate hours] < 2.5
Then [the recommendation] = "deny normal admission" and
[the action] = "based on established policy"

The knowledge base: the complete knowledge base is provided in the following table as a reference.

Graduate Admissions Knowledge Base
REM Graduate admissions demonstration expert system

REM Decide how to proceed

RULE [Language requirement] 
If [the applicant's UG status] = "receiving a bachelor's degree from a US institution" or
[the applicant's TOEFL score] > 499
Then [the language requirement] = "met"

RULE [Conditional consideration]
If [the language requirement] = "met" and
[the applicant's final undergraduate transcript] = "not available"
Then [the evaluation] = "for a conditional decision"

RULE [Full consideration]
If [the language requirement] = "met" and
[the applicant's final undergraduate transcript] = "available"
Then [the evaluation] = "for a full decision"

REM Conditional evaluation

RULE [Wait for transcript]
If [the evaluation] = "for a conditional decision" and
[the applicant's GPR on last 60 undergraduate hours] < 3.3
Then [the recommendation] = "wait for transcript" and
[the action] = "based on established policy"

RULE [Honor student]
If [the evaluation] = "for a conditional decision" and
[the applicant's GPR on last 60 undergraduate hours] > 3.29 and
[the applicant] = "an honor student" 
Then [the recommendation] = "admit conditionally" and
[the action] = "based on special decision"

RULE [Conditional eval, high GRE]
If [the evaluation] = "for a conditional decision" and
[the applicant] = "not the recipient of special honors" and
[the applicant's GRE score] > 1099
Then [the recommendation] = "admit conditionally" and
[the action] = "based on special decision"

RULE [Conditional eval, low GRE]
If [the evaluation] = "for a conditional decision" and
[the applicant] = "not the recipient of special honors" and
[the applicant's GRE score] < 1100
Then [the recommendation] = "wait for transcript" and
[the action] = "based on established policy"

REM Full evaluation

REM Deny

RULE [Deny because language requirement not met] 
If [the applicant's UG status] = "not receiving a bachelor's degree from a US institution" and
[the applicant's TOEFL score] < 500
Then [the recommendation] = "deny normal admission" and
[the action] = "based on established policy"

RULE [Deny because of graduate GPR]
If [the applicant's graduate status] = "prior graduate work completed" and
[the applicant's GPR on prior graduate work] < 3.0
Then [the recommendation] = "deny normal admission" and
[the action] = "based on established policy"

RULE [Consider undergraduate GPR (no grad credits)]
If [the applicant's graduate status] = "no prior graduate work completed"
Then [the undergraduate GPR should be considered] = true

RULE [Consider undergraduate GPR (grad credits)]
If [the applicant's graduate status] = "prior graduate work completed" and
[the applicant's GPR on prior graduate work] > 2.99
Then [the undergraduate GPR should be considered] = true

RULE [Deny because of undergraduate GPR]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] < 2.5
Then [the recommendation] = "deny normal admission" and
[the action] = "based on established policy"

RULE [Deny because of undergraduate GPR and GRE]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] > 2.49 and
[the applicant's GRE score] < 900
Then [the recommendation] = "deny normal admission" and
[the action] = "based on established policy"

RULE [Deny because of GRE]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] > 2.49 and
[the applicant] = "not the recipient of special honors" and
[the applicant's GRE score] < 900
Then [the recommendation] = "deny normal admission" and
[the action] = "based on established policy"

REM Provisional acceptance

RULE [Provisional acceptance: low GRE, verbal GRE]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] > 2.49 and
[the applicant] = "not the recipient of special honors" and
[the applicant's GRE score] > 899 and
[the applicant's GRE score] < 1100 and
[the applicant's GRE verbal score] < 400
Then [the recommendation] = "admit provisionally - recommend English remediation" and
[the action] = "based on established policy"

RULE [Provisional acceptance: low GPR, verbal GRE]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] > 2.49 and
[the applicant's GPR on last 60 undergraduate hours] < 3.0 and
[the applicant's GRE score] > 899 and
[the applicant's GRE verbal score] < 400
Then [the recommendation] = "admit provisionally - recommend English remediation" and
[the action] = "based on established policy"

RULE [Provisional acceptance: low GRE]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] > 2.99 and
[the applicant] = "not the recipient of special honors" and
[the applicant's GRE score] > 899 and
[the applicant's GRE score] < 1100 and
[the applicant's GRE verbal score] > 399
Then [the recommendation] = "admit provisionally" and
[the action] = "based on established policy"

RULE [Provisional acceptance: low GPR]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] > 2.49 and
[the applicant's GPR on last 60 undergraduate hours] < 3.0 and
[the applicant's GRE score] > 899
Then [the recommendation] = "admit provisionally" and
[the action] = "based on established policy"

REM Accept

RULE [Acceptance: honors]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] > 2.99 and
[the applicant] : "an honor graduate" "a class valedictorian" "a class salutatorian"
Then [the recommendation] = "admit with full status" and
[the action] = "based on special decision"

RULE [Acceptance at departmental discretion]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] > 2.99 and
[the applicant] = "not the recipient of special honors" and
[the applicant's GRE score] > 1099 and
[the applicant's GRE verbal score] < 400
Then [the recommendation] = "admission decision is at department's discretion" and
[the action] = "based on established policy"

RULE [Acceptance]
If [the undergraduate GPR should be considered] = true and
[the applicant's GPR on last 60 undergraduate hours] > 2.99 and
[the applicant] = "not the recipient of special honors" and
[the applicant's GRE score] > 1099 and
[the applicant's GRE verbal score] > 399
Then [the recommendation] = "admit with full status" and
[the action] = "based on established policy"

REM Prompts

PROMPT [the applicant's UG status] MultChoice
"This applicant is:"
"receiving a bachelor's degree from a US institution"
"not receiving a bachelor's degree from a US institution"

PROMPT [the applicant's TOEFL score] Numeric 
"What is the applicant's TOEFL (Test of English as a Foreign Language) score?"
"0"
"800"

PROMPT [the applicant's GPR on prior graduate work] Numeric
"What is the applicant's GPR (Grade point ratio) for prior graduate work?"
"0"
"4.0"

PROMPT [the applicant's final undergraduate transcript] MultChoice
"The applicant's final undergraduate transcript is:"
"available"
"not available"

PROMPT [the applicant's GPR on last 60 undergraduate hours] Numeric
"What is the applicant's GPR (Grade point ratio) for the last 60 UG hours?"
"0"
"4.0"

PROMPT [the applicant's graduate status] MultChoice
"This applicant's graduate status is:"
"prior graduate work completed"
"no prior graduate work completed"

PROMPT [the applicant's GPR on prior graduate work] Numeric
"What is the applicant's GPR (Grade point ratio) on prior graduate work?"
"0"
"4.0"

PROMPT [the applicant] AllChoice
"This applicant is (check all that apply):"
"an honor student"
"an honor graduate"
"a class valedictorian"
"a class salutatorian"

PROMPT [the applicant's GRE score] Numeric
"What is the applicant's total GRE (Graduate Record Exam) score?"
"0"
"1600"

PROMPT [the applicant's GRE verbal score] Numeric
"What is the applicant's GRE verbal score?"

GOAL [the recommendation]
GOAL [the action]

MAXVALS [the applicant] 4

DEFAULT [the applicant] = "not the recipient of special honors"


Recommendations for implementing and debugging a knowledge base

When the "Start the consultation" button is clicked on the e2gRuleEngine applet's opening screen, the knowledge base is loaded and syntax checked. If an error is encountered, loading immediately stops and an error number is displayed. If the test is run in the "debug" mode (the DEBUG applet parameter has the value "true") the line containing the error is displayed in the "Knowledge Base Developer's Output" window. As a result, it is most efficient to adhere to the following advice when building a knowledge base:

Some additional debugging suggestions that you might find helpful:

Finally, here is a summary of some commonly encountered knowledge base problems.

Knowledge Base Debugging Suggestions
Symptom Probable Cause Finding the problem
When the Web page containing <APPLET...> tags loads, a grey panel persists where the e2gRuleEngine opening screen should appear after the applet is downloaded. The applet cannot be found, or crashes after loading. Look for an error message on browser's status line. Check the Java console for error messages. Make sure the e2gRuleEngine.jar file is installed in the proper location on the Web server and that the CODE and ARCHIVE attributes in the <APPLET> tag are specified correctly.
Attribute values for which PROMPTs exist are never requested Different spellings, spacing or punctuation of an attribute name. Run in Debug mode (set the DEBUG <APPLET> parameter to "TRUE"), click "Start the consultation" then click "Analyze KB" in the KNOWLEDGE BASE DEVELOPER'S window. Review the ATTRIBUTE USAGE section of the resulting KNOWLEDGE BASE ANALYSIS for attribute naming problems.
Rules don't fire that should fire as a result of user input. Different spellings, spacing or punctuation of an attribute value. Run in Debug mode (set the DEBUG <APPLET> parameter to "TRUE"), click "Start the consultation" then click "Analyze KB" in the KNOWLEDGE BASE DEVELOPER'S window. Review the VALUE USAGE section of the resulting KNOWLEDGE BASE ANALYSIS for value definition problems.
In the final explanation of conclusions, some rules don't seem to have used all of the known facts in their explanation even though these attributes are in the premise. Could be normal when premise clauses connected by OR Once a rule has fired, it will not be examined again by the inference engine. When premise clauses are OR'd the true premise clause with the highest CF fires the rule.


Performing numerical calculations in rule consequents

Beginning with e2gRuleEngine version 6.0, it is possible to perform mathematical calculations in a rule consequent. Here is a knowledge base that demonstrates the capability by calculating an employee's pay. The objective is to calculate the pay based on a selected hourly rate for the first 40 hours and time-and-a-half for hours worked over 40:

Numerical Calculation Demonstration Knowledge Base
REM demonstrate e2gRuleEngine calculation capability

RULE [calculate overtime hours]
If [the number of hours worked] > 40
Then [the overtime hours] = {[the number of hours worked] - 40}

RULE [calculate pay]
If [the hourly rate] ? and
[the number of hours worked] ? and
[the overtime hours] ?
Then [the gross pay] = {[the hourly rate]*([the number of hours worked]-[the overtime hours])+1.5*[the hourly rate]*[the overtime hours]} @95

REM MultChoice prompt to demonstrate coercing string values into numeric

PROMPT [the hourly rate] MultChoice CF
"The hourly rate is:"
"5.00"
"10.00"
"15.00"

PROMPT [the number of hours worked] Numeric CF
"The number of hours worked is:"
"0.0"
"80.0"

DEFAULT [the gross pay] = 0
DEFAULT [the overtime hours] = 0

GOAL [the gross pay]

MINCF 70

To run this knowledge base, CLICK HERE.

The conditions for incorporating numeric calculations in an e2gRuleEngine rule include:


Adding hyperlinks to final results

Beginning with e2gRuleEngine v7.0, it is possible to add hyperlinks to the final results of an expert system consultation. This permits the user to link to Web pages that could include more detailed recommendations, references or advertising. The hyperlinks may be used in two ways. The first and simplest loads the Web content into the e2gRuleEngine applet, displacing the final results screen while incorporating a button to return to the final results display. The second technique uses the JavaScript interface (described in detail in Module 9) to load Web pages into a new window or frame provided by the browser that is running the e2gRuleEngine applet. In both cases the hyperlink is defined in the knowledge base and specifies the attribute and attribute value for which a link is desired and the Web address (URL) representing the link.

The new knowledge base commands and parameter that support hyperlinking include:

HYPERLINK [attribute name] = "attribute value" "URL to link to when this attribute value of this attribute name is clicked on final results display"
JSHYPERLINK [attribute name] = "attribute value" "URL and optional additional parameters to pass to JavaScript window.open() function"
TRANSLATE TR_HYPERLINK = "modifies text to display at end of any hyperlinked results - default is: Click underlined text to link to more information"

The HYPERLINK and JSHYPERLINK commands may both be used in the same knowledge base, and each may be used multiple times to hyperlink different values of different goal attributes.

A new HYPERENCODING parameter (applet tag) will generally not be required, but is provided to allow linking to HTML files with the HYPERLINK command that are stored with unusual character encoding.

<param name="HYPERENCODING" value="character encoding">
Special considerations when using the JSHYPERLINK and HYPERLINK commands
Character encoding with JSHYPERLINK: HTML files that define Web pages may be stored using a variety of different character encodings. Browsers generally do a good job of detecting the encoding used to store the files that they are loading, and are therefore able to render the output as intended. Browsers also provide menu options to change the display encoding (on the "View" menu in FireFox, the "Page" menu in MS Explorer and the "Control Page" menu in Chrome, for example). The output produced by a JSHYPERLINK is rendered by the browser running the applet, so the full detection ability of the browser is called into play for this output. Some problems have nevertheless been encountered when the JSHYPERLINK capability is used and the HTML file hosting the applet and the linked HTML files are stored using different character encodings. The problem symptom is HTML output garbled because it has been loaded with the wrong character encoding. Changing the display encoding from the browser menu before running the application may correct the problem. Testing your expert system with multiple browsers is recommended, particularly if you are using the JSHYPERLINK capability. You will find it helpful to include an explicit content-type meta tag in the <head>...</head> section at the beginning of the HTML file hosting the e2gRuleEngine applet and the linked files -- most Web pages include this meta tag. For example:
<META http-equiv="Content-Type" content="text/html; charset=UTF-16" />
or:
<META http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Character encoding with HYPERLINK: The HTML output that the HYPERLINK command links to is read by e2gRuleEngine, not the browser running the applet. It is therefore up to e2gRuleEngine to determine the character encoding. In version 7.00 of the software, this is accomplished by looking for a BOM (byte order marker) at the beginning of the linked HTML file. If bytes matching the BOM for UTF-8 encoding are found the file is loaded with this encoding. If bytes matching the BOM for Unicode big endian or Unicode little endian character encoding are found, the file is loaded using UTF-16 encoding. Otherwise, the file is loaded with default encoding. This technique should work for most files that could reasonably be used to generate Web pages since the UTF-8 and Unicode BOM character combinations would be unlikely to appear in these files by accident. If the file must be read using some other character encoding, add the HYPERENCODING parameter specifying the desired encoding to the applet tags. The three HTML files used as links in the examples that follow (hyperdemo1.html, hyperdemo2.html and hyperdemo3.html) were generated with Microsoft's Notepad editor and stored with three of the output character encodings supported by Notepad: UTF-8, UTF-16 little endian and UTF-16 big endian respectively. These files work properly with the examples and should be representative of the character encodings likely to be encountered with Web pages. These files also include the "content-type" meta tag described in the previous paragraph. Character encoding problems will be of most concern to users working with non-Roman character sets such as Chinese or Cyrillic that are represented with two bytes per character in HTML files.

HYPERLINK HTML limitations: The rendering of HTML outlet in the applet (using HYPERLINK) supports only a subset of mainstream browser capabilities, and this should be kept in mind when deciding whether to use HYPERLINK or JSHYPERLINK to support hyperlinks. If Web pages you link to are displayed properly in a browser, but not in the applet, it is likely that they incorporate HTML that is not supported (or supported in a different way) by the applet at this time. HTML support in the applet does not always ignore HTML errors the way browsers do, and may generate a message that the file cannot be loaded when an error is encountered or may simply produce a blank page. As an example, the Java HTML rendering engine cannot process <SCRIPT> tags.

Because of Java applet security requirements (the so called Java "sandbox") URLs provided in HYPERLINK tags must refer to pages located on the server from which the e2gRuleEngine applet was loaded. Java applets (unlike Java applications) cannot read files from Web servers other than the one from which the applet was loaded. This limitation does not apply to JSHYPERLINKs.

Popup blockers and JSHYPERLINK: The mechanism used by the JSHYPERLINK command to link to Web pages is similar to the technique used by commercial Web sites to produce "popup" windows displaying advertising. Popup blockers provided as a browser capability or add-on software will prevent JSHYPERLINKs from functioning unless the blocker is turned off.

Three examples follow that illustrate various ways of using and combining the HYPERLINK and JSHYPERLINK commands. Running each example, then examining the supporting HTML files and knowledge bases is strongly recommended. A provision for downloading the files defining the examples is provided at the end of the examples.

[Index][Module 1][Module 2][Module 3][Module 4][Module 5][Module 6][Module 8][Module 9][Module 10][Reference]


Copyright © 2001 - 2010 by eXpertise2Go.com. All rights reserved.
webmaster@expertise2go.com