File Coverage

blib/lib/AI/Categorizer/Learner/Guesser.pm
Criterion Covered Total %
statement 15 21 71.4
branch 1 2 50.0
condition n/a
subroutine 4 5 80.0
pod 0 2 0.0
total 20 30 66.6


line stmt bran cond sub pod time code
1             package AI::Categorizer::Learner::Guesser;
2              
3 1     1   1554 use strict;
  1         3  
  1         28  
4 1     1   5 use AI::Categorizer::Learner;
  1         2  
  1         21  
5 1     1   5 use base qw(AI::Categorizer::Learner);
  1         2  
  1         218  
6              
7             sub create_model {
8 1     1 0 2 my $self = shift;
9 1         10 my $k = $self->knowledge_set;
10 1         6 my $num_docs = $k->documents;
11            
12 1         4 foreach my $cat ($k->categories) {
13 2 50       7 next unless $cat->documents;
14 2         6 $self->{model}{$cat->name} = $cat->documents / $num_docs;
15             }
16             }
17              
18             sub get_scores {
19 0     0 0   my ($self, $newdoc) = @_;
20            
21 0           my %scores;
22 0           while (my ($cat, $prob) = each %{$self->{model}}) {
  0            
23 0           $scores{$cat} = 0.5 + $prob - rand();
24             }
25            
26 0           return (\%scores, 0.5);
27             }
28              
29             1;
30              
31             __END__