AI-Categorizer

 view release on metacpan or  search on metacpan

t/01-naive_bayes.t  view on Meta::CPAN

#!/usr/bin/perl -w

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
BEGIN { 
  require 't/common.pl';
  need_module('Algorithm::NaiveBayes');
  plan tests => 15 + num_standard_tests();
}

ok(1);

#########################

t/02-experiment.t  view on Meta::CPAN

#!/usr/bin/perl -w

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
BEGIN { plan tests => 14 };

use AI::Categorizer;
use AI::Categorizer::Experiment;

ok(1);

my $all_categories = [qw(sports politics finance world)];

{

t/03-weka.t  view on Meta::CPAN

#!/usr/bin/perl -w

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
use Module::Build;

my $classpath = Module::Build->current->notes('classpath');

require 't/common.pl';
skip_test("Weka is not installed") unless defined $classpath;

plan tests => 1 + num_standard_tests();


t/04-decision_tree.t  view on Meta::CPAN

#!/usr/bin/perl -w

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
BEGIN {
  require 't/common.pl';
  need_module('AI::DecisionTree 0.06');
  plan tests => 1 + num_standard_tests();
}

ok(1);

#########################

t/05-svm.t  view on Meta::CPAN

#!/usr/bin/perl -w

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
BEGIN {
  require 't/common.pl';
  need_module('Algorithm::SVM');
  plan tests => 1 + num_standard_tests();
}

ok(1);

#########################

t/06-knn.t  view on Meta::CPAN

#!/usr/bin/perl -w

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
BEGIN {
  require 't/common.pl';
  plan tests => 5 + 2 * num_standard_tests();
}

ok(1);

#########################

# There are only 4 test documents, so use k=2

t/07-guesser.t  view on Meta::CPAN

#!/usr/bin/perl -w

#########################

use strict;
use Test;
BEGIN {
  require 't/common.pl';
  plan tests => 1 + num_setup_tests();
}

ok(1);

#########################

my ($learner, $docs) = set_up_tests(learner_class => 'AI::Categorizer::Learner::Guesser');

t/09-rocchio.t  view on Meta::CPAN

#!/usr/bin/perl -w

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
BEGIN {
  require 't/common.pl';
  plan tests => 1 + num_standard_tests();
}

ok(1);

#########################

perform_standard_tests(learner_class => 'AI::Categorizer::Learner::Rocchio');

t/10-tools.t  view on Meta::CPAN

#!/usr/bin/perl -w

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
BEGIN { 
  plan tests => 10;
};

use AI::Categorizer::Util qw(random_elements binary_search);
ok(1);

# Test random_elements()
my @x = ('a'..'j');
my @y = random_elements(\@x, 3);
ok @y, 3;
ok $y[0] =~ /^[a-j]$/;

@y = random_elements(\@x, 7);
ok @y, 7;
ok $y[0] =~ /^[a-j]$/;

# Test binary_search()
@x = (0,1,2,3,4,6,7,8);
ok binary_search(\@x,  5), 5;
ok binary_search(\@x, -1), 0;
ok binary_search(\@x,  9), 8;

@x = ();
ok binary_search(\@x,  1), 0;
ok binary_search(\@x, -1), 0;

t/11-feature_vector.t  view on Meta::CPAN

#!/usr/bin/perl -w

# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'

#########################

use strict;
use Test;
BEGIN { 
  plan tests => 18;
}

use AI::Categorizer::FeatureVector;
ok(1);

my $f1 = new AI::Categorizer::FeatureVector(features => {sports => 2, finance => 3});
ok $f1;
ok $f1->includes('sports');

t/12-hypothesis.t  view on Meta::CPAN

#!/usr/bin/perl -w

use strict;
use Test;
BEGIN { 
  plan tests => 8;
};

use AI::Categorizer::Hypothesis;
ok(1);

my @cats = ('a'..'z', 'foo', 'bar');

my $h = new AI::Categorizer::Hypothesis

t/13-document.t  view on Meta::CPAN

#!/usr/bin/perl -w

use strict;
use Test;
BEGIN { plan tests => 27, todo => [] };

use AI::Categorizer;
use AI::Categorizer::Document;
use AI::Categorizer::FeatureVector;

ok(1);
my $docclass = 'AI::Categorizer::Document';

# Test empty document creation
{
  my $d = $docclass->new;
  ok ref($d), $docclass, "Basic empty document creation";
  ok $d->features, undef;
}

# Test basic document creation
{
  my $d = $docclass->new(content => "Hello world");
  ok ref($d), $docclass, "Basic document creation with 'content' parameter";
  ok $d->features->includes('hello'), 1;
  ok $d->features->includes('world'), 1;
  ok $d->features->includes('foo'),  '';
}

# Test document creation with 'parse'
{
  require AI::Categorizer::Document::Text;
  my $d = AI::Categorizer::Document::Text->new( parse => "Hello world" );
  ok ref($d), 'AI::Categorizer::Document::Text', "Document creation with 'parse' parameter";
  ok $d->features->includes('hello'), 1;
  ok $d->features->includes('world'), 1;
  ok $d->features->includes('foo'),  '';
}

# Test document creation with 'features'
{
  my $d = $docclass->new(features => AI::Categorizer::FeatureVector->new(features => {one => 1, two => 2}));
  ok ref($d), $docclass, "Document creation with 'features' parameter";
  ok $d->features->value('one'), 1;
  ok $d->features->value('two'), 2;
  ok $d->features->includes('foo'), '';
}
  

# Test some stemming & stopword stuff.
{
  my $d = $docclass->new
    (
     name => 'test',
     stopwords => ['stemmed'],
     stemming => 'porter',
     content  => 'stopword processing should happen after stemming',
     # Becomes qw(stopword process    should happen after stem    )
    );
  ok $d->stopword_behavior, 'stem', "stopword_behavior() is 'stem'";

t/14-collection.t  view on Meta::CPAN

#!/usr/bin/perl -w

use strict;
use Test;
BEGIN { plan tests => 13 };

use AI::Categorizer;
use File::Spec;
require File::Spec->catfile('t', 'common.pl');

ok 1;  # Loaded

# Test InMemory collection
use AI::Categorizer::Collection::InMemory;
my $c = AI::Categorizer::Collection::InMemory->new(data => {training_docs()});
ok $c;
exercise_collection($c, 4);

# Test Files collection
use AI::Categorizer::Collection::Files;
$c = AI::Categorizer::Collection::Files->new(path => File::Spec->catdir('t', 'traindocs'),
					     category_hash => {
							       doc1 => ['farming'],
							       doc2 => ['farming'],
							       doc3 => ['vampire'],
							       doc4 => ['vampire'],
							      },
					    );
ok $c;

t/15-knowledge_set.t  view on Meta::CPAN

#!/usr/bin/perl -w

use strict;
use Test;
BEGIN { plan tests => 5 };

use AI::Categorizer;
ok 1; # Loaded

my $k = AI::Categorizer::KnowledgeSet->new();
ok $k;

my $c1 = AI::Categorizer::Category->by_name(name => 'one');
my $c2 = AI::Categorizer::Category->by_name(name => 'two');

t/common.pl  view on Meta::CPAN


use strict;
use Test;
use AI::Categorizer;
use AI::Categorizer::KnowledgeSet;
use AI::Categorizer::Collection::InMemory;

sub have_module {
  my $module = shift;
  return eval "use $module; 1";
}

sub need_module {

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.449 second using v1.00-cache-2.02-grep-82fe00e-cpan-585fae043c8 )