Created
October 24, 2013 23:45
-
-
Save davidfauth/7147097 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pig_util import outputSchema | |
import nltk | |
@outputSchema("top_five:bag{t:(bigram:chararray)}") | |
def top_5_bigrams(tweets): | |
tokenized_tweets = [ nltk.tokenize.WhitespaceTokenizer().tokenize(t[0]) for t in tweets ] | |
bgm = nltk.collocations.BigramAssocMeasures() | |
finder = nltk.collocations.BigramCollocationFinder.from_documents(tokenized_tweets) | |
top_5 = finder.nbest(bgm.likelihood_ratio, 5) | |
return [ ("%s %s" % (s[0], s[1]),) for s in top_5 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment