AI-MegaHAL
view release on metacpan or search on metacpan
MODULE = AI::MegaHAL PACKAGE = AI::MegaHAL
PROTOTYPES: DISABLE
double
constant(name,arg)
char * name
int arg
void
megahal_setnoprompt ()
void
megahal_setnowrap ()
void
megahal_setnobanner ()
void
megahal_seterrorfile(filename)
char* filename
void
megahal_learn(input,log)
char* input
int log
void
megahal_output(output)
char* output
char*
megahal_input(prompt)
char* prompt
void
megahal_cleanup()
lib/AI/MegaHAL.pm view on Meta::CPAN
require DynaLoader;
require Exporter;
use AutoLoader;
use Carp;
use strict;
use vars qw(@EXPORT @ISA $VERSION $AUTOLOAD);
@EXPORT = qw(megahal_setnoprompt
megahal_setnowrap
megahal_setnobanner
megahal_seterrorfile
megahal_setstatusfile
megahal_initialize
megahal_initial_greeting
megahal_command
megahal_do_reply
megahal_learn
megahal_output
lib/AI/MegaHAL.pm view on Meta::CPAN
my $path = $args{'Path'} || ".";
if(-e "$path/megahal.brn" || -e "$path/megahal.trn") {
chdir($path) || die("Error: chdir: $!\n");
} else {
die("Error: unable to locate megahal.brn or megahal.trn\n");
}
# Set some of the options that may have been passed to us.
megahal_setnobanner() if(! $args{'Banner'});
megahal_setnowrap() if(! $args{'Wrap'});
megahal_setnoprompt() if(! $args{'Prompt'});
# This flag indicates whether or not we should automatically save
# our brain when the object goes out of scope.
$self->{'AutoSave'} = $args{'AutoSave'};
# Initialize ourselves.
$self->_initialize();
return $self;
}
lib/AI/MegaHAL.pm view on Meta::CPAN
'AutoSave' => 0);
Creates a new AI::MegaHAL object. The object constructor can optionaly receive the following named parameters:
=over 4
=item B<Path> - The path to MegaHALs brain or training file (megahal.brn and megahal.trn respectively). If 'Path' is not specified the current working directory is assumed.
=item B<Banner> - A flag which enables/disables the banner which is displayed when MegaHAL starts up. The default is to disable the banner.
=item B<Prompt> - A flag which enables/disables the prompt. This flag is only useful when MegaHAL is run interactively and is disabled by default.
=item B<Wrap> - A flag which enables/disables word wrapping of MegaHALs responses when the lines exceed 80 characters in length. The default is to disable word wrapping.
=back
=head1 METHODS
=head2 initial_greeting
$text = $megahal->initial_greeting();
libmegahal.c view on Meta::CPAN
char *helpstring;
COMMAND_WORDS command;
} COMMAND;
/*===========================================================================*/
static int width=75;
static int order=5;
static bool typing_delay=FALSE;
static bool noprompt=FALSE;
static bool speech=FALSE;
static bool quiet=FALSE;
static bool nowrap=FALSE;
static bool nobanner=FALSE;
static char *errorfilename = "megahal.log";
static char *statusfilename = "megahal.txt";
static DICTIONARY *words=NULL;
static DICTIONARY *greets=NULL;
static MODEL *model=NULL;
libmegahal.c view on Meta::CPAN
static void train(MODEL *, char *);
static void typein(char);
static void update_context(MODEL *, int);
static void update_model(MODEL *, int);
static bool warn(char *, char *, ...);
static int wordcmp(STRING, STRING);
static bool word_exists(DICTIONARY *, STRING);
static int rnd(int);
/* Function: setnoprompt
Purpose: Set noprompt variable.
*/
void megahal_setnoprompt(void)
{
noprompt = TRUE;
}
void megahal_setnowrap (void)
{
nowrap = TRUE;
}
void megahal_setnobanner (void)
{
nobanner = TRUE;
}
libmegahal.c view on Meta::CPAN
void megahal_output(char *output)
{
if(!quiet)
write_output(output);
}
/*
megahal_input --
Get a string from stdin, using a prompt.
*/
char *megahal_input(char *prompt)
{
if (noprompt)
return read_input("");
else
return read_input(prompt);
}
/*
megahal_command --
Check to see if input is a megahal command, and if so, act upon it.
Returns 1 if it is a command, 0 if it is not.
*/
libmegahal.c view on Meta::CPAN
exit(0);
}
/*---------------------------------------------------------------------------*/
/*
* Function: Read_Input
*
* Purpose: Read an input string from the user.
*/
char *read_input(char *prompt)
{
static char *input=NULL;
bool finish;
int length;
int c;
/*
* Perform some initializations. The finish boolean variable is used
* to detect a double line-feed, while length contains the number of
* characters in the input string.
libmegahal.c view on Meta::CPAN
length=0;
if(input==NULL) {
input=(char *)malloc(sizeof(char));
if(input==NULL) {
error("read_input", "Unable to allocate the input string");
return(input);
}
}
/*
* Display the prompt to the user.
*/
fprintf(stdout, prompt);
fflush(stdout);
/*
* Loop forever, reading characters and putting them into the input
* string.
*/
while(TRUE) {
/*
* Read a single character from stdin.
*/
c=getc(stdin);
/*
* If the character is a line-feed, then set the finish variable
* to TRUE. If it already is TRUE, then this is a double line-feed,
* in which case we should exit. After a line-feed, display the
* prompt again, and set the character to the space character, as
* we don't permit linefeeds to appear in the input.
*/
if((char)(c)=='\n') {
if(finish==TRUE) break;
fprintf(stdout, prompt);
fflush(stdout);
finish=TRUE;
c=32;
} else {
finish=FALSE;
}
/*
* Re-allocate the input string so that it can hold one more
* character.
#ifndef MEGAHAL_H
#define MEGAHAL_H
void megahal_setnoprompt ();
void megahal_setnowrap ();
void megahal_setnobanner ();
void megahal_seterrorfile(char *filename);
void megahal_setstatusfile(char *filename);
void megahal_initialize();
char* megahal_initial_greeting();
int megahal_command(char *input);
char* megahal_do_reply(char *input, int log);
void megahal_learn(char *input, int log);
void megahal_output(char *output);
char* megahal_input(char *prompt);
void megahal_cleanup();
#endif
( run in 1.711 second using v1.01-cache-2.11-cpan-6aa56a78535 )