line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Zemanta::Suggest; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Net::Zemanta::Suggest - Perl interface to Zemanta Suggest service |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
19825
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
25
|
|
10
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
519
|
use Net::Zemanta::Method; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
295
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(Net::Zemanta::Method); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use Net::Zemanta::Suggest; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $zemanta = Net::Zemanta::Suggest->new( |
20
|
|
|
|
|
|
|
APIKEY => 'your-API-key' |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $suggestions = $zemanta->suggest( |
24
|
|
|
|
|
|
|
"Cozy lummox gives smart squid who asks for job pen." |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Suggested images |
28
|
|
|
|
|
|
|
for $image (@{$suggestions->{images}}) { |
29
|
|
|
|
|
|
|
$image->{url_m}; |
30
|
|
|
|
|
|
|
$image->{description}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Related articles |
34
|
|
|
|
|
|
|
for $article (@{$suggestions->{articles}}) { |
35
|
|
|
|
|
|
|
$article->{url}; |
36
|
|
|
|
|
|
|
$article->{title}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# In-text links |
40
|
|
|
|
|
|
|
for $link (@{$suggestions->{markup}->{links}}) { |
41
|
|
|
|
|
|
|
for $target (@{$link->{target}}) { |
42
|
|
|
|
|
|
|
$link->{anchor}, " -> ", $target->{url}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Keywords |
47
|
|
|
|
|
|
|
for $keyword (@{$suggestions->{keywords}}) { |
48
|
|
|
|
|
|
|
$keyword->{name}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 METHODS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=over 8 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item B |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Net::Zemanta::Suggest->new(PARAM => ...); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Acceptable parameters: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=over 4 |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item APIKEY |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
The API key used for authentication with the service. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item MARKUP_ONLY |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
If set to true, a faster variant of the API call is made that only returns |
70
|
|
|
|
|
|
|
the markup element. Default is to provide everything (images, related articles, |
71
|
|
|
|
|
|
|
markup and tags). |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item USER_AGENT |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
If supplied the value is prepended to this module's identification string |
76
|
|
|
|
|
|
|
to become something like: |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
your-killer-app/0.042 Perl-Net-Zemanta/0.1 libwww-perl/5.8 |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Otherwise just Net::Zemanta's user agent string will be sent. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
C returns C on error. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub new { |
89
|
3
|
|
|
3
|
1
|
673
|
my $class = shift; |
90
|
3
|
|
|
|
|
9
|
my %params = @_; |
91
|
|
|
|
|
|
|
|
92
|
3
|
100
|
|
|
|
9
|
if( $params{MARKUP_ONLY} ) { |
93
|
1
|
|
|
|
|
4
|
$params{METHOD} = "zemanta.suggest_markup"; |
94
|
|
|
|
|
|
|
} else { |
95
|
2
|
|
|
|
|
6
|
$params{METHOD} = "zemanta.suggest"; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
3
|
|
|
|
|
22
|
my $self = $class->SUPER::new(%params); |
99
|
|
|
|
|
|
|
|
100
|
3
|
100
|
|
|
|
20
|
return unless $self; |
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
3
|
bless ($self, $class); |
103
|
2
|
|
|
|
|
8
|
return $self; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item B |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$suggestions = $zemanta->suggest( text, PARAM => ... ) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Requests suggestions for the given text. Suggestions are returned as a tree |
111
|
|
|
|
|
|
|
of hash and list references that correspond to the returned JSON data |
112
|
|
|
|
|
|
|
structure. The most important parameters and result elements are described bellow. |
113
|
|
|
|
|
|
|
For the full reference see L. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Optional parameters: |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=over 4 |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item MARKUP_LIMIT |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Number of in-text links to return (default is 10). |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item IMAGES_LIMIT |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Number of images to return (default is 24). |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item ARTICLES_LIMIT |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Number of related articles to return (default is 10). |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item IMAGE_MAX_W, IMAGE_MAX_H |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Maximum width and height of returned images respectively (default is 300 by 300). |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=back |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
C returns C on error. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over 8 |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item B |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Related articles. Contains a list of article objects, each having the following |
144
|
|
|
|
|
|
|
elements: |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over 4 |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item B |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
URL of the article. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item B |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Title of the article. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item B |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Date when article was published in ISO 8601 format. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item B |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Suggested keywords. Contains a list of keyword objects, each having the |
165
|
|
|
|
|
|
|
following elements: |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=over 4 |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item B |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Keyword name (may contain spaces) |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=back |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item B |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Related images. Contains a list of image objects, each having the following |
178
|
|
|
|
|
|
|
elements: |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=over 4 |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item B, B, B |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
URLs of a large, medium and small version of the picture respectively. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item B, B, B, B, B, B |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Width and height of large, medium and small version of the picture respectively. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item B |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
String containing license terms. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item B |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
String containing description |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item B |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Attribution that must be posted together with the image. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=item B |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
URL of a web page where more information about the image can be found. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=back |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item B |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
An object containing the following elements: |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=over 4 |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item B |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
HTML formatted input text with added in-text hyperlinks. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item B |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Suggested in-text hyperlinks. A list of link objects, each having |
221
|
|
|
|
|
|
|
the following elements: |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=over 4 |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item B |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Word or phrase in the original text that should be used as the anchor for the |
228
|
|
|
|
|
|
|
link. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item B |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
List of possible targets for this link. Each target has the following elements: |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=over 4 |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item B |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Destination URL. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item B |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Type of the resource URL is pointing to. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=item B |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Title of the resource. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=back |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=back |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=back |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item B |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Request ID. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item B |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
HTML signature that should be appended to the text. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=back |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=item B |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
If the last call to C returned an error, this function returns a |
267
|
|
|
|
|
|
|
string containing a short description of the error. Otherwise it returns |
268
|
|
|
|
|
|
|
C. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=back |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=cut |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
sub suggest { |
275
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
|
my ($text, %options) = @_; |
278
|
|
|
|
|
|
|
|
279
|
0
|
|
|
|
|
|
my %lc_options; |
280
|
0
|
|
|
|
|
|
while(my ($key, $value) = each %options) { |
281
|
0
|
|
|
|
|
|
$lc_options{lc $key} = $value |
282
|
|
|
|
|
|
|
} |
283
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
|
my $text_utf8 = Encode::encode("utf8", $text); |
285
|
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
|
return $self->execute( text => $text_utf8, |
287
|
|
|
|
|
|
|
%lc_options ); |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=head1 SEE ALSO |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
=over 4 |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=item * L |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
=item * L |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=back |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=head1 AUTHOR |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
Tomaz Solc Etomaz@zemanta.comE |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
Copyright (C) 2008 by Zemanta ltd. |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
309
|
|
|
|
|
|
|
the same terms as Perl itself, either Perl version 5.8.7 or, at your option, |
310
|
|
|
|
|
|
|
any later version of Perl 5 you may have available. |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
=cut |