File Coverage

blib/lib/Lingua/TermWeight/WordCounter/Simple.pm
Criterion Covered Total %
statement 14 14 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 19 21 90.4


line stmt bran cond sub pod time code
1             # SPDX-FileCopyrightText: 2014 Koichi SATOH
2             # SPDX-FileCopyrightText: 2026 Wesley Schwengle
3             #
4             # SPDX-License-Identifier: MIT
5              
6             package Lingua::TermWeight::WordCounter::Simple;
7             our $VERSION = '0.01';
8             # ABSTRACT: Simple word counter
9              
10 2     2   129351 use v5.26;
  2         6  
11 2     2   540 use Object::Pad;
  2         10647  
  2         14  
12 2     2   298 use Carp qw(croak);
  2         3  
  2         588  
13              
14             class Lingua::TermWeight::WordCounter::Simple {
15              
16             field %frequencies;
17              
18 419     419 0 400 method add_count ($word) {
  419         556  
  419         413  
  419         398  
19 419 50       525 croak "Word must be defined" unless defined $word;
20 419         818 ++$frequencies{$word};
21             }
22              
23             method clear {
24             %frequencies = ();
25             }
26              
27             method frequencies {
28             return {%frequencies};
29             }
30             }
31              
32             1;
33              
34             __END__