Branch Coverage

blib/lib/Algorithm/Classifier/NaiveBayes.pm
Criterion Covered Total %
branch 187 194 96.3


line true false branch
167 1 46 unless (defined $known_args{$arg})
172 1 77 if (defined $args{'lc_tokens'} and ref $args{'lc_tokens'} ne "")
177 11 141 if (defined $args{$regex_arg})
179 1 10 if ($ref ne "" and $ref ne "Regexp")
182 1 9 if ($args{$regex_arg} eq "")
186 2 7 unless (defined $compiled)
192 8 65 defined $args{'smoothing'} ? :
193 1 72 if ($smoothing ne "laplace" and $smoothing ne "lidstone")
197 7 65 if (defined $args{'alpha'}) { }
198 1 6 if ($smoothing eq "laplace")
201 2 4 if (ref $args{'alpha'} ne "" or not $args{'alpha'} =~ /\A\d*\.?\d+\z/ or $args{'alpha'} <= 0)
206 1 64 $smoothing eq 'lidstone' ? :
209 7 62 defined $args{'ngrams'} ? :
210 3 66 if (ref $ngrams ne "" or not $ngrams =~ /\A\d+\z/ or $ngrams < 1)
214 5 61 defined $args{'token_weighting'} ? :
215 1 65 if ($token_weighting ne "count" and $token_weighting ne "binary")
219 4 61 defined $args{'priors'} ? :
220 1 64 if ($priors ne "trained" and $priors ne "uniform")
240 2 62 defined $args{'lc_tokens'} ? :
2 62 defined $args{'token_splitter'} ? :
281 2 96 unless (defined $text)
289 2 269 if ($token eq "")
292 266 3 if ($self->{'model'}{'lc_tokens'})
296 15 254 if (defined $self->{'model'}{'stop_regex'})
298 7 8 if ($token =~ /\A(?:$stop_regex)\z/)
302 262 7 if ($add_token)
308 4 92 if (defined $self->{'model'}{'ngrams'} and $self->{'model'}{'ngrams'} > 1)
340 1 51 if (not defined $class) { }
1 50 elsif (not defined $text) { }
348 37 13 unless (defined $self->{'model'}{'token_counts'}{$class})
351 37 13 unless (defined $self->{'model'}{'class_totals'}{$class})
365 6 43 if (defined $self->{'model'}{'priors'} and $self->{'model'}{'priors'} eq "uniform")
378 7 78 if (defined $self->{'model'}{'token_weighting'} and $self->{'model'}{'token_weighting'} eq "binary")
413 1 11 if (not defined $class) { }
1 10 elsif (not defined $text) { }
419 2 8 if (not defined $self->{'model'}{'class_counts'}{$class} or $self->{'model'}{'class_counts'}{$class} < 1)
429 25 4 if (defined $self->{'model'}{'token_counts'}{$class}{$word})
432 20 5 if ($self->{'model'}{'token_counts'}{$class}{$word} < 1)
438 5 3 if ($self->{'model'}{'class_counts'}{$class} < 1)
480 1 6 unless (defined $min_count)
483 2 4 if (ref $min_count ne "" or not $min_count =~ /\A\d+\z/ or $min_count < 1)
497 13 8 if ($totals{$token} < $min_count)
500 14 12 if (defined $self->{'model'}{'token_counts'}{$class}{$token})
546 1 6 if (not defined $class) { }
2 4 elsif (not defined $self->{'model'}{'token_counts'}{$class}) { }
598 3 23 if ($self->{'model'}{'total_docs'} < 1)
599 1 2 wantarray ? :
604 23 0 defined $self->{'model'}{'alpha'} ? :
611 39 2 if ($total + $alpha * $token_size > 0)
620 0 13 unless $scores{$b} <=> $scores{$a}
622 10 13 unless (wantarray)
692 1 5 unless (defined $text)
696 1 4 if ($self->{'model'}{'total_docs'} < 1)
702 4 0 defined $self->{'model'}{'alpha'} ? :
718 8 0 if ($denom > 0)
730 0 4 unless $scores{$b} <=> $scores{$a}
795 2 30 unless (defined $known_args{$arg})
799 2 16 unless (grep {defined $args{$_};} keys %args)
804 10 6 defined $args{'smoothing'} ? :
805 0 16 unless (defined $smoothing)
808 2 14 if ($smoothing ne "laplace" and $smoothing ne "lidstone")
812 7 7 if (defined $args{'alpha'})
813 1 6 if ($smoothing eq "laplace")
816 2 4 if (ref $args{'alpha'} ne "" or not $args{'alpha'} =~ /\A\d*\.?\d+\z/ or $args{'alpha'} <= 0)
821 1 4 if (defined $args{'priors'} and $args{'priors'} ne "trained" and $args{'priors'} ne "uniform")
826 6 4 if (defined $args{'smoothing'})
828 1 5 if ($args{'smoothing'} eq "laplace")
833 4 6 if (defined $args{'alpha'})
836 4 6 if (defined $args{'priors'})
863 1 25 if (ref $model{$regex_item} eq "Regexp")
891 1 46 unless (defined $raw)
896 2 44 unless (defined $model)
900 1 43 if (ref $model ne "HASH")
903 2 41 if (not defined $model->{'format'} or $model->{'format'} ne __PACKAGE__)
906 1 40 unless (defined $model->{'version'} and $model->{'version'} =~ /^\d+$/)
909 1 39 if ($model->{'version'} > $MODEL_VERSION)
916 1 152 if (ref $model->{$hash_item} ne "HASH")
920 1 37 unless (defined $model->{'total_docs'} and $model->{'total_docs'} =~ /\A\d+\z/)
923 1 36 if (not defined $model->{'token_splitter'} or $model->{'token_splitter'} eq "")
927 1 70 if (defined $model->{$regex_item} and not defined eval { do { qr/$model->{$regex_item}/ } })
933 9 26 unless (defined $model->{'smoothing'})
936 1 34 if ($model->{'smoothing'} ne "laplace" and $model->{'smoothing'} ne "lidstone")
939 9 25 unless (defined $model->{'alpha'})
940 0 9 $model->{'smoothing'} eq 'lidstone' ? :
942 2 32 if (ref $model->{'alpha'} ne "" or not $model->{'alpha'} =~ /\A\d*\.?\d+\z/ or $model->{'alpha'} <= 0)
945 1 31 if ($model->{'smoothing'} eq "laplace" and $model->{'alpha'} != 1)
949 7 24 unless (defined $model->{'ngrams'})
952 2 29 if (ref $model->{'ngrams'} ne "" or not $model->{'ngrams'} =~ /\A\d+\z/ or $model->{'ngrams'} < 1)
956 6 23 unless (defined $model->{'token_weighting'})
959 1 28 if ($model->{'token_weighting'} ne "count" and $model->{'token_weighting'} ne "binary")
963 5 23 unless (defined $model->{'priors'})
966 1 27 if ($model->{'priors'} ne "trained" and $model->{'priors'} ne "uniform")
988 1 11 unless (defined $file)
995 1 10 if ($@)
1018 1 26 unless (defined $file)
1023 1 25 unless (defined $raw)
1028 6 19 if ($@)