Creating an expert system

UPDATE 5 October 2013: Due to changes in the latest Java plugin, eXpertise2Go cannot be used in the way described here. However, I have successfully used a similar system, CLIPS, to create expert systems and use the examples, tasks, and lesson ideas described here. Please see Creating an Expert System with CLIPS.

Yesterday’s blog post contained several examples of expert systems for ITGS students and teachers. In today’s post, we’re going to create our own simple expert system. The software we are going to use for this is called Expertise2Go, which is free to download. You can also download the software and the files for this tutorial (including this blog post as a classroom handout) from the Artificial Intelligence section of the ITGS textbook site.

Expert system components
First though, a quick recap. Expert systems have three main components: a user interface which poses questions to the user and provides an answer; the knowledge base which contains facts and rules in a specific knowledge domain (for example, medical diagnosis); and the inference engine whose job it is to infer answers or solutions by examining the user’s input and the contents of the knowledge base. A knowledge engineer is responsible fro taking knowledge from the human expert and writing it as a set of computer rules (i.e. programming).

 

In this tutorial, we are going to create the user interface and the knowledge base for a very simple expert system: one that determines the title for a person from the options: Mr, Mrs, or Miss. (I won’t get into the Ms debate right now). The diagram below shows the knowledge in this domain.

Creating an expert system

 

Expert systems for Expertise2Go are created in plain text files. The downloads above automatically load expert.kb, so open that file in a text editor (Notepad or Text Edit).
Goals
The GOAL command is used to specify what the expert system is trying to achieve. GOAL is followed by a variable name. In this example we are trying to determine a person’s correct title (Mr, Mrs, Miss), so our goal is:GOAL [title]

(the square brackets are required around all variable names)

The User Interface
The PROMPT command is used to get input from the user. Whatever the user types will be stored in the variable whose name is written after the PROMPT command.

There are different types of PROMPT. A MultChoice prompt provides the user with a list of options from which to choose. The next line contains the prompt or question for the user (in quotes), and the choices are written on the lines after that (again, in quotes). For example, to prompt a user whether they are male or female, and store their answer in a variable called [gender], we would use the code:

PROMPT [gender] MultChoice
“What is your gender?”
“Male”
“Female”

The Knowledge Base
The knowledge base consists of a series of RULEs. Each rule has a name which follows the RULE statement and is written in square brackets. Like variables, rules should be given sensible names to make them memorable and clear.

Usually rules test the value of one or more variables and make a decision based on that. In our example, to determine whether a person’s correct title is “Mr”, we need to know if they are male. A simple rule to do this looks like this:

RULE [1. Mr]
If [gender] = “Male”
THEN [title] = “Mr”

The If [gender] clause of this rule will automatically call the PROMPT gender above to ask the user their gender. The user’s answer will be stored in the gender variable and then compared to “Male”. If it matches, the variable title (notice how we used title in our GOAL earlier) is assigned the value “Mr” and the program will the end. If it does not match, the program moves onto the next rule.

Some rules must consider more than one variable. For example, if the user is female we must then also consider the marital status to determine the title. We need two rules to achieve this:

RULE [2. Mrs]
If [gender] = “Female” and
[marital status] = “Married”
Then [title] = “Mrs”

RULE [3. Miss]
If [gender] = “Female” and
[marital status] = “Single”
Then [title] = “Miss”

(Both of these rules assume we have written another PROMPT in our user interface which asks for the user’s marital status and stored it in a variable called “marital status”)

When the knowledge base rules and the user interface prompts are completed, the expert system can be running using the Run-expert-system.html file in the folder you downloaded.

[Note: Expertise2Go requires the RULE statements to appear in the text file before the PROMPT statements.]

Download Expertise2Go files, tutorial and additional tasks

Be the first to comment

Leave a Reply

Your email address will not be published.


*