Yahoo::CAS - Yahoo::CAS documentation


Yahoo-CAS documentation Contained in the Yahoo-CAS distribution.

Index


Code Index:

NAME

Top

Yahoo::CAS is a simple interface for Yahoo! Asia keyword segment and TVS open APIs.

VERSION

Top

This document describes version 0.1 of Yahoo::CAS , released January 16, 2008.

SYNOPSIS

Top

use Yahoo::CAS;

$cas = Yahoo::CAS({ appid => "Ea6oQPHIkY03GklWeauQHWPpPJByMjCDoxRxcW"}); $res = $cas->ws({content => '..........'); $list = $cas->ke({thredhold => '30', maxnum => '10', content => '...'); print $res->{token} for (keys %{$Segment}); print $res->{token} for (keys %{$Keyword});

DESCRIPTION

Top

Yahoo! Asia provides open APIs for segment and keyword extract for an article. The ws is for segment and the ke is for the concept extract of article. So you just need to apply the appid and then you can use it very easy.

METHODS

Top

For more methods, please just refer the Yahoo! Developers Network in Taiwan. <http://tw.developer.yahoo.com/cas/api.php>

AUTHORS

Top

Hsin-Chan Chien <hcchien@hcchien.org>

COPYRIGHT

Top


Yahoo-CAS documentation Contained in the Yahoo-CAS distribution.

package Yahoo::CAS;

use strict;
use LWP;
use XML::Simple;

our $VERSION = '0.2';

sub new {
    my $self = shift;
    my $param = shift;
    my $appid = $param->{appid};
    my $version = 'v1';
    my $url = 'http://asia.search.yahooapis.com/cas/';
    my $request = "$url.$version/";
    bless ( { 
	    version => $version, 
	    url => $url, 
	    appid => $appid,
	    request => $request }, 
	$self);
}

sub ws {
    my $self= shift;
    my $param = shift;
    my $content = $param->{content};
    my $request = { url => $self->{request}."ws", content => $content };
    my $response = XMLin($self->_get($request));
    if (exists($response->{WordSegmentationResult})) {
	return $response->{WordSegmentationResult};
    } else {
	return 0;
    }
}

sub ke {
    my $self= shift;
    my $param = shift;
    my $content = $param->{content};
    my $threshold = $param->{threshold};
    my $maxnum = $param->{maxnum};
    my $request = { url => $self->{request}."ke", content => "content=$content&threshold=$threshold&maxnum=$maxnum" };
    my $response = XMLin($self->_get($request));
    if (exists($response->{KeywordExtractionResult})) {
	return $response->{KeywordExtractionResult};
    } else {
	return 0;
    }
}

sub _get {
    my $self = shift;
    my $request = shift;
    my $req = HTTP::Request->new(POST => $request->{url});
    $req->content_type('application/x-www-form-urlencoded');
    $req->{content} = $request->{content}."&appid=".$self->{appid};
    my $res = $req->request($req);
    if ($res->is_success) {
	return $res->content;
    } else {
	return $res->status_line;
    }
}


1;

__END__