line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::UnAbbrev; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
44194
|
use common::sense; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
4
|
1
|
|
|
1
|
|
2571
|
use charnames q(:full); |
|
1
|
|
|
|
|
38675
|
|
|
1
|
|
|
|
|
8
|
|
5
|
1
|
|
|
1
|
|
244
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
6
|
1
|
|
|
1
|
|
867
|
use English qw[-no_match_vars]; |
|
1
|
|
|
|
|
3835
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
392
|
use File::Find; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
63
|
|
8
|
1
|
|
|
1
|
|
877
|
use File::Spec::Functions (); |
|
1
|
|
|
|
|
968
|
|
|
1
|
|
|
|
|
24
|
|
9
|
1
|
|
|
1
|
|
784
|
use IO::File; |
|
1
|
|
|
|
|
11454
|
|
|
1
|
|
|
|
|
124
|
|
10
|
1
|
|
|
1
|
|
3228
|
use Moo; |
|
1
|
|
|
|
|
24025
|
|
|
1
|
|
|
|
|
7
|
|
11
|
1
|
|
|
1
|
|
3295
|
use File::ShareDir::ProjectDistDir; |
|
1
|
|
|
|
|
65445
|
|
|
1
|
|
|
|
|
11
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has share_dir => ( is => q(ro), default => sub { }, ); |
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
|
0
|
|
|
0
|
|
|
my $self = shift; |
23
|
0
|
|
|
|
|
|
my $args = shift; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $share_dir = dist_dir(__PACKAGE__); |
26
|
0
|
|
|
|
|
|
my @dict_file; |
27
|
0
|
0
|
|
0
|
|
|
find( sub { push @dict_file, $File::Find::name if -e }, $share_dir, ); |
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
while ( my $dict_file = shift @dict_file ) { |
30
|
0
|
|
|
|
|
|
$self->_load_dict($dict_file); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
if ( ref $args eq q(HASH) ) { |
34
|
0
|
|
|
|
|
|
foreach my $method ( keys %{$args} ) { |
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
if ( __PACKAGE__->can($method) ) { |
36
|
0
|
|
|
|
|
|
my $value = delete $args->{$method}; |
37
|
0
|
|
|
|
|
|
$self->$method($value); |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
else { croak( sprintf q(method unknown: '%s'), $method ); } |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
return 1; |
44
|
|
|
|
|
|
|
} ## end sub BUILD |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _load_dict { |
47
|
0
|
|
|
0
|
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my $dict_file = shift; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my ( $language, $domain, $subdomain ) |
51
|
|
|
|
|
|
|
= ( File::Spec::Functions::splitdir($dict_file) )[ -3, -2, -1 ]; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $fh = IO::File->new( $dict_file, q(<:utf8) ); |
54
|
0
|
|
|
|
|
|
while ( my $line = $fh->getline() ) { |
55
|
0
|
|
|
|
|
|
chomp $line; |
56
|
0
|
|
|
|
|
|
my ( $abbrev, $expansion ) = split m{\t+|\N{SPACE}{2,}}msx, $line; |
57
|
0
|
|
|
|
|
|
$abbrev = $self->_norm_abbrev($abbrev); |
58
|
0
|
|
|
|
|
|
push @{ $self->dict->{$language}{$domain}{$subdomain}{$abbrev} }, |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$expansion; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
$fh->close(); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return 1; |
64
|
|
|
|
|
|
|
} ## end sub _load_dict |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub lookup { |
67
|
0
|
|
|
0
|
|
|
my $self = shift; |
68
|
0
|
|
|
|
|
|
my $abbrev = shift; |
69
|
0
|
|
|
|
|
|
my $mode = shift; |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
return unless defined $abbrev; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $query = $self->_norm_abbrev($abbrev); |
74
|
0
|
|
|
|
|
|
my @result; |
75
|
0
|
|
0
|
|
|
|
my @language = $self->language() || keys %{ $self->dict() }; |
76
|
0
|
|
|
|
|
|
foreach my $language (@language) { |
77
|
0
|
|
|
|
|
|
my $language_node = $self->dict->{$language}; |
78
|
0
|
|
0
|
|
|
|
my @domain = $self->domain() || keys %{$language_node}; |
79
|
0
|
|
|
|
|
|
foreach my $domain (@domain) { |
80
|
0
|
|
|
|
|
|
my $domain_node = $language_node->{$domain}; |
81
|
0
|
|
0
|
|
|
|
my @subdomain = $self->subdomain() || keys %{$domain_node}; |
82
|
0
|
|
|
|
|
|
foreach my $subdomain (@subdomain) { |
83
|
0
|
|
|
|
|
|
my $subdomain_node = $domain_node->{$subdomain}; |
84
|
0
|
0
|
|
|
|
|
if ( exists $subdomain_node->{$query} ) { |
85
|
0
|
|
|
|
|
|
my $origin = { |
86
|
|
|
|
|
|
|
language => $language, |
87
|
|
|
|
|
|
|
domain => $domain, |
88
|
|
|
|
|
|
|
subdomain => $subdomain, |
89
|
|
|
|
|
|
|
}; |
90
|
0
|
|
|
|
|
|
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
|
0
|
|
|
|
|
|
return @result; |
99
|
|
|
|
|
|
|
} ## end sub lookup |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _proc_results { |
102
|
|
|
|
|
|
|
my $self = shift; |
103
|
|
|
|
|
|
|
my $results = shift; |
104
|
|
|
|
|
|
|
my $mode = shift; |
105
|
|
|
|
|
|
|
my $origin = shift; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my @result; |
108
|
|
|
|
|
|
|
foreach my $result ( @{$results} ) { |
109
|
|
|
|
|
|
|
if ( $mode ~~ q(with_origin) ) { |
110
|
|
|
|
|
|
|
push @result, { $result => $origin }; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
else { |
113
|
|
|
|
|
|
|
push @result, $result; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
return @result; |
118
|
|
|
|
|
|
|
} ## end sub _proc_results |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _norm_abbrev { |
121
|
|
|
|
|
|
|
my $self = shift; |
122
|
|
|
|
|
|
|
my $abbrev = shift; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
foreach ($abbrev) { |
125
|
|
|
|
|
|
|
tr{\N{FULL STOP}}{}d; |
126
|
|
|
|
|
|
|
tr{\N{SPACE}} {}d; |
127
|
|
|
|
|
|
|
$_ = fc; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
return $abbrev; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |