WWW::Yahoo::KeywordExtractor - Get keywords from summary text via the Yahoo API


WWW-Yahoo-KeywordExtractor documentation Contained in the WWW-Yahoo-KeywordExtractor distribution.

Index


Code Index:

NAME

Top

WWW::Yahoo::KeywordExtractor - Get keywords from summary text via the Yahoo API

SYNOPSIS

Top

This module will submit content to the Yahoo keyword extractor API to return a list of relevant keywords.

  use WWW::Yahoo::KeywordExtractor;
  my $yke = WWW::Yahoo::KeywordExtractor->new();
  my $keywords = $yke->extract('My wife and I love to cook together. Carolyn surprises me with new things to love about her everyday.');
  print join q{}. 'Keyword 1: ', $keywords->[0], "\n";

SUBROUTINES/METHOD

Top

new

The new subroutine creates and returns a WWW:Yahoo::KeywordExtractor object.

extract

This method will return a list of keywords based on sample data. It will die if there is no 'content' arg given.

Note: In older versions this method would also cache the keywords returned, however this is no longer the case.

AUTHOR

Top

Nick Gerakines, <nick at socklabs.com>

BUGS

Top

Please report any bugs or feature requests to bug-www-yahoo-keywordextractor at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Yahoo-KeywordExtractor. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc WWW::Yahoo::KeywordExtractor

You can also look for information at:

* WWW-Yahoo-KeywordExtractor SVN Repository

http://code.sixapart.com/svn/WWW-Yahoo-KeywordExtractor

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/WWW-Yahoo-KeywordExtractor

* CPAN Ratings

http://cpanratings.perl.org/d/WWW-Yahoo-KeywordExtractor

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Yahoo-KeywordExtractor

* Search CPAN

http://search.cpan.org/dist/WWW-Yahoo-KeywordExtractor

ACKNOWLEDGEMENTS

Top

Thanks to the bright developers at Yahoo for creating a nifty keyword API.

Subbu Allamaraju ( http://www.subbu.org ) gave some good feedback and is also worth mentioning here.

COPYRIGHT & LICENSE

Top


WWW-Yahoo-KeywordExtractor documentation Contained in the WWW-Yahoo-KeywordExtractor distribution.

package WWW::Yahoo::KeywordExtractor;

use strict;
use warnings;

use LWP::UserAgent;

use constant KEYWORD_API_URL => 'http://api.search.yahoo.com/ContentAnalysisService/V1/termExtraction';

our $VERSION = '0.5';

sub new {
	my ($class, %args) = @_;
	my $self = bless {%args}, $class;
	return $self;
}

sub extract {
    my ($self, $content) = @_;
    if (! $content) { die 'No content specified'; }
    my $ua = LWP::UserAgent->new();
    my $response = $ua->post(
        KEYWORD_API_URL,
        { 'appid' => 'WWWYahooKeywordExtractor',
        'query' => 'null',
        'context' => $content, }
    );
    if (! $response->is_success()) {
    	die "Error getting data!\n";
    }
    my $xml = $response->content();
    my @results = ();
    while ($xml =~ m!<Result>([^<]*)</Result>!g) {
        push @results, $1;
    }
    return \@results;
}

1;
__END__