e2gLite Tutorial Part 1

advertisement
EXPERT SYSTEM SHELL
e2gLiteTutorial_Part1
Prepared by Louise Hawkins and
Sylvia Ward (2008)
Table of Contents
e2gLite _______________________________________________________2
Introduction_______________________________________________________ 2
Expertise2go demo _________________________________________________ 2
Tutorial A _____________________________________________________3
To build your own Knowledgebase ____________________________________ 3
Steps required to develop a knowledge base ___________________________________ 4
Understanding the components of your knowledge base __________________________ 6
How to go about debugging knowledge bases __________________________________ 8
e2gLite
Introduction
Expert systems shell.
T
his tutorial will assist you to learn how to use e2gLite. e2gLite is a rule-based expert system
shell. e2gLite is a development toolkit (a 'shell') developed by eXpertise2GO. Access to the
e2gLite
documentation
provided
by
eXpertise2Go
is
available
from
http://expertise2go.com/webesie/e2gdoc/ .
Icons: The icons (below) are used throughout the manual to highlight key concepts.
I C O N
K E Y
Warning
Save now
Expertise2go demo
To start, go to http://expertise2go.com/webesie/e2gdoc/ and click on Module 1. Click on the “Graduate
school admissions, demonstration: end-user mode” link and run the graduate admissions demo. You
will see a webpage open up. Click on the button “Start the consultation” to run the demo. Answer each
question and the expert system will provide you with advice. (This is an American demonstration so
you may not understand what the questions are asking, but answer the questions with any appropriate
response to see the result).
2
Tutorial A
To build your own Knowledgebase
Creating your first knowledgebase
T
he components that make up a knowledge base using e2gLite consists of three files, the
e2gLite.jar file, the .kb file and the .html file. The e2gLite.jar file is the executable file which is
the expert system shell. The .kb file is the knowledge base which includes the goals, the rules
by which the goals will be reached, and the questions (prompts) which the user must answer.
The .html file is used to provide an appropriate interface for the system.
The following is a very simple example of an expert system using e2gLite.
What to wear problem
This simple expert system will help the decision maker to decide what to wear based on possible
weather conditions.
The questions relating to the inputs are:

Is the temperature high or low?

Is it likely to rain?
The inputs for this decision are:

Temperature (high, low)

Rain (yes, no)
The outputs for this decision are:

Wear a parka

Wear a sports coat

Wear a rain coat

Wear a shirt
The decision table below shows the inputs and outputs for the decision above.
Temperature
Low
Low
high
high
Rain
yes
no
yes
no
Advice on what to wear
wear a parka
wear a sports coat
wear a rain coat
wear a shirt
3
Steps required to develop a knowledge base
Step
1:
First,
you
need
to
download
the
e2glite.jar
file
from
http://expertise2go.com/webesie/e2gdoc/e2mod2.htm. (Link: “I agree to the conditions of use –
Download e2gLite”). This is the executable file that your expert system will use to run your
knowledge base.
Step 2: Create a folder for your expert system files and save the e2glite.jar file in this folder.
Step 3: Open a text editor (DOS based editor included with Windows or Notepad). (Do not use a word
processing application).
Step 4: Now type the following into the text file:
REM What to wear based on weather conditions (what_to_wear.kb)
REM Decide how to proceed
RULE [temperature low and weather wet]
If [temperature] = "low" and
[rain] = "yes"
Then [the recommendation] = "wear a parka"
RULE [temperature high and weather wet]
If [temperature] = "high" and
[rain] = "yes"
Then [the recommendation] = "wear a rain coat"
RULE [temperature low and weather dry]
If [temperature] = "low" and
[rain] = "no"
Then [the recommendation] = "wear a sports coat"
RULE [temperature high and weather dry]
If [temperature] = "high" and
[rain] = "no"
Then [the recommendation] = "wear a shirt"
REM Prompts
PROMPT [temperature] MultChoice
"Is the temperature high or low?"
"high"
"low"
PROMPT [rain] MultChoice
"Is it likely to rain?"
"yes"
"no"
GOAL [the recommendation]
Step 5: Save the file.
 Type in the name of the knowledgebase, what_to_wear.txt’ and save the file in the same folder
as you saved the e2gLite.jar file.
4
Step 6: Go to Windows Explorer and change the file extension from .txt to .kb by right clicking on the
file name and typing in the new extension. (Do not try to save the file as a .kb while in the text
editor).
Step 7: Now download the .txt template from the resources page on the course website.
Step 8: You will now need to use Notepad to develop the html file. Open the .txt template in Notepad
and change the appropriate sections. Remember to enter your name and student number in Line
11. The html file needs to look like this:
<HTML>
<HEAD><TITLE>Example 1</TITLE></HEAD>
<BODY BGCOLOR="white">
<FONT FACE="Arial,Helvetica" SIZE=2>
<CENTER><H2>What to wear</H2></CENTER>
This system allows you to decide what clothing to wear, based on different
weather conditions
<H4>Student name and student number</H4>
<P>
<CENTER>
<P><H3>What to wear (end-user mode)</H3>
<APPLET CODE="e2glite.e2g.class" archive="e2glite.jar" WIDTH=450 HEIGHT=300>
<PARAM NAME="KBURL" VALUE="what_to_wear.kb">
<PARAM NAME="APPTITLE" VALUE="What to wear">
<PARAM NAME="PROMPTCOLOR" VALUE="#ff0000">
<PARAM NAME="BGCOLOR" VALUE="#00ff00">
<PARAM NAME="DEBUG" VALUE="false">
Java-enabled browser required
</APPLET>
<P><H3>What to wear (debug mode)</H3>
<APPLET CODE="e2glite.e2g.class" archive="e2glite.jar" WIDTH=450 HEIGHT=300>
<PARAM NAME="KBURL" VALUE="what_to_wear.kb">
<PARAM NAME="APPTITLE" VALUE="What to wear">
<PARAM NAME="DEBUG" VALUE="true">
Java-enabled browser required
</APPLET>
</FONT>
</CENTER>
</BODY>
</HTML>
Step 9: Save the html file as what_to_wear.txt in the same folder as the .jar and .kb file. Go to
Windows Explorer and change the file extension from .txt to .html by right clicking on the file
name and typing in the new extension. (Do not try to save the file as a .html while in the text
editor).
Step 10: Now that you have created the three files for your expert system, go to the files using
Windows Explorer and double click on the .html file. Your knowledge base should start to run.
Step 11: Test your knowledge base by answering the questions and checking to see that you get an
appropriate answer.
5
Step 12: If your knowledge base does not work and you get an error message you will need to correct
the errors in the .kb and .html files.
Step 13: Use the debug link on the interface page to see where your errors are located.
The next section explains the elements in your knowledge base and provides some suggestions of
potential errors.
Understanding the components of your knowledge base
To understand how the elements in the what_to_wear.kb example interact, the following elements are
defined:
REM statements: These are single line comments, ignored when the knowledge
base is processed. The REM command must appear at the beginning of the line,
and everything else on that line is ignored.
Blank lines: Empty lines are optional and are ignored. They may be used to
improve readability of the knowledge base.
RULE definitions: Possible elements of each rule include:







The first line begins with RULE followed by a short identifying description
of the rule enclosed in square brackets.
The next line begins the rule premise with IF followed by a logical
expression consisting of:
o An attribute name enclosed in square brackets.
o A relational operator: = (equal) in the example. The other
possibilities include < > ! : representing less-than, greater-than,
not-equal-to and equals-any-of.
o A comparison quantity enclosed in matching single or double
quotes if it is a string. Other possiblities are a numeric value or the
Boolean values TRUE or FALSE.
(Optional) either of the logical operators AND or OR if there are multiple
logical expressions in the rule premise. If there is more than one premise
logical expression, they must all be connected by the same logical
operator. Each premise clause consisting of an attribute name, relational
operator and comparison quantity is entered on a separate line. The final
premise clause must not end with AND or OR.
The next line following a premise logical expression that doesn't end with
AND or OR begins the rule consequent with THEN followed by an
assignment statement consisting of:
o An attribute name enclosed in square brackets
o The assignment operator (=)
o The value to be assigned to the attribute: enclosed in matching
single or double quotes if it is a string. Other possibilities are a
numeric value or the Boolean values TRUE or FALSE.
Rule elements are not case sensitive.
Each element of a rule must be on a separate line as shown in the
example.
Once an attribute type has been established as either string(text), numeric
or Boolean, that attribute must remain that type. A change of the attribute
type will be an error.
PROMPT definitions: Prompts should be included in the knowledge base after all
rules are defined. Possible elements of each prompt include:

The first line begins with PROMPT followed by an attribute name enclosed
6

in square brackets followed by the prompt type. In addition to MultChoice
(multiple choice) shown in the example, prompt types include Choice
(drop down list box), AllChoice (accept multiple responses), YesNo
(Boolean input) and Numeric (accept a numeric value).
For MultChoice, Choice and AllChoice prompt types, alternate values to
be presented to the expert system user are presented on successive lines
enclosed in matching single or double quotes, one per line. For the
Numeric prompt type, the minimum and maximum values to accept are
provided on the next two lines and must be enclosed in matching single or
double quotes.
GOAL definitions: Each GOAL is defined on a single line that begins with GOAL
followed by the name of the goal attribute enclosed in square brackets. GOALs
may be specified before or after PROMPTS, but must follow RULE definitions.
There has to be at least one GOAL statement in a knowledge base: GOALs are
the attributes for which the inference engine seeks values.
Source: Adapted from http://expertise2go.com/webesie/e2gdoc/e2gmod4.htm
7
How to go about debugging knowledge bases
If your knowledge base does not work there are parts of the .kb and .html files that you need to check.
Potential errors:
1. You may have used an application to create the files that does not save ASCII text files. It will
not work for instance if you created the files in MSWord, saved them as a .txt file and then
changed the file extension. MSWord puts a lot of additional formatting in these .txt files that
e2gLite will not read.
2. When developing the rules, you need to use square brackets. Check to see that you have not put
curly brackets in error, or omitted the brackets altogether.
3. Your quotes need to be the straight quotes (If you have used a text editor the quotes should
automatically show as straight quotes)
4. Where two attributes are included in a RULE and you use AND or OR, the second attribute
must be on a separate line.
5. Make sure that you have included every line in the example.
6. The three files must be in the same folder.
7. Your .html file must include the name of the .kb file. Make sure that the names are the same and
that the spelling is correct. Check to see if you have used upper case instead of lower case and
vice versa.
You have now completed Tutorial Part 1, and your first Knowledge Wright
expert system.
8
Download