| 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
| |||||||||||
| 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
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | my $doc_freq = $self->create_delayed_object('features'); | |||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | while (my $doc = $c->next) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | ▶ | $args{prog_bar}->() if $args{prog_bar}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | $doc_freq->add( $doc->features->as_boolean_hash ); | |||||||||
| 38 | } | ||||||||||
| 39 | 0 | ▶ | print "\n" if $self->verbose; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | return $self->reduce_features($doc_freq); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 6 | 1; | |||||||||
| 45 | |||||||||||
| 46 | __END__ | ||||||||||