view release on metacpan or search on metacpan
$build->create_build_script;
{
my $path = $build->prompt
(
"\nIf you have the Weka system installed, please specify the path\n".
"to the 'weka.jar' file, or '-' to search CLASSPATH, or '!' to skip:",
'!'
);
$build->notes(classpath => $path eq '!' ? undef : $path);
}
lib/AI/Categorizer/Collection/DBI.pm view on Meta::CPAN
use strict;
use DBI;
use AI::Categorizer::Collection;
use base qw(AI::Categorizer::Collection);
use Params::Validate qw(:types);
__PACKAGE__->valid_params
(
connection_string => {type => SCALAR, default => undef},
dbh => {isa => 'DBI::db', default => undef},
select_statement => {type => SCALAR, default => "SELECT text FROM documents"},
);
__PACKAGE__->contained_objects
(
document => { class => 'AI::Categorizer::Document',
delayed => 1 },
);
sub new {
lib/AI/Categorizer/Collection/DBI.pm view on Meta::CPAN
$self->{sth}->finish;
}
$self->{sth}->execute;
}
sub next {
my $self = shift;
my @result = $self->{sth}->fetchrow_array;
return undef unless @result;
return $self->create_delayed_object('document',
name => $result[0],
categories => [$result[1]],
content => $result[2],
);
}
1;
lib/AI/Categorizer/Collection/Files.pm view on Meta::CPAN
categories => \@cats,
);
}
sub _read_file {
my ($self) = @_;
my $file = readdir $self->{dir_fh};
if (!defined $file) { # Directory has been exhausted
return undef unless @{$self->{path}};
$self->_next_path;
return $self->_read_file;
} elsif ($file eq '.' or $file eq '..') {
return $self->_read_file;
} elsif (-d (my $path = File::Spec->catdir($self->{cur_dir}, $file))) {
push @{$self->{path}}, $path # Add for later processing
if $self->{recurse} and !grep {$_ eq $path} @{$self->{path}}, @{$self->{used}};
return $self->_read_file;
}
return $file;
lib/AI/Categorizer/Collection/SingleFile.pm view on Meta::CPAN
use strict;
use AI::Categorizer::Collection;
use base qw(AI::Categorizer::Collection);
use Params::Validate qw(:types);
__PACKAGE__->valid_params
(
path => { type => SCALAR|ARRAYREF },
categories => { type => HASHREF|UNDEF, default => undef },
delimiter => { type => SCALAR },
);
__PACKAGE__->contained_objects
(
document => { class => 'AI::Categorizer::Document::Text',
delayed => 1 },
);
sub new {
lib/AI/Categorizer/Collection/SingleFile.pm view on Meta::CPAN
}
sub next {
my $self = shift;
my $fh = $self->{fh}; # Must put in a simple scalar
my $content = do {local $/ = $self->{delimiter}; <$fh>};
if (!defined $content) { # File has been exhausted
unless (@{$self->{path}}) { # All files have been exhausted
$self->{fh} = undef;
return undef;
}
$self->_next_path;
return $self->next;
} elsif ($content =~ /^\s*$self->{delimiter}$/) { # Skip empty docs
return $self->next;
}
#warn "doc is $content";
#warn "creating document=>@{[ %{$self->{container}{delayed}{document}} ]}";
return $self->create_delayed_object('document', content => $content);
lib/AI/Categorizer/Document.pm view on Meta::CPAN
sub { ! grep !UNIVERSAL::isa($_, 'AI::Categorizer::Category'), @{$_[0]} },
},
public => 0,
},
stopwords => {
type => ARRAYREF|HASHREF,
default => {},
},
content => {
type => HASHREF|SCALAR,
default => undef,
},
parse => {
type => SCALAR,
optional => 1,
},
parse_handle => {
type => HANDLE,
optional => 1,
},
features => {
lib/AI/Categorizer/Document.pm view on Meta::CPAN
content_weights => {
type => HASHREF,
default => {},
},
front_bias => {
type => SCALAR,
default => 0,
},
use_features => {
type => HASHREF|UNDEF,
default => undef,
},
stemming => {
type => SCALAR|UNDEF,
optional => 1,
},
stopword_behavior => {
type => SCALAR,
default => "stem",
},
);
lib/AI/Categorizer/FeatureSelector.pm view on Meta::CPAN
KnowledgeSet. In a scalar context returns the number of such objects.
=item documents()
In a list context returns a list of all Document objects in this
KnowledgeSet. In a scalar context returns the number of such objects.
=item document()
Given a document name, returns the Document object with that name, or
C<undef> if no such Document object exists in this KnowledgeSet.
=item features()
Returns a FeatureSet object which represents the features of all the
documents in this KnowledgeSet.
=item verbose()
Returns the C<verbose> parameter of this KnowledgeSet, or sets it with
an optional argument.
lib/AI/Categorizer/Hypothesis.pm view on Meta::CPAN
different categorization tasks either.
=item all_categories()
Returns the list of category names specified with the
C<all_categories> constructor parameter.
=item document_name()
Returns the value of the C<document_name> parameter specified as a
constructor parameter, or C<undef> if none was specified.
=back
=head1 AUTHOR
Ken Williams <ken@mathforum.org>
=head1 COPYRIGHT
This distribution is free software; you can redistribute it and/or
lib/AI/Categorizer/KnowledgeSet.pm view on Meta::CPAN
KnowledgeSet. In a scalar context returns the number of such objects.
=item documents()
In a list context returns a list of all Document objects in this
KnowledgeSet. In a scalar context returns the number of such objects.
=item document()
Given a document name, returns the Document object with that name, or
C<undef> if no such Document object exists in this KnowledgeSet.
=item features()
Returns a FeatureSet object which represents the features of all the
documents in this KnowledgeSet.
=item verbose()
Returns the C<verbose> parameter of this KnowledgeSet, or sets it with
an optional argument.
lib/AI/Categorizer/Learner/Rocchio.pm view on Meta::CPAN
negative_setting => {type => SCALAR, default => 4 },
threshold => {type => SCALAR, default => 0.1},
);
sub create_model {
my $self = shift;
foreach my $doc ($self->knowledge_set->documents) {
$doc->features->normalize;
}
$self->{model}{all_features} = $self->knowledge_set->features(undef);
$self->SUPER::create_model(@_);
delete $self->{knowledge_set};
}
sub create_boolean_model {
my ($self, $positives, $negatives, $cat) = @_;
my $posdocnum = @$positives;
my $negdocnum = @$negatives;
my $beta = $self->{positive_setting};
my $gamma = $self->{negative_setting};
my $profile = $self->{model}{all_features}->clone->scale(-$gamma/$negdocnum);
my $f = $cat->features(undef)->clone->scale( $beta/$posdocnum + $gamma/$negdocnum );
$profile->add($f);
return $profile->normalize;
}
sub get_boolean_score {
my ($self, $newdoc, $profile) = @_;
return $newdoc->features->normalize->dot($profile);
}
lib/AI/Categorizer/Util.pm view on Meta::CPAN
if ( $arr->[$cur] < $target ) {
$low = $cur + 1;
} else {
$high = $cur;
}
}
return $low;
}
sub max {
return undef unless @_;
my $max = shift;
foreach (@_) {
$max = $_ if $_ > $max;
}
return $max;
}
sub min {
return undef unless @_;
my $min = shift;
foreach (@_) {
$min = $_ if $_ > $min;
}
return $min;
}
sub average {
return undef unless @_;
my $total;
$total += $_ foreach @_;
return $total/@_;
}
sub intersection {
my ($one, $two) = @_;
$two = _hashify($two);
return UNIVERSAL::isa($one, 'HASH') ? # Accept hash or array for $one
t/13-document.t view on Meta::CPAN
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'), '';
}