Skip to content

Commit

Permalink
review sentiment working
Browse files Browse the repository at this point in the history
  • Loading branch information
seekshreyas committed Dec 3, 2013
1 parent 28231bd commit 17e134a
Show file tree
Hide file tree
Showing 7 changed files with 4,073,744 additions and 14 deletions.
73 changes: 61 additions & 12 deletions classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
import random
import math
import nltk
from cPickle import dump
from cPickle import load
import parser
import extractor

def getUserInput():
optionparser = OptionParser()
Expand Down Expand Up @@ -52,14 +56,20 @@ def featureAggregator(extract):
def featureExtractor(app):
featDict = {}

# featList['price'] = getAppPrice(app)
fObj = open('mySentClassifier.pickle')
cl = load(fObj)
fObj.close()


featDict['price'] = getAppPrice(app)
# featList['numrev'] = getNumReviews(app)
featDict['1starrating'] = getOneStarRating(app)
featDict['2starrating'] = getTwoStarRating(app)
featDict['3starRating'] = getThreeStarRating(app)
featDict['4starRating'] = getFourStarRating(app)
featDict['5starRating'] = getFiveStarRating(app)
featDict['hasPrivacy'] = getPrivacyState(app)
featDict['revSent'] = getReviewSentiment(app, cl)

return featDict

Expand Down Expand Up @@ -104,12 +114,46 @@ def getFiveStarRating(app):


def getPrivacyState(app):
if app['devprivacyurl'] == 'N.A':
if app['devprivacyurl'] == 'N.A.':
return False
else:
return True



def getReviewSentiment(app, classifier):
revAggSentiment = 0
for rev in app['reviews']:
sentList = nltk.tokenize.sent_tokenize(rev[1])

sentAggSentiment = 0

for sent in sentList:

sent = unicode(sent.strip())
# print sent
featdata = extractor.featureExtractor(sent)

# pprint(featdata)
cl= classifier.classify(featdata)

if cl == 'pos':
label = 1
elif cl == 'neutral':
label = 0
else:
label = -1

sentAggSentiment += label

revAggSentiment += sentAggSentiment
print "review Sentiment: ", revAggSentiment

return revAggSentiment




def classifier(extract, fold=10):

labeldata = 'fair'
Expand All @@ -121,28 +165,31 @@ def classifier(extract, fold=10):

# print "reviews" , revlower
if revlower.find('fake') != -1:

labeldata = 'unfair'

features = featureExtractor(app)

data.append([labeldata, list(features.values())])


# pprint(data)
pprint(data)

# for d in data:
# if d[1][1] == False:
# pprint(d)

random.shuffle(data)
# random.shuffle(data)

claccuracy = []
size = int(math.floor(len(data) / 10.0))
# claccuracy = []
# size = int(math.floor(len(data) / 10.0))

for i in range(fold):
test_this_round = data[i*size:][:size]
train_this_round = data[:i*size] + data[(i+1)*size:]
# for i in range(fold):
# test_this_round = data[i*size:][:size]
# train_this_round = data[:i*size] + data[(i+1)*size:]

acc = myclassifier(train_this_round, test_this_round)
# acc = myclassifier(train_this_round, test_this_round)

claccuracy.append(acc)
# claccuracy.append(acc)



Expand All @@ -159,6 +206,8 @@ def myclassifier(train_data, test_data):





def main():
userinput = getUserInput()
print userinput['file']
Expand Down
3 changes: 1 addition & 2 deletions exports/trayvon_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{"category": "Arcade & Action",
"company": "Trade Digital, Inc",
"contentRating": "High Maturity",
"description": "Trayvon is angry and nobody can stop him from completing his world tour of revenge on the bad guys who terrorize cities everyday. Use a variety of weapons to demolish Trayvons attackers in various cities around the world.As you complete a level, you will notice more bad guys coming at
at a faster pace and a deadlier attack.If you like to attack from far, then purchase the 'dagger' as you will be able to throw it at your enemies for the kill. If you want to dominate the leaderboards across the world, then make sure you collect the money that the bad guys will drop once you kill them to increase your score.(This game is fiction and does not represent any real persons)",
"description": "Trayvon is angry and nobody can stop him from completing his world tour of revenge on the bad guys who terrorize cities everyday. Use a variety of weapons to demolish Trayvons attackers in various cities around the world.As you complete a level, you will notice more bad guys coming at a faster pace and a deadlier attack.If you like to attack from far, then purchase the 'dagger' as you will be able to throw it at your enemies for the kill. If you want to dominate the leaderboards across the world, then make sure you collect the money that the bad guys will drop once you kill them to increase your score.(This game is fiction and does not represent any real persons)",
"id": "air.AngryTravonAndroid",
"install": "100 - 500",
"moreFromDev": "None",
Expand Down
Loading

0 comments on commit 17e134a

Please sign in to comment.