NAME
OurNet::ChatBot - Context-free interactive Q&A engine
SYNOPSIS
use OurNet::ChatBot;
my $bot = eval { OurNet::ChatBot->new('fianjmo', 'fianjmo.db') };
if ($@ or !$bot->{db}{idxcount}) {
die "No database found. you must build it with 'make test'.\n";
}
while (1) {
print '['.($ENV{USER} || 'user').'] ';
print '<fianjmo> '.($bot->input(scalar <STDIN>) || '...')."\n";
}
DESCRIPTION
The OurNet::ChatBot module simulates a general-purpose, context-free, interactive chatter-bot using the OurNet::FuzzyIndex engine. It reads the file stored in a ChatBot/ directory, parses synonyms and random output settings, then return answers via the input()
method.
This module require no reformatting of existing contents at all; it can automatically parse paragraphs and sentences, then convert the weighted data into a OurNet::FuzzyIndex database. You can also specify additional parameters like keywords, weights and grammar at any time.
The lastone property is used to return/set the id of the bot's last sentence. In conjunction of directly manipulating the CHUNKS array (which contains all possible return values for input()
), the front-end program could prevent duplicate responses.
CAVEATS
The nextone flag-property is implemented badly. It's supposed to tweak the behaviour so it allows a more sequencial follow-up to a training material based on real dialogs. See the __DATA__
section in Makefile.PL for an example.
METHODS
OurNet::ChatBot->new($botname, $bot, [$writable])
Constructor method; reads bot name, bot database file, and writable flag as arguments. Returns a OurNet::ChatBot object.
$self->addsyn($skey, @syns)
Inserts new synonyms of the word $skey
into the bot database.
$self->addentry($content, [$trigger])
Inserts a response sentence to the ChatBot's corpus. The optional $trigger
variable indicates a cue sentence to be used as index instead of $content
; this is useful in a Q & A context.
$self->sync()
Writes back to the database file.
$self->input($say, [@avoid])
Process the query sentence in $say
, and returns the chat-bot's response. The chunk IDs specified in @avoid
will not be used.
$self->convert($data)
Converts the legacy database in Chatbot::Amber format to a database file. This function is obsoleted, unsupported, and will probably go away at some point in favor of some XML or YAML-based format.
SEE ALSO
AUTHORS
Autrijus Tang <autrijus@autrijus.org>
COPYRIGHT
Copyright 2001, 2003 by Autrijus Tang <autrijus@autrijus.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.