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