def countwords(results): count=dict() for value in results["results"]: #get the text from each tweet text=value["text"] #correct ASCII issues text = filter(lambda x: x in string.printable, text) #add space at the end of the line text = text + " " #stem text text1=porterstemmer.stemWords(text) #find all strings that only contains alphabets from the stemming text words=re.findall("[A-Za-z]+",text1) for word in swords: t=words.count(word) if word in count: count[word]+=t else: count[word]=t return count
list=open("sentimentList.txt") #create a dictionary to store stemming words and values swords=dict() for line in list: line=line.strip() #split the line into words by the last comma words=line.rsplit(",") #words[0] is the sentiment word or expression word=words[0] #check if it is an actual word if not word.isalpha(): continue #if it is a word, then run porterstemmer to stem the words line1=porterstemmer.stemWords(line) words1=line.rsplit(",") word=words1[0] value=words1[1] #store the sentiment word/value after stemming into the dictionary swords #ignore the duplicate word if word in swords: continue else: swords[word]=value #create a dictionary to store sentiment word from twitter text and its frequency def countwords(results): count=dict() for value in results["results"]: