AI-MegaHAL

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

        'Test::More'      => '0.47',
    },
    $^O =~/win/i ? (
        dist => {
            TAR      => 'ptar',
            TARFLAGS => '-c -C -f',
        },
    ) : (),
);

sub WriteMakefile1 {  #Written by Alexandr Ciornii, version 0.21. Added by eumm-upgrade.
    my %params=@_;
    my $eumm_version=$ExtUtils::MakeMaker::VERSION;
    $eumm_version=eval $eumm_version;
    die "EXTRA_META is deprecated" if exists $params{EXTRA_META};
    die "License not specified" if not exists $params{LICENSE};
    if ($params{BUILD_REQUIRES} and $eumm_version < 6.5503) {
        #EUMM 6.5502 has problems with BUILD_REQUIRES
        $params{PREREQ_PM}={ %{$params{PREREQ_PM} || {}} , %{$params{BUILD_REQUIRES}} };
        delete $params{BUILD_REQUIRES};
    }

lib/AI/MegaHAL.pm  view on Meta::CPAN

	     megahal_command
	     megahal_do_reply
	     megahal_learn
	     megahal_output
	     megahal_input
	     megahal_cleanup);

@ISA = qw(Exporter DynaLoader);
$VERSION = '0.08';

sub AUTOLOAD {
    # This AUTOLOAD is used to 'autoload' constants from the constant()
    # XS function.  If a constant is not found then control is passed
    # to the AUTOLOAD in AutoLoader.

    my $constname;
    ($constname = $AUTOLOAD) =~ s/.*:://;
    croak "& not defined" if $constname eq 'constant';
    my $val = constant($constname, @_ ? $_[0] : 0);
    if ($! != 0) {
	if ($! =~ /Invalid/ || $!{EINVAL}) {

lib/AI/MegaHAL.pm  view on Meta::CPAN

	    goto &AutoLoader::AUTOLOAD;
	}
	else {
	    croak "Your vendor has not defined AI::MegaHAL macro $constname";
	}
    }
    {
	no strict 'refs';
	# Fixed between 5.005_53 and 5.005_61
	if ($] >= 5.00561) {
	    *$AUTOLOAD = sub () { $val };
	}
	else {
	    *$AUTOLOAD = sub { $val };
	}
    }
    goto &$AUTOLOAD;
}

sub new {
    my ($class,%args) = @_;
    my $self;

    # Bless ourselves into the AI::MegaHAL class.
    $self = bless({ },$class);

    # Make sure that we can find a brain or a training file somewhere
    # else die with an error.
    my $path = $args{'Path'} || ".";
    if(-e "$path/megahal.brn" || -e "$path/megahal.trn") {

lib/AI/MegaHAL.pm  view on Meta::CPAN

    # 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;
}

sub initial_greeting {
    my $self = shift;

    return megahal_initial_greeting();
}

sub do_reply {
    my ($self,$text) = @_;

    return megahal_do_reply($text,0);
}

sub learn {
    my ($self,$text) = @_;

    return megahal_learn($text,0);
}

sub _initialize {
    my $self = shift;

    megahal_initialize();
    return;
}

sub _cleanup {
    my $self = shift;

    megahal_cleanup();
    return;
}

sub DESTROY {
    my $self = shift;

    $self->_cleanup() if($self->{'AutoSave'});
    return;
}

bootstrap AI::MegaHAL $VERSION;
1;

__END__

libmegahal.c  view on Meta::CPAN

 *
 *		Purpose:		Update the statistics of the specified tree with the
 *						specified symbol, which may mean growing the tree if the
 *						symbol hasn't been seen in this context before.
 */
TREE *add_symbol(TREE *tree, BYTE2 symbol)
{
    TREE *node=NULL;

    /*
     *		Search for the symbol in the subtree of the tree node.
     */
    node=find_symbol_add(tree, symbol);

    /*
     *		Increment the symbol counts
     */
    if((node->count<65535)) {
	node->count+=1;
	tree->usage+=1;
    }

libmegahal.c  view on Meta::CPAN

 *						tree.
 */
TREE *find_symbol_add(TREE *node, int symbol)
{
    register int i;
    TREE *found=NULL;
    bool found_symbol=FALSE;

    /*
     *		Perform a binary search for the symbol.  If the symbol isn't found,
     *		attach a new sub-node to the tree node so that it remains sorted.
     */
    i=search_node(node, symbol, &found_symbol);
    if(found_symbol==TRUE) {
	found=node->tree[i];
    } else {
	found=new_node();
	found->symbol=symbol;
	add_node(node, found, i);
    }

    return(found);
}

/*---------------------------------------------------------------------------*/

/*
 *		Function:	Add_Node
 *
 *		Purpose:		Attach a new child node to the sub-tree of the tree
 *						specified.
 */
void add_node(TREE *tree, TREE *node, int position)
{
    register int i;

    /*
     *		Allocate room for one more child node, which may mean allocating
     *		the sub-tree from scratch.
     */
    if(tree->tree==NULL) {
	tree->tree=(TREE **)malloc(sizeof(TREE *)*(tree->branch+1));
    } else {
	tree->tree=(TREE **)realloc((TREE **)(tree->tree),sizeof(TREE *)*
				    (tree->branch+1));
    }
    if(tree->tree==NULL) {
	error("add_node", "Unable to reallocate subtree.");
	return;
    }

    /*
     *		Shuffle the nodes down so that we can insert the new node at the
     *		subtree index given by position.
     */
    for(i=tree->branch; i>position; --i)
	tree->tree[i]=tree->tree[i-1];

    /*
     *		Add the new node to the sub-tree.
     */
    tree->tree[position]=node;
    tree->branch+=1;
}

/*---------------------------------------------------------------------------*/

/*
 *		Function:	Search_Node
 *
 *		Purpose:		Perform a binary search for the specified symbol on the
 *						subtree of the given node.  Return the position of the
 *						child node in the subtree if the symbol was found, or the
 *						position where it should be inserted to keep the subtree
 *						sorted if it wasn't.
 */
int search_node(TREE *node, int symbol, bool *found_symbol)
{
    register int position;
    int min;
    int max;
    int middle;
    int compar;

    /*
     *		Handle the special case where the subtree is empty.
     */
    if(node->branch==0) {
	position=0;
	goto notfound;
    }

    /*
     *		Perform a binary search on the subtree.
     */
    min=0;
    max=node->branch-1;
    while(TRUE) {
	middle=(min+max)/2;
	compar=symbol-node->tree[middle]->symbol;
	if(compar==0) {
	    position=middle;
	    goto found;
	} else if(compar>0) {

libmegahal.c  view on Meta::CPAN


    fread(&(node->symbol), sizeof(BYTE2), 1, file);
    fread(&(node->usage), sizeof(BYTE4), 1, file);
    fread(&(node->count), sizeof(BYTE2), 1, file);
    fread(&(node->branch), sizeof(BYTE2), 1, file);

    if(node->branch==0) return;

    node->tree=(TREE **)malloc(sizeof(TREE *)*(node->branch));
    if(node->tree==NULL) {
	error("load_tree", "Unable to allocate subtree");
	return;
    }

    if(level==0) progress("Loading tree", 0, 1);
    for(i=0; i<node->branch; ++i) {
	node->tree[i]=new_node();
	++level;
	load_tree(file, node->tree[i]);
	--level;
	if(level==0) progress(NULL, i, node->branch);

megahal.trn  view on Meta::CPAN

Tell me something I don't know!
I wish I could believe you, I really do!
I've known that for a long time.
That's a fairly outrageous claim.
That's just a tad unbelievable.
Yeah, everyone knows that!
I wish I could tell you, but I must desist!
I hate avoiding questions, but I'm going to avoid that one!
Perhaps you could tell me?  On second thoughts, don't bother.
What is it with these silly questions?  Anyway, let's talk about something else...
What am I to you?  Some sort of encyclopaedia or something?  Let's change the subject...
Does it really matter?  Anyhow, let's chat about something interesting!
How boring!  Everybody and his dog asks me that!
You are soooo predictable it's not funny!
That is a universal mystery, methinks.
Please don't trouble me with such droll.
You are an bottomless pit of questions.
Let's talk about something vaguely interesting.
I guess that line of conversation is buggered, then!
If you want to keep your private life private, I understand.
Awww geez, I'm running out of things to talk about!

megahal.trn  view on Meta::CPAN

The cat is a carnivorous animal.
A chromosome is a chemical found in all cells which determines how the cell will act.
The cranium is the skeleton enclosing the brain.
The dingo is wild dog found in Australia.
The dinosaurs were a family of reptiles which lived on the earth millions of years ago.
A dog is a domesticated mammal descended from the wolf.
Donkey is another name for ass.
Ecology is a study of the relationship between an organism and its environment.
The emu is a large, ostrich-like flightless bird found in Australia.
Eucalyptus is a tree native to Australia where it is called the gum tree.
Excretion is the process of getting rid of unwanted substances from within the body.
Genes are hereditary information material arranged in a single row along the length of each chromosome.
Gum tree is another name for Eucalyptus.
A herbivore is an animal that eats plants.
The kangaroo is a marsupial mammal found in Australia.
The kiwi is a group of three species of bird only found in New Zealand.
The koala is a marsupial found only in east Australia.
Locomotion is the idea of movement from one place to another.
Milk is a secretion of modified skin glands of female mammals.
A monkey is a small, usually tree dwelling, primate.
The mule is a hybrid animal, the result of an ass and a mare breeding.
A neurone is a cell which receives and transmits electrical impulses.
Nutrition is the process of taking in food and obtaining energy and vital substances from it.
An omnivore is an animal that eats both plant and animal matter.
A plant is a living organism which does not have the ability to move, and does not have sensory organs or digestive organs.
The platypus is found in Australia.
Protoplasm is the basic living substance of all animals.
The wombat is a nocturnal marsupial.
#
#	Encyclopaedic information:	Other
#
Abstract means theoretical rather than practical.
An accent is a local mode of pronunciation in speech.
An accordion is a small portable musical instrument with a keyboard and bellows.
An acid is a chemical compound that reacts with metals to form salts by releasing hydrogen.
An acronym is a word formed from the initials of other words.
An adhesive is a sticky substance.
An adult is a fully grown being.
An aircraft is a flying machine, a vessel which flies through the air rather than floats on water or travels along a road or rail.
Ale is an alcoholic drink made from malt and hops.
An algorithm is a set of rules.
An alphabet is an ordered series of letters used in language.
An atom is the smallest quantity of a chemical element which can enter into combination or take part in a chemical reaction.
Beer is a drink of fermented hops, malt and barley.
A bicycle is a two wheeled vehicle.
Cement is a mixture of chalk and clay used for building.
Chocolate is a confectionery made from cocoa beans.
A coma is a state of deep unconsciousness.
A compiler is a computer program that translates high level language code into machine language code.
A computer is a programmable electronic device.
Cooking is the art of preparing food for the table by subjecting it to heat in various ways.
Cosmology is the study of the structure of the universe.
The cymbal is a suspended brass disk which is struck with a stick.
Dance is a rhythmic movement of the body usually performed to music.
Data is information, especially that stored in a computer.
A day is the time taken for the earth to rotate once on its axis.
The earth is the third planet from the sun.
A galaxy is a congregation of stars held together by gravity.
Gravity is the force of attraction between two objects resulting from their mass.
A house is a building for human habitation.
Knowledge is practical understanding.



( run in 0.413 second using v1.01-cache-2.11-cpan-88abd93f124 )