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