line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## ---------------------------------------------------------------------------- |
2
|
|
|
|
|
|
|
# Pod::MultiLang::Dict |
3
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
4
|
|
|
|
|
|
|
# Mastering programed by YAMASHINA Hio |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Copyright 2003 YMIRLINK,Inc. |
7
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
8
|
|
|
|
|
|
|
# $Id: /perl/Pod-MultiLang/lib/Pod/MultiLang/Dict.pm 216 2006-11-14T15:01:52.545337Z hio $ |
9
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
package Pod::MultiLang::Dict; |
11
|
8
|
|
|
8
|
|
715
|
use strict; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
332
|
|
12
|
8
|
|
|
8
|
|
53
|
use vars qw($VERSION); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
398
|
|
13
|
|
|
|
|
|
|
BEGIN{ |
14
|
8
|
|
|
8
|
|
124
|
$VERSION = '0.01'; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
8
|
|
|
8
|
|
41
|
use Carp; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
505
|
|
18
|
8
|
|
|
8
|
|
42
|
use vars qw(%STATIC_TABLE %DICT); |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
6323
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
21
|
|
|
|
|
|
|
# new() |
22
|
|
|
|
|
|
|
# とくになにもしないけど^^;; |
23
|
|
|
|
|
|
|
# |
24
|
|
|
|
|
|
|
sub new |
25
|
|
|
|
|
|
|
{ |
26
|
0
|
|
|
0
|
1
|
0
|
my $pkg = shift; |
27
|
0
|
|
|
|
|
0
|
my $this = bless \$pkg,$pkg; |
28
|
0
|
|
|
|
|
0
|
$this; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
32
|
|
|
|
|
|
|
# Pod::MultiLang::Dict->load_dict([@langs]); |
33
|
|
|
|
|
|
|
# 失敗時には die. |
34
|
|
|
|
|
|
|
# 辞書をロード. |
35
|
|
|
|
|
|
|
# ロード済みなら単純に無視される. |
36
|
|
|
|
|
|
|
# |
37
|
|
|
|
|
|
|
sub load_dict |
38
|
|
|
|
|
|
|
{ |
39
|
7
|
|
|
7
|
1
|
32
|
my $pkg = shift; |
40
|
7
|
50
|
|
|
|
26
|
@_ or return; |
41
|
7
|
100
|
|
|
|
50
|
foreach my $lang(UNIVERSAL::isa($_[0],'ARRAY')?@{$_[0]}:@_) |
|
5
|
|
|
|
|
26
|
|
42
|
|
|
|
|
|
|
{ |
43
|
12
|
50
|
|
|
|
101
|
$lang =~ /^[a-zA-Z_]\w+([\.\-]\w+)*$/ or croak "invalid lang [$lang]"; |
44
|
12
|
100
|
|
|
|
53
|
exists($DICT{$lang}) and next; |
45
|
8
|
|
|
|
|
27
|
my $pkg = "Pod::MultiLang::Dict::$lang"; |
46
|
8
|
|
|
|
|
26
|
$pkg =~ tr/\.\-/__/; |
47
|
8
|
|
|
|
|
21
|
$DICT{$lang} = $pkg; |
48
|
8
|
|
|
|
|
27
|
my $eval = "use $pkg;"; |
49
|
8
|
|
|
5
|
|
655
|
eval $eval; |
|
5
|
|
|
3
|
|
6060
|
|
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
83
|
|
|
3
|
|
|
|
|
1413
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
8
|
50
|
66
|
|
|
121
|
$@ && $lang ne 'en' and croak $@; |
51
|
8
|
100
|
|
|
|
117
|
if( $pkg->can("static_table") ) |
52
|
|
|
|
|
|
|
{ |
53
|
5
|
|
|
|
|
25
|
my $table = $pkg->static_table(); |
54
|
5
|
|
|
|
|
28
|
$STATIC_TABLE{$lang} = $table; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
60
|
|
|
|
|
|
|
# @text = Pod::MultiLang::Dict->find_word([@langs],$text); |
61
|
|
|
|
|
|
|
# |
62
|
|
|
|
|
|
|
sub find_word |
63
|
|
|
|
|
|
|
{ |
64
|
89
|
|
|
89
|
1
|
204
|
my $pkg = shift; |
65
|
89
|
|
|
|
|
164
|
my $langs = shift; |
66
|
89
|
|
|
|
|
134
|
my $origtext = shift; |
67
|
89
|
|
|
|
|
289
|
my $text = uc($origtext); |
68
|
89
|
|
|
|
|
742
|
my @inparts = split(/\s+(AND|&)\s+/,$text); |
69
|
89
|
|
|
|
|
156
|
my @text; |
70
|
89
|
|
|
|
|
373
|
$#text = $#$langs; |
71
|
89
|
|
|
|
|
159
|
my $idx = -1; |
72
|
|
|
|
|
|
|
EACH_LANG: |
73
|
89
|
|
|
|
|
533
|
foreach my $lang (@$langs) |
74
|
|
|
|
|
|
|
{ |
75
|
100
|
|
|
|
|
136
|
++$idx; |
76
|
100
|
|
|
|
|
141
|
my @parts; |
77
|
100
|
50
|
33
|
|
|
410
|
if( @inparts>1 && !exists($STATIC_TABLE{$lang}{AND}) ) |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
|
|
0
|
next; |
80
|
|
|
|
|
|
|
} |
81
|
100
|
|
|
|
|
196
|
foreach my $text (@inparts) |
82
|
|
|
|
|
|
|
{ |
83
|
100
|
100
|
|
|
|
402
|
if( exists($STATIC_TABLE{$lang}{$text}) ) |
84
|
|
|
|
|
|
|
{ |
85
|
11
|
|
|
|
|
55
|
push(@parts,$STATIC_TABLE{$lang}{$text}); |
86
|
11
|
|
|
|
|
31
|
next; |
87
|
|
|
|
|
|
|
} |
88
|
89
|
50
|
|
|
|
274
|
if( $text eq '&' ) |
89
|
|
|
|
|
|
|
{ |
90
|
0
|
0
|
|
|
|
0
|
if( exists($STATIC_TABLE{$lang}{AND}) ) |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
|
|
|
|
0
|
push(@parts,$STATIC_TABLE{$lang}{AND}); |
93
|
|
|
|
|
|
|
}else |
94
|
|
|
|
|
|
|
{ |
95
|
0
|
|
|
|
|
0
|
push(@parts,$text); |
96
|
|
|
|
|
|
|
} |
97
|
0
|
|
|
|
|
0
|
next; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
89
|
|
|
|
|
141
|
my $chk; |
101
|
|
|
|
|
|
|
# 複数形っぽかったら単数形探してみる |
102
|
|
|
|
|
|
|
# |
103
|
89
|
50
|
66
|
|
|
1827
|
if( ($chk = $text) =~ s/S$// && exists($STATIC_TABLE{$lang}{$chk}) ) |
104
|
|
|
|
|
|
|
{ |
105
|
0
|
|
|
|
|
0
|
push(@parts,$STATIC_TABLE{$lang}{$chk}); |
106
|
0
|
|
|
|
|
0
|
next; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
# 複数形にして探してみる |
109
|
|
|
|
|
|
|
# |
110
|
89
|
100
|
|
|
|
2148
|
$chk = $text.($text=~/[SX]$/?'ES':'S'); |
111
|
89
|
50
|
|
|
|
521
|
if( exists($STATIC_TABLE{$lang}{$chk}) ) |
112
|
|
|
|
|
|
|
{ |
113
|
0
|
|
|
|
|
0
|
push(@parts,$STATIC_TABLE{$lang}{$chk}); |
114
|
0
|
|
|
|
|
0
|
next; |
115
|
|
|
|
|
|
|
} |
116
|
89
|
|
|
|
|
462
|
next EACH_LANG; |
117
|
|
|
|
|
|
|
} |
118
|
11
|
|
|
|
|
43
|
$text[$idx] = join('',@parts); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
#print "[$text] @{[scalar@text]}\n"; |
121
|
|
|
|
|
|
|
#map{print " $_\n"}map{defined($_)?"[$_]":"{undef}"}@text; |
122
|
89
|
|
|
|
|
659
|
@text; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
126
|
|
|
|
|
|
|
# $text = $pkg->make_linktext($lang,$name,$section); |
127
|
|
|
|
|
|
|
# |
128
|
|
|
|
|
|
|
sub make_linktext |
129
|
|
|
|
|
|
|
{ |
130
|
0
|
|
|
0
|
1
|
0
|
my ($pkg,$lang,$name,$section) = @_; |
131
|
0
|
|
|
|
|
0
|
my $impl = $pkg.'::'.$lang; |
132
|
0
|
0
|
|
|
|
0
|
if( UNIVERSAL::can($impl,'make_linktext') ) |
133
|
|
|
|
|
|
|
{ |
134
|
0
|
|
|
|
|
0
|
$impl->make_linktext($lang,$name,$section); |
135
|
|
|
|
|
|
|
}else |
136
|
|
|
|
|
|
|
{ |
137
|
0
|
0
|
|
|
|
0
|
$name |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
138
|
|
|
|
|
|
|
? $section ? qq($name/"$section") : $name |
139
|
|
|
|
|
|
|
: $section ? qq("$section") : undef; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
__END__ |