line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
MetaTrans::WordbookCz - MetaTrans plug-in for L |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=cut |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package MetaTrans::WordbookCz; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1117
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
11
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
12
|
1
|
|
|
1
|
|
5
|
use MetaTrans::Base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use HTTP::Request; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
737
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
$VERSION = do { my @r = (q$Revision: 1.3 $ =~ /\d+/g); sprintf "%d."."%02d", @r }; |
17
|
|
|
|
|
|
|
@ISA = qw(MetaTrans::Base); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 CONSTRUCTOR METHODS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=over 4 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=item MetaTrans::WordbookCz->new(%options) |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This method constructs a new MetaTrans::WordbookCz object and returns it. All |
26
|
|
|
|
|
|
|
C<%options> are passed to C<< MetaTrans::Base->new >>. The method also sets |
27
|
|
|
|
|
|
|
supported translation directions and the C attribute. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=back |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
36
|
0
|
|
|
|
|
|
my %options = @_; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
$options{host_server} = "www.wordbook.cz" |
39
|
|
|
|
|
|
|
unless (defined $options{host_server}); |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $self = new MetaTrans::Base(%options); |
42
|
0
|
|
|
|
|
|
$self = bless $self, $class; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$self->set_languages("cze", "eng", "fre", "ger", "spa"); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->set_dir_1_to_all("cze"); |
47
|
0
|
|
|
|
|
|
$self->set_dir_all_to_1("cze"); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return $self; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 METHODS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Methods are inherited from C. Following methods are overriden: |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=over 4 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item $plugin->create_request($expression, $src_lang_code, $dest_lang_code) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Create and return a C object to be used for retrieving |
63
|
|
|
|
|
|
|
translation of the C<$expression> from C<$src_lang_code> language to |
64
|
|
|
|
|
|
|
C<$dest_lang_code> language. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub create_request |
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
my $expression = shift; |
72
|
0
|
|
|
|
|
|
my $src_lang_code = shift; |
73
|
0
|
|
|
|
|
|
my $dest_lang_code = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my %table = ( |
76
|
|
|
|
|
|
|
eng => "enu", |
77
|
|
|
|
|
|
|
fre => "fra", |
78
|
|
|
|
|
|
|
ger => "ger", |
79
|
|
|
|
|
|
|
spa => "spa", |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $fsmer; |
83
|
|
|
|
|
|
|
my $fslovnik; |
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if ($src_lang_code eq 'cze') |
|
|
0
|
|
|
|
|
|
86
|
|
|
|
|
|
|
{ |
87
|
0
|
|
|
|
|
|
$fsmer = 1; |
88
|
0
|
|
|
|
|
|
$fslovnik = $table{$dest_lang_code}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
elsif ($dest_lang_code eq 'cze') |
91
|
|
|
|
|
|
|
{ |
92
|
0
|
|
|
|
|
|
$fsmer = 0; |
93
|
0
|
|
|
|
|
|
$fslovnik = $table{$src_lang_code}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(POST => "http://www.wordbook.cz/index.php"); |
97
|
0
|
|
|
|
|
|
$request->content_type('application/x-www-form-urlencoded'); |
98
|
0
|
|
|
|
|
|
my $query = |
99
|
|
|
|
|
|
|
"fextend=1" . |
100
|
|
|
|
|
|
|
"&fslovo=$expression" . |
101
|
|
|
|
|
|
|
"&fsmer=$fsmer" . |
102
|
|
|
|
|
|
|
"&fslovnik=$fslovnik"; |
103
|
0
|
|
|
|
|
|
$request->content($query); |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
return $request; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item $plugin->process_response($contents, $src_lang_code, $dest_lang_code) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Process the server response contents. Return the result of the translation in |
111
|
|
|
|
|
|
|
an array of following form: |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
(expression_1, translation_1, expression_2, translation_2, ...) |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=back |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub process_response |
120
|
|
|
|
|
|
|
{ |
121
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
122
|
0
|
|
|
|
|
|
my $contents = shift; |
123
|
0
|
|
|
|
|
|
my $src_lang_code = shift; |
124
|
0
|
|
|
|
|
|
my $dest_lang_code = shift; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my @result; |
127
|
0
|
|
|
|
|
|
while ($contents =~ m| |
128
|
|
|
|
|
|
|
|
]*?>
129
|
|
|
|
|
|
|
( | .*?) |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|gsix) |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
|
|
|
|
|
my $row = $1; |
134
|
0
|
|
|
|
|
|
$row =~ s/ //g; |
135
|
0
|
|
|
|
|
|
my @data; |
136
|
0
|
|
|
|
|
|
while ($row =~ m/ | (.*?)<\/td>/gixm) |
137
|
|
|
|
|
|
|
{ |
138
|
0
|
|
|
|
|
|
push @data, $1; |
139
|
|
|
|
|
|
|
} |
140
|
0
|
|
|
|
|
|
my ($expr, $trans, $note); |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# exact words. |
143
|
0
|
0
|
|
|
|
|
if (@data == 5) { |
|
|
0
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
(undef, $expr, undef, $trans, $note) = @data; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# similar words. |
147
|
|
|
|
|
|
|
} elsif (@data == 3) { |
148
|
0
|
|
|
|
|
|
($expr, $trans, $note) = @data; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# skip blank values. |
152
|
0
|
0
|
0
|
|
|
|
next if $expr =~ /^\s*$/ || $trans =~ /^\s*$/; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# normalize german. |
155
|
0
|
0
|
|
|
|
|
$expr = _normalize_german($expr, $note) |
156
|
|
|
|
|
|
|
if $src_lang_code eq 'ger'; |
157
|
0
|
0
|
|
|
|
|
$trans = _normalize_german($trans, $note) |
158
|
|
|
|
|
|
|
if $dest_lang_code eq 'ger'; |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# new result. |
161
|
0
|
|
|
|
|
|
push @result, ($expr, $trans); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
return @result; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub _normalize_german |
168
|
|
|
|
|
|
|
{ |
169
|
0
|
|
|
0
|
|
|
my $expr = shift; |
170
|
0
|
|
|
|
|
|
my $note = shift; |
171
|
|
|
|
|
|
|
|
172
|
0
|
0
|
0
|
|
|
|
if ($note && ($note eq 'die' || $note eq 'das' || $note eq 'der')) |
|
|
|
0
|
|
|
|
|
173
|
|
|
|
|
|
|
{ |
174
|
0
|
|
|
|
|
|
$expr .= '; ' . substr($note, 2, 1); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
return $expr; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
__END__ |