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