Categorizer/FeatureSelector/DocFrequency.pm

filter: Statementstmt 54.8% 17 / 31 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 50.0% 1 / 2 totaltotal 46.0% 23 / 50 CC 7 SCAR 26.9
CC
7
Cov
41%
scan_features
30.0
rank_features
12.0
BEGIN
1.0
CRAP 14.7
« Categorizer/FeatureSelector.pm ↑ Summary Categorizer/Learner/Weka.pm »
1 package AI::Categorizer::FeatureSelector::DocFrequency;
2  
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use AI::Categorizer::FeatureSelector;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use base qw(AI::Categorizer::FeatureSelector);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use Params::Validate qw(:types);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 6 __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 0 ▶sub rank_features {
Subroutine rank_features: not called CC=3 SCAR=24.8
Pod undocumented
18 0 my ($self, %args) = @_;
19
20 0 ▶ my $k = $args{knowledge_set} or die "No knowledge_set parameter provided to rank_features()";
Branch: 1 branch
BranchTrueFalseTotal
my $k = $args{"knowledge_set"} or die "No knowledge_set parameter provided to rank_features()" 0 0 0
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 0 ▶sub scan_features {
Subroutine scan_features: not called CC=5 SCAR=34.0
Pod documented
30 0 my ($self, %args) = @_;
31 0 ▶ my $c = $args{collection} or die "No 'collection' parameter provided to scan_features()";
Branch: 1 branch
BranchTrueFalseTotal
my $c = $args{"collection"} or die "No 'collection' parameter provided to scan_features()" 0 0 0
32  
33 0 my $doc_freq = $self->create_delayed_object('features');
34
35 0 ▶ while (my $doc = $c->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $doc = $c->next) 0 0 0
36 0 ▶ $args{prog_bar}->() if $args{prog_bar};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"prog_bar"} 0 0 0
37 0 $doc_freq->add( $doc->features->as_boolean_hash );
38 }
39 0 ▶ print "\n" if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
40
41 0 return $self->reduce_features($doc_freq);
42 }
43  
44 6 1;
45  
46 __END__
« Categorizer/FeatureSelector.pm ↑ Summary Categorizer/Learner/Weka.pm »