line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Grapheme::Ngram; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
780
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
276
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
6
|
|
|
6
|
1
|
712
|
my $class = shift; |
11
|
|
|
|
|
|
|
# uncoverable condition false |
12
|
6
|
100
|
66
|
|
|
40
|
bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; |
|
2
|
100
|
|
|
|
12
|
|
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub ngram { |
16
|
14
|
|
|
14
|
1
|
21
|
my ($self, $word, $width) = @_; |
17
|
|
|
|
|
|
|
|
18
|
14
|
100
|
|
|
|
48
|
return [] unless (length($word)); |
19
|
|
|
|
|
|
|
|
20
|
11
|
|
|
|
|
17
|
return $self->from_tokens( |
21
|
|
|
|
|
|
|
$self->_tokenize($word), |
22
|
|
|
|
|
|
|
$width |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub from_tokens { |
27
|
11
|
|
|
11
|
1
|
1099
|
my ($self, $tokens, $width) = @_; |
28
|
|
|
|
|
|
|
|
29
|
11
|
100
|
100
|
|
|
61
|
$width = 1 unless ($width && $width =~ m/^[1-9][0-9]*$/x); |
30
|
|
|
|
|
|
|
|
31
|
11
|
100
|
|
|
|
22
|
return [join('',@$tokens)] unless ($width <= scalar @$tokens); |
32
|
|
|
|
|
|
|
|
33
|
10
|
|
|
|
|
13
|
my @ngrams; |
34
|
|
|
|
|
|
|
|
35
|
10
|
|
|
|
|
21
|
for my $i (0..scalar(@$tokens)-$width) { |
36
|
13
|
|
|
|
|
28
|
my $ngram = join('',@$tokens[$i..$i+$width-1]); |
37
|
13
|
|
|
|
|
27
|
push @ngrams,$ngram; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
10
|
|
|
|
|
44
|
return \@ngrams; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
12
|
|
|
12
|
|
71
|
sub _tokenize { [$_[1] =~ m/(\X)/g] } |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |