AI-ExpertSystem-Simple
view release on metacpan or search on metacpan
AI::ExpertSystem::Simple - A class implementing an expert system
This is release V1.2 of AI::ExpertSystem::Simple. The class
implements a simple expert system that reads its knowledge base
(set of IF .. THEN rules) from an XML file.
Three sample knowledge bases are provided along with a command line shell
that allows the knowledge bases to be consulted.
There is a Tcl/Tk based shell in which you can run a consultation, I
was going to write this in Perl/Tk as would seem obvious but this is
less than simple under OSX, infact I never got it to work. However there
was an OSX based version of Tcl/Tk and it would be easier to write the
shell in that which is much more portable (just install ActiveTcl on
Windows, Aqua Tcl/Tk on OSX and use what you have on Linux - ideal).
So I dont have to write to a lowest common installation of PerlTk and
bin/consult view on Meta::CPAN
label .askme.l -text $message -padx 10 -pady 10 -wraplength 300
pack .askme.l -side top -anchor n
# The is where the users choice will go
global choice
set choice ""
# Set up each button
set counter 1
foreach option $argv {
button .askme.$counter -text $option -command [list set choice $counter]
pack .askme.$counter -side top -anchor n -fill x
incr counter
}
vwait choice
# Our option has been set, now dismantel the
# contents of the toplevel so we can build it
# up again from scratch next time.
bin/consult view on Meta::CPAN
# Setting up the window
################################################################################
proc main {} {
wm title . "Simple Inference Engine"
wm geometry . 500x500
# The top frame holds the buttons
frame .top
button .load -text "Load..." -command "do_load" -width 8
button .run -text "Run" -command "do_run" -width 8 -state disabled
button .save -text "Save..." -command "do_save" -width 8 -state disabled
checkbutton .display -text "Display 'information' messages" -variable display_information -onvalue 1 -offvalue 0
pack .load .run .save .display -side left -anchor n -in .top
pack .top -anchor nw
# A log of the output is written here
text .text -yscrollcommand {.textscroll set}
scrollbar .textscroll -orient vertical -command {.text yview}
pack .text -side top -anchor w -fill both -expand 1
pack .textscroll -side right -fill y -in .text
# Define some colours
.text tag config is_status -foreground blue
.text tag config is_question -foreground red
.text tag config is_response -foreground cyan
.text tag config is_answer -foreground green
.text tag config is_information -foreground grey
# A nice hello message
status "Welcome to the Tcl/Tk expert system shell"
status ""
status "This program is used to call the command line"
status "expert system called simpleshell and allows"
status "you to interact with it via the gui"
status ""
status "First select a knowledgebase to load with the Load button"
status "Then start a consultation with the Run button"
status "You can rerun the consultation as many times as you like"
status ""
status "The Save button allows you to save the contents of the"
status "session to a file"
status ""
status "The \"Display 'information' messages\" check box is used"
status "to turn the grey information messages on and off. The "
status "information messages tell you what the expert system is"
status "up to and can be quite voluminous"
status ""
status "Have fun - Peter Hickman"
status ""
# Do we have a command line file
global filename
if {$filename != ""} {
load_a_file $filename
}
}
################################################################################
# Code to handle the buttons
################################################################################
bin/consult view on Meta::CPAN
proc mymessage {text tag} {
.text insert end "$text\n" $tag
.text see end
update
}
################################################################################
# The program starts here
################################################################################
# Was there a filename on the command line
set p_count 0
while {[set err [cmdline::getopt argv {f.arg p.arg} opt val]] > 0} {
switch -- $opt {
f {
if {$filename == ""} {
set filename $val
} {
set error "The $opt switch should only be used once"
( run in 1.799 second using v1.01-cache-2.11-cpan-0d23b851a93 )