tweet as your opinion

import sysimport twython
#from nltk.corpus import wordnet as wn
#import nltk
nounsstring = open("Nouns.txt", "r").read()
adjectivesstring = open("Adjectives.txt", "r").read()

nouns = list()
adjectives = list()

nouns = nounsstring.split("\r\n")
adjectives = adjectivesstring.split("\n")
#print nouns

results = dict()
def isNoun(word):
	if word == "":
		return False
	if word.lower() in nouns:
		return True
	else:
		return False

def isAdjective(word):
	if word == "":
		return False
	if word.lower() in adjectives:
		return True
	else:
		return False

api_key, api_secret, access_token, token_secret = sys.argv[1:]

twitter = twython.Twython(api_key, api_secret, access_token, token_secret)
response = twitter.get_user_timeline(screen_name='aparrish', count=200)

for tweet in response:
	mynouns = list()
	myadjectives = list()
	if tweet['retweeted'] is False and tweet['text'][0:2] != "RT":
	  #print tweet['text']
	  words = tweet['text'].split(" ")
	  for word in words:
	  	if isNoun(word):
	  		mynouns.append(word)
	  		#print word + " is noun"
	  	elif isAdjective(word):
	  		myadjectives.append(word)
	  		#print word + " is adjective"
	for noun in mynouns:
		nounindex = words.index(noun)
		for adjective in myadjectives:
			adjectiveindex = words.index(adjective)
			if adjectiveindex < nounindex:
				results[noun] = adjective

print "MY RESULTS"
for key in results:
	print results[key] + "\t\t" + key

Basically, I was trying to get every tweet (in the case above, I got 200 tweets) from an account, and pick up the nouns and adjectives from each tweet, then matched them together in a corresponding way to show the writer's opinions toward different objects (nouns).

I downloaded the nouns list and adjectives list from the Internet, by checking the words in tweets with words in nouns and adjectives list, python will pick the words in tweets as nouns or adjectives and match them together.

01DE6B30-5E43-473A-80B6-BAD7C616FBAE B2916150-6894-4287-AE5A-C214D9D42E5B01DE6B30-5E43-473A-80B6-BAD7C616FBAE

 

To be honest, I was not that satisfied about the outcomes. Because it is really hard to cover one's taste by using limited pieces of words. I have been thinking about making more structures and logics to make the outcomes more reasonable and accurate. However, I found that the grammar and many idiomatic expressions are totally beyond my power. Anyway, it was a good shot for me to further this idea and deepen my thesis idea as well. Maybe it works not good, but the experience I have got from this mid-term project would definitely be helpful for me to do some other experiments along with this idea.