line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::UnAbbrev; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
40597
|
use common::sense; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
4
|
1
|
|
|
1
|
|
803
|
use charnames q(:full); |
|
1
|
|
|
|
|
41925
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
290
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
113
|
|
6
|
1
|
|
|
1
|
|
941
|
use English qw[-no_match_vars]; |
|
1
|
|
|
|
|
5036
|
|
|
1
|
|
|
|
|
10
|
|
7
|
1
|
|
|
1
|
|
568
|
use File::Find; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
82
|
|
8
|
1
|
|
|
1
|
|
886
|
use File::Spec::Functions (); |
|
1
|
|
|
|
|
1121
|
|
|
1
|
|
|
|
|
37
|
|
9
|
1
|
|
|
1
|
|
730
|
use IO::File; |
|
1
|
|
|
|
|
12428
|
|
|
1
|
|
|
|
|
182
|
|
10
|
1
|
|
|
1
|
|
2163
|
use Moo; |
|
1
|
|
|
|
|
18589
|
|
|
1
|
|
|
|
|
9
|
|
11
|
1
|
|
|
1
|
|
2952
|
use File::ShareDir::ProjectDistDir; |
|
1
|
|
|
|
|
23770
|
|
|
1
|
|
|
|
|
9
|
|
12
|
1
|
|
|
1
|
|
936
|
use Unicode::CaseFold; |
|
1
|
|
|
|
|
1084
|
|
|
1
|
|
|
|
|
543
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.03'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has dict => ( is => q(rw), default => sub { {}; }, ); |
17
|
|
|
|
|
|
|
has language => ( is => q(rw) ); |
18
|
|
|
|
|
|
|
has domain => ( is => q(rw) ); |
19
|
|
|
|
|
|
|
has subdomain => ( is => q(rw) ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub BUILD { |
22
|
1
|
|
|
1
|
0
|
9
|
my $self = shift; |
23
|
1
|
|
|
|
|
2
|
my $args = shift; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
2
|
my $pkg = __PACKAGE__; |
26
|
1
|
|
|
|
|
5
|
$pkg =~ s{::}{-}g; |
27
|
1
|
|
|
|
|
6
|
my $share_dir = dist_dir($pkg); |
28
|
1
|
|
|
|
|
194895
|
my @dict_file; |
29
|
1
|
50
|
|
13
|
|
142
|
find( sub { push @dict_file, $File::Find::name if -e }, $share_dir, ); |
|
13
|
|
|
|
|
668
|
|
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
12
|
while ( my $dict_file = shift @dict_file ) { |
32
|
13
|
|
|
|
|
47
|
$self->_load_dict($dict_file); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
1
|
50
|
|
|
|
7
|
if ( ref $args eq q(HASH) ) { |
36
|
1
|
|
|
|
|
2
|
foreach my $method ( keys %{$args} ) { |
|
1
|
|
|
|
|
6
|
|
37
|
0
|
0
|
|
|
|
0
|
if ( __PACKAGE__->can($method) ) { |
38
|
0
|
|
|
|
|
0
|
my $value = delete $args->{$method}; |
39
|
0
|
|
|
|
|
0
|
$self->$method($value); |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
0
|
else { croak( sprintf q(method unknown: '%s'), $method ); } |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
33
|
return 1; |
46
|
|
|
|
|
|
|
} ## end sub BUILD |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _load_dict { |
49
|
13
|
|
|
13
|
|
22
|
my $self = shift; |
50
|
13
|
|
|
|
|
21
|
my $dict_file = shift; |
51
|
|
|
|
|
|
|
|
52
|
13
|
|
|
|
|
58
|
my ( $language, $domain, $subdomain ) |
53
|
|
|
|
|
|
|
= ( File::Spec::Functions::splitdir($dict_file) )[ -3, -2, -1 ]; |
54
|
|
|
|
|
|
|
|
55
|
13
|
|
|
|
|
184
|
my $fh = IO::File->new( $dict_file, q(<:utf8) ); |
56
|
13
|
|
|
|
|
1647
|
while ( my $line = $fh->getline() ) { |
57
|
1907
|
|
|
|
|
42871
|
chomp $line; |
58
|
1907
|
|
|
|
|
13292
|
my ( $abbrev, $expansion ) = split m{\t+|\N{SPACE}{2,}}msx, $line; |
59
|
1907
|
|
|
|
|
3478
|
$abbrev = $self->_norm_abbrev($abbrev); |
60
|
1907
|
|
|
|
|
1604
|
push @{ $self->dict->{$language}{$domain}{$subdomain}{$abbrev} }, |
|
1907
|
|
|
|
|
42853
|
|
61
|
|
|
|
|
|
|
$expansion; |
62
|
|
|
|
|
|
|
} |
63
|
13
|
|
|
|
|
476
|
$fh->close(); |
64
|
|
|
|
|
|
|
|
65
|
13
|
|
|
|
|
370
|
return 1; |
66
|
|
|
|
|
|
|
} ## end sub _load_dict |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub lookup { |
69
|
7037
|
|
|
7037
|
1
|
5072973
|
my $self = shift; |
70
|
7037
|
|
|
|
|
10566
|
my $abbrev = shift; |
71
|
7037
|
|
|
|
|
10111
|
my $mode = shift; |
72
|
|
|
|
|
|
|
|
73
|
7037
|
50
|
|
|
|
17950
|
return unless defined $abbrev; |
74
|
|
|
|
|
|
|
|
75
|
7037
|
|
|
|
|
14861
|
my $query = $self->_norm_abbrev($abbrev); |
76
|
7037
|
|
|
|
|
7943
|
my @result; |
77
|
7037
|
|
66
|
|
|
27843
|
my @language = $self->language() || keys %{ $self->dict() }; |
78
|
7037
|
|
|
|
|
11479
|
foreach my $language (@language) { |
79
|
8759
|
|
|
|
|
19876
|
my $language_node = $self->dict->{$language}; |
80
|
8759
|
|
66
|
|
|
24171
|
my @domain = $self->domain() || keys %{$language_node}; |
81
|
8759
|
|
|
|
|
11307
|
foreach my $domain (@domain) { |
82
|
13087
|
|
|
|
|
19647
|
my $domain_node = $language_node->{$domain}; |
83
|
13087
|
|
66
|
|
|
32800
|
my @subdomain = $self->subdomain() || keys %{$domain_node}; |
84
|
13087
|
|
|
|
|
15110
|
foreach my $subdomain (@subdomain) { |
85
|
17598
|
|
|
|
|
18839
|
my $subdomain_node = $domain_node->{$subdomain}; |
86
|
17598
|
100
|
|
|
|
59086
|
if ( exists $subdomain_node->{$query} ) { |
87
|
7116
|
|
|
|
|
25337
|
my $origin = { |
88
|
|
|
|
|
|
|
language => $language, |
89
|
|
|
|
|
|
|
domain => $domain, |
90
|
|
|
|
|
|
|
subdomain => $subdomain, |
91
|
|
|
|
|
|
|
}; |
92
|
7116
|
|
|
|
|
24205
|
push @result, |
93
|
|
|
|
|
|
|
$self->_proc_results( $subdomain_node->{$query}, |
94
|
|
|
|
|
|
|
$mode, $origin, ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} ## end foreach my $domain (@domain) |
98
|
|
|
|
|
|
|
} ## end foreach my $language (@language) |
99
|
|
|
|
|
|
|
|
100
|
7037
|
|
|
|
|
26894
|
return @result; |
101
|
|
|
|
|
|
|
} ## end sub lookup |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _proc_results { |
104
|
7116
|
|
|
7116
|
|
8795
|
my $self = shift; |
105
|
7116
|
|
|
|
|
8384
|
my $results = shift; |
106
|
7116
|
|
|
|
|
7167
|
my $mode = shift; |
107
|
7116
|
|
|
|
|
7256
|
my $origin = shift; |
108
|
|
|
|
|
|
|
|
109
|
7116
|
|
|
|
|
7329
|
my @result; |
110
|
7116
|
|
|
|
|
6541
|
foreach my $result ( @{$results} ) { |
|
7116
|
|
|
|
|
12472
|
|
111
|
7628
|
50
|
33
|
|
|
19204
|
if ( defined $mode && $mode eq q(with_origin) ) { |
112
|
0
|
|
|
|
|
0
|
push @result, { $result => $origin }; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
else { |
115
|
7628
|
|
|
|
|
17843
|
push @result, $result; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
7116
|
|
|
|
|
38093
|
return @result; |
120
|
|
|
|
|
|
|
} ## end sub _proc_results |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub _norm_abbrev { |
123
|
8944
|
|
|
8944
|
|
11474
|
my $self = shift; |
124
|
8944
|
|
|
|
|
10205
|
my $abbrev = shift; |
125
|
|
|
|
|
|
|
|
126
|
8944
|
|
|
|
|
16910
|
foreach ($abbrev) { |
127
|
8944
|
|
|
|
|
27836
|
tr{\N{FULL STOP}}{}d; |
128
|
8944
|
|
|
|
|
14820
|
tr{\N{SPACE}} {}d; |
129
|
8944
|
|
|
|
|
27138
|
$_ = fc; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
8944
|
|
|
|
|
71847
|
return $abbrev; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
__END__ |