line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Yahoo::CAS; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25366
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
4
|
1
|
|
|
1
|
|
2304
|
use LWP; |
|
1
|
|
|
|
|
85010
|
|
|
1
|
|
|
|
|
155
|
|
5
|
1
|
|
|
1
|
|
536
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.2'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
|
|
|
|
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
my $param = shift; |
12
|
|
|
|
|
|
|
my $appid = $param->{appid}; |
13
|
|
|
|
|
|
|
my $version = 'v1'; |
14
|
|
|
|
|
|
|
my $url = 'http://asia.search.yahooapis.com/cas/'; |
15
|
|
|
|
|
|
|
my $request = "$url.$version/"; |
16
|
|
|
|
|
|
|
bless ( { |
17
|
|
|
|
|
|
|
version => $version, |
18
|
|
|
|
|
|
|
url => $url, |
19
|
|
|
|
|
|
|
appid => $appid, |
20
|
|
|
|
|
|
|
request => $request }, |
21
|
|
|
|
|
|
|
$self); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub ws { |
25
|
|
|
|
|
|
|
my $self= shift; |
26
|
|
|
|
|
|
|
my $param = shift; |
27
|
|
|
|
|
|
|
my $content = $param->{content}; |
28
|
|
|
|
|
|
|
my $request = { url => $self->{request}."ws", content => $content }; |
29
|
|
|
|
|
|
|
my $response = XMLin($self->_get($request)); |
30
|
|
|
|
|
|
|
if (exists($response->{WordSegmentationResult})) { |
31
|
|
|
|
|
|
|
return $response->{WordSegmentationResult}; |
32
|
|
|
|
|
|
|
} else { |
33
|
|
|
|
|
|
|
return 0; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub ke { |
38
|
|
|
|
|
|
|
my $self= shift; |
39
|
|
|
|
|
|
|
my $param = shift; |
40
|
|
|
|
|
|
|
my $content = $param->{content}; |
41
|
|
|
|
|
|
|
my $threshold = $param->{threshold}; |
42
|
|
|
|
|
|
|
my $maxnum = $param->{maxnum}; |
43
|
|
|
|
|
|
|
my $request = { url => $self->{request}."ke", content => "content=$content&threshold=$threshold&maxnum=$maxnum" }; |
44
|
|
|
|
|
|
|
my $response = XMLin($self->_get($request)); |
45
|
|
|
|
|
|
|
if (exists($response->{KeywordExtractionResult})) { |
46
|
|
|
|
|
|
|
return $response->{KeywordExtractionResult}; |
47
|
|
|
|
|
|
|
} else { |
48
|
|
|
|
|
|
|
return 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub _get { |
53
|
|
|
|
|
|
|
my $self = shift; |
54
|
|
|
|
|
|
|
my $request = shift; |
55
|
|
|
|
|
|
|
my $req = HTTP::Request->new(POST => $request->{url}); |
56
|
|
|
|
|
|
|
$req->content_type('application/x-www-form-urlencoded'); |
57
|
|
|
|
|
|
|
$req->{content} = $request->{content}."&appid=".$self->{appid}; |
58
|
|
|
|
|
|
|
my $res = $req->request($req); |
59
|
|
|
|
|
|
|
if ($res->is_success) { |
60
|
|
|
|
|
|
|
return $res->content; |
61
|
|
|
|
|
|
|
} else { |
62
|
|
|
|
|
|
|
return $res->status_line; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |