line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::UnAbbrev; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23564
|
use common::sense; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
4
|
1
|
|
|
1
|
|
492
|
use charnames q(:full); |
|
1
|
|
|
|
|
26321
|
|
|
1
|
|
|
|
|
7
|
|
5
|
1
|
|
|
1
|
|
220
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
87
|
|
6
|
1
|
|
|
1
|
|
832
|
use English qw[-no_match_vars]; |
|
1
|
|
|
|
|
4191
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
445
|
use File::Find; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
8
|
1
|
|
|
1
|
|
594
|
use File::Spec::Functions (); |
|
1
|
|
|
|
|
653
|
|
|
1
|
|
|
|
|
22
|
|
9
|
1
|
|
|
1
|
|
443
|
use IO::File; |
|
1
|
|
|
|
|
7500
|
|
|
1
|
|
|
|
|
161
|
|
10
|
1
|
|
|
1
|
|
753
|
use Moo; |
|
1
|
|
|
|
|
15256
|
|
|
1
|
|
|
|
|
8
|
|
11
|
1
|
|
|
1
|
|
1938
|
use File::ShareDir::ProjectDistDir; |
|
1
|
|
|
|
|
17592
|
|
|
1
|
|
|
|
|
6
|
|
12
|
1
|
|
|
1
|
|
975
|
use Unicode::CaseFold; |
|
1
|
|
|
|
|
808
|
|
|
1
|
|
|
|
|
530
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.02'; # 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
|
7
|
my $self = shift; |
23
|
1
|
|
|
|
|
2
|
my $args = shift; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
5
|
my $share_dir = dist_dir(__PACKAGE__); |
26
|
1
|
|
|
|
|
92771
|
my @dict_file; |
27
|
1
|
50
|
|
13
|
|
88
|
find( sub { push @dict_file, $File::Find::name if -e }, $share_dir, ); |
|
13
|
|
|
|
|
428
|
|
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
7
|
while ( my $dict_file = shift @dict_file ) { |
30
|
13
|
|
|
|
|
47
|
$self->_load_dict($dict_file); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
1
|
50
|
|
|
|
5
|
if ( ref $args eq q(HASH) ) { |
34
|
1
|
|
|
|
|
1
|
foreach my $method ( keys %{$args} ) { |
|
1
|
|
|
|
|
4
|
|
35
|
0
|
0
|
|
|
|
0
|
if ( __PACKAGE__->can($method) ) { |
36
|
0
|
|
|
|
|
0
|
my $value = delete $args->{$method}; |
37
|
0
|
|
|
|
|
0
|
$self->$method($value); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
0
|
else { croak( sprintf q(method unknown: '%s'), $method ); } |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
19
|
return 1; |
44
|
|
|
|
|
|
|
} ## end sub BUILD |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _load_dict { |
47
|
13
|
|
|
13
|
|
20
|
my $self = shift; |
48
|
13
|
|
|
|
|
15
|
my $dict_file = shift; |
49
|
|
|
|
|
|
|
|
50
|
13
|
|
|
|
|
40
|
my ( $language, $domain, $subdomain ) |
51
|
|
|
|
|
|
|
= ( File::Spec::Functions::splitdir($dict_file) )[ -3, -2, -1 ]; |
52
|
|
|
|
|
|
|
|
53
|
13
|
|
|
|
|
150
|
my $fh = IO::File->new( $dict_file, q(<:utf8) ); |
54
|
13
|
|
|
|
|
1358
|
while ( my $line = $fh->getline() ) { |
55
|
1907
|
|
|
|
|
39993
|
chomp $line; |
56
|
1907
|
|
|
|
|
11143
|
my ( $abbrev, $expansion ) = split m{\t+|\N{SPACE}{2,}}msx, $line; |
57
|
1907
|
|
|
|
|
3011
|
$abbrev = $self->_norm_abbrev($abbrev); |
58
|
1907
|
|
|
|
|
1504
|
push @{ $self->dict->{$language}{$domain}{$subdomain}{$abbrev} }, |
|
1907
|
|
|
|
|
37151
|
|
59
|
|
|
|
|
|
|
$expansion; |
60
|
|
|
|
|
|
|
} |
61
|
13
|
|
|
|
|
403
|
$fh->close(); |
62
|
|
|
|
|
|
|
|
63
|
13
|
|
|
|
|
267
|
return 1; |
64
|
|
|
|
|
|
|
} ## end sub _load_dict |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub lookup { |
67
|
7037
|
|
|
7037
|
1
|
3767874
|
my $self = shift; |
68
|
7037
|
|
|
|
|
7713
|
my $abbrev = shift; |
69
|
7037
|
|
|
|
|
5625
|
my $mode = shift; |
70
|
|
|
|
|
|
|
|
71
|
7037
|
50
|
|
|
|
14160
|
return unless defined $abbrev; |
72
|
|
|
|
|
|
|
|
73
|
7037
|
|
|
|
|
12260
|
my $query = $self->_norm_abbrev($abbrev); |
74
|
7037
|
|
|
|
|
6891
|
my @result; |
75
|
7037
|
|
66
|
|
|
20573
|
my @language = $self->language() || keys %{ $self->dict() }; |
76
|
7037
|
|
|
|
|
8730
|
foreach my $language (@language) { |
77
|
8759
|
|
|
|
|
14739
|
my $language_node = $self->dict->{$language}; |
78
|
8759
|
|
66
|
|
|
18396
|
my @domain = $self->domain() || keys %{$language_node}; |
79
|
8759
|
|
|
|
|
9173
|
foreach my $domain (@domain) { |
80
|
13087
|
|
|
|
|
12588
|
my $domain_node = $language_node->{$domain}; |
81
|
13087
|
|
66
|
|
|
25195
|
my @subdomain = $self->subdomain() || keys %{$domain_node}; |
82
|
13087
|
|
|
|
|
12929
|
foreach my $subdomain (@subdomain) { |
83
|
17598
|
|
|
|
|
14823
|
my $subdomain_node = $domain_node->{$subdomain}; |
84
|
17598
|
100
|
|
|
|
47374
|
if ( exists $subdomain_node->{$query} ) { |
85
|
7116
|
|
|
|
|
17622
|
my $origin = { |
86
|
|
|
|
|
|
|
language => $language, |
87
|
|
|
|
|
|
|
domain => $domain, |
88
|
|
|
|
|
|
|
subdomain => $subdomain, |
89
|
|
|
|
|
|
|
}; |
90
|
7116
|
|
|
|
|
16944
|
push @result, |
91
|
|
|
|
|
|
|
$self->_proc_results( $subdomain_node->{$query}, |
92
|
|
|
|
|
|
|
$mode, $origin, ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} ## end foreach my $domain (@domain) |
96
|
|
|
|
|
|
|
} ## end foreach my $language (@language) |
97
|
|
|
|
|
|
|
|
98
|
7037
|
|
|
|
|
20278
|
return @result; |
99
|
|
|
|
|
|
|
} ## end sub lookup |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _proc_results { |
102
|
7116
|
|
|
7116
|
|
7358
|
my $self = shift; |
103
|
7116
|
|
|
|
|
6286
|
my $results = shift; |
104
|
7116
|
|
|
|
|
5477
|
my $mode = shift; |
105
|
7116
|
|
|
|
|
5633
|
my $origin = shift; |
106
|
|
|
|
|
|
|
|
107
|
7116
|
|
|
|
|
4997
|
my @result; |
108
|
7116
|
|
|
|
|
5791
|
foreach my $result ( @{$results} ) { |
|
7116
|
|
|
|
|
10555
|
|
109
|
7628
|
50
|
33
|
|
|
16616
|
if ( defined $mode && $mode eq q(with_origin) ) { |
110
|
0
|
|
|
|
|
0
|
push @result, { $result => $origin }; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
else { |
113
|
7628
|
|
|
|
|
15546
|
push @result, $result; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
7116
|
|
|
|
|
31866
|
return @result; |
118
|
|
|
|
|
|
|
} ## end sub _proc_results |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _norm_abbrev { |
121
|
8944
|
|
|
8944
|
|
9142
|
my $self = shift; |
122
|
8944
|
|
|
|
|
8334
|
my $abbrev = shift; |
123
|
|
|
|
|
|
|
|
124
|
8944
|
|
|
|
|
12908
|
foreach ($abbrev) { |
125
|
8944
|
|
|
|
|
19855
|
tr{\N{FULL STOP}}{}d; |
126
|
8944
|
|
|
|
|
12357
|
tr{\N{SPACE}} {}d; |
127
|
8944
|
|
|
|
|
22022
|
$_ = fc; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
8944
|
|
|
|
|
58063
|
return $abbrev; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |