| 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
| |||||||||||
| 25 | |||||||||||
| 26 | 22 | my ($best_cat, $best_score) = each %$sc; | |||||||||
| 27 | 22 | ▶ | while (my ($key, $val) = each %$sc) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 46 | ▶ | ($best_cat, $best_score) = ($key, $val) if $val > $best_score; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||