Skip to content

operasoftware/AI-Classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SYNOPSIS

my $cl = AI::Classifier::Text->new(
  training_data => [
       {  
           attributes => _hash(qw(sheep very valuable farming)),
           labels => ['farming']
       },
       {  
           attributes => _hash(qw(farming requires many kinds animals)),
           labels => ['farming']
       },
       {  
           attributes => _hash(qw(vampires drink blood vampires may staked)),
           labels => ['vampire']
       },
);
# the above creates a default AI::NaiveBayes classifier and feeds it the training data

my $res = $cl->classify("I would like to begin farming sheep" );

$res    = $cl->classify("I would like to begin farming sheep", { new_user => 1 });

print $res->best_category; 
$cl->store('some-file');
# later
my $cl = AI::Classifier::Text->load('some-file');
my $res = $cl->classify("do cats eat sheep?");

DESCRIPTION

AI::Classifier::Text combines a lexical analyzer (by default being AI::Classifier::Text::Analyzer) and a compatible classifier to perform text classification.

The constructor requires either a compatible trained classifier (like AI::NaiveBayes) - or training_data parameter with a list of training examples. In that later case it creates the default AI::NaiveBayes classifier and traubs it before constructing the AI::Classifier::Text object.

If your training data does not feet into the computer memory, or you want a different classifier to use - than train the classifier first and then pass it to the AI::Classifier::Text constructor.

This is partially based on AI::TextCategorizer.

ATTRIBUTES

classifier

An object that'll perform classification of supplied feature vectors. Has to define a classify() method, which accepts a hash refence. The return value of AI::Classifier::Text->classify() will be the return value of classifier's classify() method.

This attribute has to be supplied to the new() method during object creation.

analyzer

The class performing lexical analysis of the text in order to produce a feature vector. This defaults to AI::Classifier::Text::Analyzer.

METHODS

new(classifier => $foo)

Creates a new AI::Classifier::Text object. It requires either the classifier or the training data passed to it.

classify($document, $features)

Categorize the given document. A lexical analyzer will be used to extract features from $document, and in addition to that the features from $features hash reference will be added. The return value comes directly from the classifier object's classify method.

SEE ALSO

AI::NaiveBayes (3), AI::Categorizer(3)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages