Ejemplo n.º 1
0
    def stemming_word(self, args):
        stemming_val = []
        for w in args:
            if (len(w) > 4):
                stemming_result = stem(w)
                stemming_val.append(stemming_result)
            else:
                stemming_val.append(w)

        return stemming_val
import sys
import json
from stemming.lovins import stem

# read in the sentiment words
fh = open('sentiment_wordlist.txt','r')
sentiment_wordscores = dict()
pos_words = fh.readline().split(',')
neg_words = fh.readline().split(',')

for w in pos_words:
	sentiment_wordscores[stem(w)] = 1
for w in neg_words:
	sentiment_wordscores[stem(w)] = -1
	
# read in tweets
tweetfile = sys.argv[1]
fh = open(tweetfile,'r')

sentiment = 0

for line in fh:
	try:
		tweet = json.loads(line)
	except:
		break
		
	if 'text' in tweet:
		try:
			text = tweet['text']
			words = text.split()
Ejemplo n.º 3
0
 def safe_stem(word):
     try:
         return stem(word)
     except Exception as e:
         return word
Ejemplo n.º 4
0
import sys
import json
from stemming.lovins import stem

# read in the sentiment words
fh = open('sentiment_wordlist.txt', 'r')
sentiment_wordscores = dict()
pos_words = fh.readline().split(',')
neg_words = fh.readline().split(',')

for w in pos_words:
    sentiment_wordscores[stem(w)] = 1
for w in neg_words:
    sentiment_wordscores[stem(w)] = -1

# read in tweets
tweetfile = sys.argv[1]
fh = open(tweetfile, 'r')

sentiment = 0

for line in fh:
    try:
        tweet = json.loads(line)
    except:
        break

    if 'text' in tweet:
        try:
            text = tweet['text']
            words = text.split()