line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::Guess::Script; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
3177
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
125
|
|
4
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
163
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
2402
|
use Unicode::Normalize; |
|
4
|
|
|
|
|
8719
|
|
|
4
|
|
|
|
|
337
|
|
9
|
4
|
|
|
4
|
|
4135
|
use Unicode::UCD qw(charscript prop_value_aliases); |
|
4
|
|
|
|
|
204588
|
|
|
4
|
|
|
|
|
1657
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @codes; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
6
|
|
|
6
|
1
|
929
|
my $class = shift; |
15
|
|
|
|
|
|
|
# uncoverable condition false |
16
|
6
|
100
|
66
|
|
|
44
|
bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class; |
|
2
|
100
|
|
|
|
14
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub guess { |
20
|
11
|
|
|
11
|
1
|
2031
|
my ($self, $text) = @_; |
21
|
|
|
|
|
|
|
|
22
|
11
|
100
|
|
|
|
40
|
if ( $text eq '' ) { return ''; } |
|
1
|
|
|
|
|
5
|
|
23
|
|
|
|
|
|
|
|
24
|
10
|
|
|
|
|
37
|
my $guesses = $self->_guesses($text); |
25
|
|
|
|
|
|
|
|
26
|
10
|
|
|
|
|
88
|
return $guesses->[0]->[0]; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub guesses { |
30
|
4
|
|
|
4
|
1
|
10
|
my ($self, $text) = @_; |
31
|
|
|
|
|
|
|
|
32
|
4
|
100
|
|
|
|
14
|
if ( $text eq '' ) { return []; } |
|
1
|
|
|
|
|
5
|
|
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
8
|
my $guesses = $self->_guesses($text); |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
16
|
return $guesses; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _guesses { |
40
|
13
|
|
|
13
|
|
57
|
my ($self, $text) = @_; |
41
|
|
|
|
|
|
|
|
42
|
13
|
|
|
|
|
1109
|
my $text_NFC = NFC($text); |
43
|
|
|
|
|
|
|
|
44
|
13
|
|
|
|
|
5002
|
my @tokens = $text_NFC =~ m/(.)/xmsg; |
45
|
|
|
|
|
|
|
|
46
|
13
|
|
|
|
|
78
|
my $chars = {}; |
47
|
13
|
|
|
|
|
34
|
for my $token (@tokens) { |
48
|
10506
|
|
|
|
|
15233
|
$chars->{$token}++; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
13
|
|
|
|
|
30
|
my $guesses = {}; |
52
|
|
|
|
|
|
|
#my @other_codes = @codes; |
53
|
|
|
|
|
|
|
#my @seen_codes; |
54
|
|
|
|
|
|
|
|
55
|
13
|
|
|
|
|
70
|
for my $char (keys %$chars) { |
56
|
122
|
|
|
|
|
348
|
my ($code, $name) = prop_value_aliases("Script",charscript(ord($char))); |
57
|
|
|
|
|
|
|
|
58
|
122
|
|
|
|
|
142274
|
$guesses->{$code} += $chars->{$char}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $result = [ |
62
|
21
|
|
|
|
|
89
|
map { [ $_, $guesses->{$_}/scalar(@tokens) ] } |
63
|
13
|
|
|
|
|
98
|
sort { $guesses->{$b} <=> $guesses->{$a} } |
|
8
|
|
|
|
|
43
|
|
64
|
|
|
|
|
|
|
keys(%$guesses) |
65
|
|
|
|
|
|
|
]; |
66
|
13
|
|
|
|
|
858
|
return $result; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |