Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch 'master' of https://github.uconn.edu/job13011/BigData
- Loading branch information
Showing
9 changed files
with
4,262 additions
and
67,055 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import division | ||
import sys | ||
import time | ||
|
||
import nltk | ||
from nltk.corpus import movie_reviews | ||
from nltk.corpus import sentiwordnet as swn | ||
from nltk.corpus import wordnet as wn | ||
|
||
start_time = time.time() | ||
count = 0.00 | ||
correct = 0.00 | ||
ids = sorted(movie_reviews.fileids()) | ||
|
||
for reviews in ids: #For every review | ||
score = 0.0 | ||
positive = 0.0 | ||
negative = 0.0 | ||
tokens = nltk.pos_tag(nltk.word_tokenize(movie_reviews.raw(fileids=[reviews]))) #Tokenize all words with POS | ||
for token in tokens: | ||
if (token[1]== "JJ" or token[1] == "JJR" or token[1] == "JJS"): # If adjective, check value | ||
if len(wn.synsets(token[0], pos=wn.ADJ)) != 0 and swn.senti_synset(wn.synsets(token[0], pos=wn.ADJ)[0].name()) : | ||
word = wn.synsets(token[0], pos=wn.ADJ)[0].name() | ||
print word | ||
print swn.senti_synset(word) | ||
positive = positive + swn.senti_synset(word).pos_score() | ||
negative = negative + swn.senti_synset(word).neg_score() | ||
print "%s, %d, %d" %(word,positive,negative) | ||
score = positive - negative | ||
if (score < 0): | ||
print "Negative at %f" % (score) | ||
sentiment = 'neg' | ||
else: | ||
sentiment = 'pos' | ||
print "Positive at %d" % (score) | ||
if (sentiment == movie_reviews.categories(fileids=[reviews])[0]): | ||
print "Correct" | ||
correct = correct + 1.00 | ||
count = count + 1.00 | ||
|
||
print correct/count | ||
print "Seconds: %d" %(time.time() - start_time) | ||
print "correct:", correct/len(ids) | ||
print "positive:", positive/len(ids) |
Oops, something went wrong.