File Coverage

blib/lib/AI/Categorizer/FeatureSelector/DocFrequency.pm
Criterion Covered Total %
statement 15 29 51.7
branch 0 8 0.0
condition n/a
subroutine 5 7 71.4
pod 1 2 50.0
total 21 46 45.6


line stmt bran cond sub pod time code
1             package AI::Categorizer::FeatureSelector::DocFrequency;
2              
3 6     6   6072 use strict;
  6         13  
  6         222  
4 6     6   3172 use AI::Categorizer::FeatureSelector;
  6         19  
  6         146  
5 6     6   31 use base qw(AI::Categorizer::FeatureSelector);
  6         11  
  6         387  
6              
7 6     6   29 use Params::Validate qw(:types);
  6         9  
  6         801  
8 6     6   26 use Carp qw(croak);
  6         8  
  6         1637  
9              
10             __PACKAGE__->contained_objects
11             (
12             features => { class => 'AI::Categorizer::FeatureVector',
13             delayed => 1 },
14             );
15              
16             # The KnowledgeSet keeps track of document frequency, so just use that.
17             sub rank_features {
18 0     0 0   my ($self, %args) = @_;
19            
20 0 0         my $k = $args{knowledge_set} or die "No knowledge_set parameter provided to rank_features()";
21            
22 0           my %freq_counts;
23 0           foreach my $name ($k->features->names) {
24 0           $freq_counts{$name} = $k->document_frequency($name);
25             }
26 0           return $self->create_delayed_object('features', features => \%freq_counts);
27             }
28              
29             sub scan_features {
30 0     0 1   my ($self, %args) = @_;
31 0 0         my $c = $args{collection} or die "No 'collection' parameter provided to scan_features()";
32              
33 0           my $doc_freq = $self->create_delayed_object('features');
34            
35 0           while (my $doc = $c->next) {
36 0 0         $args{prog_bar}->() if $args{prog_bar};
37 0           $doc_freq->add( $doc->features->as_boolean_hash );
38             }
39 0 0         print "\n" if $self->verbose;
40            
41 0           return $self->reduce_features($doc_freq);
42             }
43              
44             1;
45              
46             __END__