#! /usr/local/bin/perl # # Gather up the user responses and dump them to a file in a format usable by the # CLIPS "load-instance" command. # use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); my $query = new CGI; print $query->header('text/html'); print $query->start_html; ## Change this section print "
Note: sometimes you are not sure what kind of wine to have with a meal. In that case, you can click on the \"Not Sure\" button, and the expert system will attempt a \"best guess\" on the wine selection. But, the less information you give an expert system, the more ambiguous the results can become.
";
print "
One of the interesting things about expert systems is that you can receive more than one answer from the program. In this case, CLIPS will list wines in order of certainty, which is a measure of how likely a wine will match with the meal. If the certainty numbers are close (or equal), you will have to make a final choice from the list, or get a bottle of each wine and try them all!
" ;
print "
Do you generally prefer red or white wines?
",
$query->radio_group(
-name=>'preferred-color',
-values=>['Red', 'White', 'Not Sure'],
-default=>'Red');
print "
Do you generally prefer dry, medium, or sweet wines?
",
$query->radio_group(
-name=>'preferred-sweetness',
-values=>['Dry', 'Medium', 'Sweet', 'Not Sure'],
-default=>'Medium');
print "
Do you generally prefer light, medium, or full bodied wines?
",
$query->radio_group(
-name=>'preferred-body',
-values=>['Full', 'Medium', 'Light', 'Not Sure'],
-default=>'Medium');
print "
Is the main component of the meal meat, fish, or poultry?
",
$query->radio_group(
-name=>'main-component',
-values=>['Meat', 'Fish', 'Poultry'],
-default=>'Meat');
print "
If the main component of the meal is poultry does the meal have turkey in it?
",
$query->radio_group(
-name=>'has-turkey',
-values=>['Yes', 'No'],
-default=>'No');
print "
Is the flavor of the meal delicate, average, or strong?
",
$query->radio_group(
-name=>'tastiness',
-values=>['Delicate', 'Average', 'Strong'],
-default=>'Average');
print "
Does the meal have a sauce on it?
",
$query->radio_group(
-name=>'has-sauce',
-values=>['Yes', 'No'],
-default=>'No');
print "
If the meal has a sauce, is the sauce Spicy, Sweet, Cream, or Tomato?
",
$query->radio_group(
-name=>'sauce',
-values=>['Spicy', 'Sweet', 'Cream', 'Tomato'],
-default=>'nil');
print "
", $query->reset; print "
", $query->submit('Action', 'Submit Choices'); print $query->endform; } sub do_work { my($query) = @_; my(@values, $key); my $instance_file = "/tmp/GUIinstances.clp"; open(OUTFILE, "> $instance_file") or die "Cannot open the instance file: $!\n"; foreach $key ($query->param) { next if $key =~ /Action/; @values = $query->param($key); if (@values[0] =~ /Not/) { @values[0] = "unknown"; } print OUTFILE "( of ATTRIBUTE (att-name $key) (value ", lcfirst(@values[0]), ") (certainty 100.0))\n"; } close(OUTFILE); print "
"; print "
"; } sub print_tail { print "