Categorizer/Hypothesis.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 7 / 7 totaltotal 95.5% 65 / 68 CC 6 SCAR 7.0
CC
6
Cov
94%
best_category
4.0
categories
2.0
in_category
2.0
CRAP 2.0
« Categorizer/Experiment.pm ↑ Summary Categorizer/Document/SMART.pm »
1 package AI::Categorizer::Hypothesis;
2  
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 12 ▶use Class::Container;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use base qw(Class::Container);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use Params::Validate qw(:types);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 12 __PACKAGE__->valid_params
10 (
11 all_categories => {type => ARRAYREF},
12 scores => {type => HASHREF},
13 threshold => {type => SCALAR},
14 document_name => {type => SCALAR, optional => 1},
15 );
16  
17 10 ▶sub all_categories { @{$_[0]->{all_categories}} }
Subroutine all_categories: called CC=1 SCAR=0.0
Pod documented
18 20 ▶sub document_name { $_[0]->{document_name} }
Subroutine document_name: called CC=1 SCAR=0.0
Pod documented
19 40 ▶sub threshold { $_[0]->{threshold} }
Subroutine threshold: called CC=1 SCAR=0.0
Pod documented
20  
21 22 ▶sub best_category {
Subroutine best_category: called CC=4 SCAR=13.9
Pod documented
22 22 my ($self) = @_;
23 22 my $sc = $self->{scores};
24 22 ▶ return unless %$sc;
Branch: 1 branch
BranchTrueFalseTotal
unless %$sc 0 22 22
25  
26 22 my ($best_cat, $best_score) = each %$sc;
27 22 ▶ while (my ($key, $val) = each %$sc) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$sc) 46 22 68
28 46 ▶ ($best_cat, $best_score) = ($key, $val) if $val > $best_score;
Branch: 1 branch
BranchTrueFalseTotal
if $val > $best_score 14 32 46
29 }
30 22 return $best_cat;
31 }
32  
33 44 ▶sub in_category {
Subroutine in_category: called CC=2 SCAR=6.9
Pod documented
34 44 my ($self, $cat) = @_;
35 44 ▶ return '' unless exists $self->{scores}{$cat};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"scores"}{$cat} 1 43 44
36 43 return $self->{scores}{$cat} > $self->{threshold};
37 }
38  
39 41 ▶sub categories {
Subroutine categories: called CC=2 SCAR=7.1
Pod documented
40 41 my $self = shift;
41 0 ▶ return @{$self->{cats}} if $self->{cats};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cats"} 0 41 41
42 4 $self->{cats} = [sort {$self->{scores}{$b} <=> $self->{scores}{$a}}
43 106 grep {$self->{scores}{$_} >= $self->{threshold}}
44 41 keys %{$self->{scores}}];
45 41 return @{$self->{cats}};
46 }
47  
48 40 ▶sub scores {
Subroutine scores: called CC=1 SCAR=0.0
Pod documented
49 40 my $self = shift;
50 40 return @{$self->{scores}}{@_};
51 }
52  
53 12 1;
54  
55 __END__
« Categorizer/Experiment.pm ↑ Summary Categorizer/Document/SMART.pm »