AI-ExpertSystem-Simple
view release on metacpan or search on metacpan
bin/consult view on Meta::CPAN
################################################################################
# To do
# -----
# Save defaults for program to run, text colour etc
################################################################################
package require cmdline
################################################################################
# Some global variables
################################################################################
set display_information 1
set filehandle ""
set filename ""
set program "simpleshell"
set error ""
set choice ""
toplevel .askme
bin/consult view on Meta::CPAN
wm deiconify .askme
wm title .askme "What I want to know is?"
# Set the question text
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
}
bin/consult view on Meta::CPAN
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
################################################################################
proc do_load {} {
status "Load a file..."
set types {{{XML Files} {.xml}} {{All Files} *}}
global filename
set filename [tk_getOpenFile -filetypes $types -title "Load a knowledge base"]
if {$filename != ""} {
load_a_file $filename
} {
status "No file was selected"
}
}
proc load_a_file {filename} {
bin/consult view on Meta::CPAN
wm title . [append newtitle "Simple Inference Engine: " [file tail $filename]]
}
}
proc do_run {} {
status "Run the file..."
status "This may take a few moments to get started..."
.save configure -state normal
.run configure -state disabled
global filename
global program
set filehandle [open "|$program -t $filename" "r+"]
set question ''
set responses [list]
.text delete 0.1 end
while {![eof $filehandle]} {
set text [gets $filehandle]
bin/consult view on Meta::CPAN
################################################################################
# Utility functions
################################################################################
proc status {text} { mymessage $text is_status }
proc question {text} { mymessage $text is_question }
proc response {text} { mymessage $text is_response }
proc answer {text} { mymessage $text is_answer }
proc information {text} {
global display_information
if {$display_information == 1} {
mymessage $text is_information
}
}
proc mymessage {text tag} {
.text insert end "$text\n" $tag
.text see end
update
}
( run in 0.615 second using v1.01-cache-2.11-cpan-49f99fa48dc )