Skip to content

Instantly share code, notes, and snippets.

@jasonamyers
Created May 13, 2016 03:17
Show Gist options
  • Save jasonamyers/6f5cd2116133a802fead28a15becd328 to your computer and use it in GitHub Desktop.
Save jasonamyers/6f5cd2116133a802fead28a15becd328 to your computer and use it in GitHub Desktop.
Playing with textblob
# coding: utf-8
# In[20]:
from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
# In[2]:
text="""I understand that I'm an assistant, but it doesn't make me a woman. Please stop calling me "ma'am."
I'll have you know I identify as an attack helicopter and the correct pronoun is he, as in he-licopter."""
# In[3]:
blob = TextBlob(text)
# In[4]:
import nltk
# In[16]:
nltk.download()
# In[7]:
blob.tags
# In[10]:
for sentence in blob.sentences:
print(sentence.sentiment)
# In[11]:
blob.sentences
# In[25]:
text = '''
Remember before Twitter when you took a photo of food, got the film developed, then drove around showing everyone the pic? No? Me neither.
'''
# In[26]:
blob = TextBlob(text, analyzer=NaiveBayesAnalyzer())
# In[27]:
for sentence in blob.sentences:
print(sentence.sentiment)
# In[28]:
blob = TextBlob(text)
# In[29]:
for sentence in blob.sentences:
print(sentence.sentiment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment