![]() |
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:
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:
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:
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:
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:
The knowledge base: the complete knowledge base is provided in
the following table as a reference.
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.
Graduate Admissions Recommendation Logic
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"
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"
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"
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
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:
| Mathematical Operator Precedence | ||
|---|---|---|
| Operator | Precedence | Operation |
| ^ | 3 | Exponentiation |
| * | 2 | Multiplication |
| / | 2 | Division |
| + | 1 | Addition |
| - | 1 | Subtraction |
Some examples to illustrate calculation precedence and the impact of parentheses:
5 + 2 * 10 = 25
(5 + 2) * 10 = 70
(5+2) * 10 ^ 2 = 700
((5+2) * 10) ^ 2 = 4900
RULE [Decide whether to buy] If (A + B) < 5 Then [result] = "buy the item"e2gRuleEngine cannot support this rule premise calculation. However, the following two rules will provide equivalent logic:
RULE [Calculate sum of A and B]
If [A] ? and
[B] ?
Then [AplusB] = {[A] + [B]}
RULE [Decide whether to buy]
If [AplusB] < 5
Then [result] = "buy the item"
The first rule will only fire when values are available for both A and B and will calculate their sum in the new variable AplusB. Then, the second rule
will be able to fire.