docfrequency.pm

来自「AI::Categorizer is a framework for autom」· PM 代码 · 共 71 行

PM
71
字号
package AI::Categorizer::FeatureSelector::DocFrequency;use strict;use AI::Categorizer::FeatureSelector;use base qw(AI::Categorizer::FeatureSelector);use Params::Validate qw(:types);use Carp qw(croak);__PACKAGE__->contained_objects  (   features => { class => 'AI::Categorizer::FeatureVector',		 delayed => 1 },  );# The KnowledgeSet keeps track of document frequency, so just use that.sub rank_features {  my ($self, %args) = @_;    my $k = $args{knowledge_set} or die "No knowledge_set parameter provided to rank_features()";    my %freq_counts;  foreach my $name ($k->features->names) {    $freq_counts{$name} = $k->document_frequency($name);  }  return $self->create_delayed_object('features', features => \%freq_counts);}sub scan_features {  my ($self, %args) = @_;  my $c = $args{collection} or die "No 'collection' parameter provided to scan_features()";  my $doc_freq = $self->create_delayed_object('features');    while (my $doc = $c->next) {    $args{prog_bar}->() if $args{prog_bar};    $doc_freq->add( $doc->features->as_boolean_hash );  }  print "\n" if $self->verbose;    return $self->reduce_features($doc_freq);}1;__END__=head1 NAMEAI::Categorizer::FeatureSelector - Abstract Feature Selection class=head1 SYNOPSIS ...=head1 DESCRIPTIONThe KnowledgeSet class that provides an interface to a set ofdocuments, a set of categories, and a mapping between the two.  Manyparameters for controlling the processing of documents are managed bythe KnowledgeSet class.=head1 METHODS=over 4=item new()Creates a new KnowledgeSet and returns it.  Accepts the followingparameters:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?