Changeset 303dbc1


Ignore:
Timestamp:
Jun 22, 2011, 9:56:46 PM (10 years ago)
Author:
Edward Z. Yang <ezyang@mit.edu>
Children:
6dccccf
Parents:
6c3d4ad
git-author:
Edward Z. Yang <ezyang@mit.edu> (06/20/11 12:03:35)
git-committer:
Edward Z. Yang <ezyang@mit.edu> (06/22/11 21:56:46)
Message:
Add alternate implementation of keywords.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perl/modules/Facebook/lib/BarnOwl/Module/Facebook/Handle.pm

    r6c3d4ad r303dbc1  
    1616use Facebook::Graph;
    1717
    18 use Lingua::EN::Keywords;
     18use List::Util qw(reduce);
     19
     20eval { require Lingua::EN::Keywords; };
     21if ($@) {
     22    *keywords = sub {
     23        # stupidly pick the longest one, and only return one.
     24        my $sentence = shift;
     25        $sentence =~ s/[[:punct:]]//g;
     26        my @words = split(' ', lc($sentence));
     27        return () unless @words;
     28        return (reduce{ length($a) > length($b) ? $a : $b } @words,);
     29    };
     30} else {
     31    *keywords = \&Lingua::EN::Keywords::keywords;
     32}
    1933
    2034use JSON;
Note: See TracChangeset for help on using the changeset viewer.