Skip to content

Instantly share code, notes, and snippets.

@baojie
Created August 27, 2013 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baojie/6359567 to your computer and use it in GitHub Desktop.
Save baojie/6359567 to your computer and use it in GitHub Desktop.
https://pypi.python.org/pypi/textblob Simple, Pythonic text processing. Sentiment analysis, POS tagging, noun phrase parsing, and more.
from text.blob import TextBlob
text = '''
The titular threat of The Blob has always struck me as the ultimate movie
monster: an insatiably hungry, amoeba-like mass able to penetrate
virtually any safeguard, capable of--as a doomed doctor chillingly
describes it--"assimilating flesh on contact.
Snide comparisons to gelatin be damned, it's a concept with the most
devastating of potential consequences, not unlike the grey goo scenario
proposed by technological theorists fearful of
artificial intelligence run rampant.
'''
blob = TextBlob(text)
blob.tags # [(u'The', u'DT'), (u'titular', u'JJ'),
# (u'threat', u'NN'), (u'of', u'IN'), ...]
blob.noun_phrases # WordList(['titular threat', 'blob',
# 'ultimate movie monster',
# 'amoeba-like mass', ...])
for sentence in blob.sentences:
print(sentence.sentiment) # returns (polarity, subjectivity)
# (0.060, 0.605)
# (-0.341, 0.767)
blob.translate(to="es") # 'La amenaza titular de The Blob...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment