Lingua::EN::Keywords::Yahoo - Automatically extracts keywords from text using the Yahoo! API


Lingua-EN-Keywords-Yahoo documentation Contained in the Lingua-EN-Keywords-Yahoo distribution.

Index


Code Index:

NAME

Top

Lingua::EN::Keywords::Yahoo - Automatically extracts keywords from text using the Yahoo! API

SYNOPSIS

Top

  use Lingua::EN::Keywords::Yahoo qw(keywords);

  my @keywords = keywords($text);

or

  my @keywords = keywords($text, $query);

Where $query is an optional term to help with the extraction process.

DESCRIPTION

Top

This uses the Yahoo! keywords API to extract keywords from text.

To quote the Yahoo! page: "The Term Extraction Web Service provides a list of significant words or phrases extracted from a larger content."

EXPORT

Top

Can export the keywords subroutine.

AUTHOR

Top

Original code by Simon Cozens, <simon@cpan.org>

Packaged by Simon Wistow, <simon@thegestalt.org>

COPYRIGHT

Top

SEE ALSO

Top

The Term Extraction API: http://developer.yahoo.net/search/content/V1/termExtraction.html

Yahoo::Search


Lingua-EN-Keywords-Yahoo documentation Contained in the Lingua-EN-Keywords-Yahoo distribution.

package Lingua::EN::Keywords::Yahoo;

use strict;
use LWP::UserAgent;
use XML::Twig;
use base qw(Exporter);

our $VERSION   = "0.5";
our @EXPORT_OK = qw(keywords);

our $ua;
our $uri = "http://api.search.yahoo.com/ContentAnalysisService/V1/termExtraction";

BEGIN {
    $ua = LWP::UserAgent->new();
};



sub keywords {
    my $content = shift;

    my $q    =  {
        appid => "Perl::Lingua::EN::Keywords::Yahoo",
        context => $content
    };

    $q->{query} = shift if @_;

    my $resp = $ua->post($uri, $q);
    my @terms;
    if ($resp->is_success) { 
        my $xmlt = XML::Twig->new( index => [ "Result" ] );
        $xmlt->parse($resp->content);
        for my $result (@{ $xmlt->index("Result") || []}) {
            push @terms, $result->text;
        }
    }
    return @terms;
}

1;