line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Guess::Script; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
3067
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
121
|
|
4
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
161
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
3283
|
use Unicode::Normalize; |
|
4
|
|
|
|
|
17161
|
|
|
4
|
|
|
|
|
311
|
|
9
|
4
|
|
|
4
|
|
5851
|
use Unicode::UCD qw(charscript prop_value_aliases); |
|
4
|
|
|
|
|
209333
|
|
|
4
|
|
|
|
|
1899
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @codes; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
6
|
|
|
6
|
1
|
1314
|
my $class = shift; |
15
|
|
|
|
|
|
|
# uncoverable condition false |
16
|
6
|
100
|
66
|
|
|
62
|
bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; |
|
2
|
100
|
|
|
|
22
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub guess { |
20
|
12
|
|
|
12
|
1
|
2276
|
my ($self, $text) = @_; |
21
|
|
|
|
|
|
|
|
22
|
12
|
100
|
|
|
|
51
|
if ( $text eq '' ) { return ''; } |
|
1
|
|
|
|
|
8
|
|
23
|
|
|
|
|
|
|
|
24
|
11
|
|
|
|
|
45
|
my $guesses = $self->_guesses($text); |
25
|
|
|
|
|
|
|
|
26
|
11
|
|
|
|
|
104
|
return $guesses->[0]->[0]; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub guesses { |
30
|
11
|
|
|
11
|
1
|
30
|
my ($self, $text) = @_; |
31
|
|
|
|
|
|
|
|
32
|
11
|
100
|
|
|
|
32
|
if ( $text eq '' ) { return []; } |
|
1
|
|
|
|
|
7
|
|
33
|
|
|
|
|
|
|
|
34
|
10
|
|
|
|
|
24
|
my $guesses = $self->_guesses($text); |
35
|
|
|
|
|
|
|
|
36
|
10
|
|
|
|
|
56
|
return $guesses; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _guesses { |
40
|
21
|
|
|
21
|
|
79
|
my ($self, $text) = @_; |
41
|
|
|
|
|
|
|
|
42
|
21
|
|
|
|
|
1221
|
my $text_NFC = NFC($text); |
43
|
|
|
|
|
|
|
|
44
|
21
|
|
|
|
|
4781
|
my @tokens = $text_NFC =~ m/(.)/xmsg; |
45
|
|
|
|
|
|
|
|
46
|
21
|
|
|
|
|
84
|
my $chars = {}; |
47
|
21
|
|
|
|
|
46
|
for my $token (@tokens) { |
48
|
10524
|
|
|
|
|
15202
|
$chars->{$token}++; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
21
|
|
|
|
|
39
|
my $guesses = {}; |
52
|
21
|
|
|
|
|
43
|
my $names = {}; |
53
|
|
|
|
|
|
|
|
54
|
21
|
|
|
|
|
89
|
for my $char (keys %$chars) { |
55
|
137
|
|
|
|
|
392
|
my ($code, $name) = prop_value_aliases( 'Script', charscript( ord($char) ) ); |
56
|
|
|
|
|
|
|
|
57
|
137
|
|
|
|
|
155320
|
$guesses->{$code} += $chars->{$char}; |
58
|
137
|
|
66
|
|
|
477
|
$names->{$code} //= $name; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $result = [ |
62
|
30
|
|
|
|
|
146
|
map { [ $_, $guesses->{$_}/scalar(@tokens), $names->{$_} ] } |
63
|
21
|
|
|
|
|
147
|
sort { $guesses->{$b} <=> $guesses->{$a} } |
|
9
|
|
|
|
|
53
|
|
64
|
|
|
|
|
|
|
keys( %$guesses ) |
65
|
|
|
|
|
|
|
]; |
66
|
|
|
|
|
|
|
|
67
|
21
|
|
|
|
|
960
|
return $result; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |