line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
MetaTrans::SlovnikZcuCz - MetaTrans plug-in for L |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=cut |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package MetaTrans::SlovnikZcuCz; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1215
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
11
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
12
|
1
|
|
|
1
|
|
6
|
use MetaTrans::Base qw(convert_to_utf8); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
6
|
use Encode qw(decode_utf8 encode); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
88
|
|
15
|
1
|
|
|
1
|
|
6
|
use HTTP::Request; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
16
|
1
|
|
|
1
|
|
6
|
use URI::Escape; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
813
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf "%d."."%02d", @r }; |
19
|
|
|
|
|
|
|
@ISA = qw(MetaTrans::Base); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 CONSTRUCTOR METHODS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=over 4 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item MetaTrans::SlovnikZcuCz->new(%options) |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This method constructs a new MetaTrans::SlovnikZcuCz object and returns it. All |
28
|
|
|
|
|
|
|
C<%options> are passed to C<< MetaTrans::Base->new >>. The method also sets |
29
|
|
|
|
|
|
|
supported translation directions and the C attribute. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=back |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
38
|
0
|
|
|
|
|
|
my %options = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
$options{host_server} = "slovnik.zcu.cz" |
41
|
|
|
|
|
|
|
unless (defined $options{host_server}); |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $self = new MetaTrans::Base(%options); |
44
|
0
|
|
|
|
|
|
$self = bless $self, $class; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# set supported languages |
47
|
0
|
|
|
|
|
|
$self->set_languages("cze", "eng"); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$self->set_dir_1_to_all("cze"); |
50
|
0
|
|
|
|
|
|
$self->set_dir_all_to_1("cze"); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 METHODS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Methods are inherited from C. Following methods are overriden: |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item $plugin->create_request($expression, $src_lang_code, $dest_lang_code) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Create and return a C object to be used for retrieving |
66
|
|
|
|
|
|
|
translation of the C<$expression> from C<$src_lang_code> language to |
67
|
|
|
|
|
|
|
C<$dest_lang_code> language. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub create_request |
72
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
74
|
0
|
|
|
|
|
|
my $expression = shift; |
75
|
0
|
|
|
|
|
|
my $src_lang_code = shift; |
76
|
0
|
|
|
|
|
|
my $dest_lang_code = shift; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# convert to perl internal form |
79
|
0
|
|
|
|
|
|
$expression = decode_utf8($expression); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# convert to iso-8859-2 |
82
|
0
|
|
|
|
|
|
$expression = uri_escape(encode('iso-8859-2', $expression)); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(POST => "http://slovnik.zcu.cz/online/index.php"); |
85
|
0
|
|
|
|
|
|
$request->content_type('application/x-www-form-urlencoded'); |
86
|
0
|
|
|
|
|
|
$request->content("word=$expression"); |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return $request; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item $plugin->process_response($contents, $src_lang_code, $dest_lang_code) |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Process the server response contents. Return the result of the translation in |
94
|
|
|
|
|
|
|
an array of following form: |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
(expression_1, translation_1, expression_2, translation_2, ...) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=back |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub process_response |
103
|
|
|
|
|
|
|
{ |
104
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
105
|
0
|
|
|
|
|
|
my $contents = shift; |
106
|
0
|
|
|
|
|
|
my $src_lang_code = shift; |
107
|
0
|
|
|
|
|
|
my $dest_lang_code = shift; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# the output is in iso-8859-2 character encoding with HTML entities, |
110
|
|
|
|
|
|
|
# let's convert it to UTF-8 |
111
|
0
|
|
|
|
|
|
$contents = convert_to_utf8('iso-8859-2', $contents); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
my @result; |
114
|
0
|
|
|
|
|
|
while ($contents =~ m| |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
]*>\s+ |
117
|
|
|
|
|
|
|
\s+ |
118
|
|
|
|
|
|
|
\s+ |
121
|
|
|
|
|
|
|
]*> |
122
|
|
|
|
|
|
|
|gsix) |
123
|
|
|
|
|
|
|
{ |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
push @result, _process_row($1, $src_lang_code); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return @result; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub _process_row { |
132
|
0
|
|
|
0
|
|
|
my $string = shift; |
133
|
0
|
|
|
|
|
|
my $src_lang_code = shift; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my @result; |
136
|
|
|
|
|
|
|
my $actual; |
137
|
0
|
|
|
|
|
|
while ($string =~ m| |
]*>(.*?)
|gsix)
138
|
|
|
|
|
|
|
{ |
139
|
0
|
|
|
|
|
|
my $td = $1; |
140
|
0
|
0
|
|
|
|
|
if ($td =~ m| | ]*>(.*?) | |gsix)
|
|
0
|
|
|
|
|
|
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
|
|
|
$actual = $1; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
elsif ($td =~ m| |
145
|
|
|
|
|
|
|
| ([^<>]+?) | \s+
146
|
|
|
|
|
|
|
| ([^<>]+?) | \s+
147
|
|
|
|
|
|
|
| .*? | \s+
148
|
|
|
|
|
|
|
| .*? | \s+
149
|
|
|
|
|
|
|
| .*? |
150
|
|
|
|
|
|
|
|gsix) |
151
|
|
|
|
|
|
|
{ |
152
|
0
|
|
|
|
|
|
my ($first, $second) = ($1, $2); |
153
|
0
|
0
|
0
|
|
|
|
if ($src_lang_code eq 'eng' && $actual =~ m|^Anglicko-Český\ssměr$|msx) |
|
|
0
|
0
|
|
|
|
|
154
|
|
|
|
|
|
|
{ |
155
|
0
|
|
|
|
|
|
push @result, $first, $second; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
elsif ($src_lang_code eq 'cze' |
158
|
|
|
|
|
|
|
&& $actual =~ m|^Česko-Anglický\ssměr$|msx) |
159
|
|
|
|
|
|
|
{ |
160
|
0
|
|
|
|
|
|
push @result, $second, $first; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
} |
164
|
0
|
|
|
|
|
|
return @result; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
__END__ |