Skip to content

Commit

Permalink
Sentiment queires added for section wise count
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinbhy committed Mar 22, 2018
1 parent da38c4b commit 7fef7ba
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 33 deletions.
7 changes: 7 additions & 0 deletions Facts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ from
(select section,webURL from articles group by section,webURL) as t1 LEFT OUTER JOIN
comments c ON c.assetURL=t1.webURL
group by section


U.S. 77302
World 72599
Sports 49454
Business Day 39859
Arts 15226
13 changes: 13 additions & 0 deletions Queries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ from
(select section,webURL from articles group by section,webURL) as t1 LEFT OUTER JOIN
comments c ON c.assetURL=t1.webURL where section is not NULL
group by section



Section wise sentiment count
select section,count(*) as total,COUNT(CASE WHEN cs.gender = 'male' then 1 ELSE NULL END) as "Male_Count",
COUNT(CASE WHEN cs.gender = 'male' and cs.sentiment=-1 then 1 ELSE NULL END) as "Male_Negative",
COUNT(CASE WHEN cs.gender = 'male' and cs.sentiment=1 then 1 ELSE NULL END) as "Male_Positive",
COUNT(CASE WHEN cs.gender = 'male' and cs.sentiment=0 then 1 ELSE NULL END) as "Male_Neutral",
COUNT(CASE WHEN cs.gender = 'female' then 1 ELSE NULL END) as "Female_Count",
COUNT(CASE WHEN cs.gender = 'female' and cs.sentiment=-1 then 1 ELSE NULL END) as "Female_Negative",
COUNT(CASE WHEN cs.gender = 'female' and cs.sentiment=1 then 1 ELSE NULL END) as "Female_Positive",
COUNT(CASE WHEN cs.gender = 'female' and cs.sentiment=0 then 1 ELSE NULL END) as "Female_Neutral"
from articles a,comments c,CommentSent cs where c.commentID=cs.commentID and a.webURL=c.assetURL and section in ('U.S.','World','Sports','Business Day','Arts') group by section
Empty file added femaleSentiments
Empty file.
33 changes: 21 additions & 12 deletions sentimentAnalysisFemale.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,41 @@
db = sqlite3.connect('../commentsData.db')
c = db.cursor()

c.execute("select commentBody,g.gender from comments c,commenterGender g where c.userID=g.userID and\

c.execute("CREATE TABLE IF NOT EXISTS CommentSent (commentID int,sentiment int,gender text,PRIMARY KEY (commentID))")


c.execute("select commentBody,g.gender,commentID from comments c,commenterGender g where c.userID=g.userID and\
c.username=g.username and gender='female' ")

malePositive=0
maleNegative=0
maleNeutral=0
femalPositive=0
femaleNegative=0
femaleNeutral=0
progress=0
sqlstat="insert into CommentSent values(?,?,?)"

f=open("femaleSentiments","w")
progress=0


for t in c.fetchall():
progress+=1
comment=t[0]
gen=t[1]
comID=t[2]
com=TextBlob(comment)

polar=com.sentiment.polarity

sent=0
if gen == 'female':
f.write(str(polar)+"\n")
if polar <= -0.2:
sent=-1
elif polar >= 0.2:
sent=1
else:
sent=0

c.execute(sqlstat,(comID,sent,'female'))

if progress%10000==0:
print progress," Comments processed"
f.close()

db.commit()
db.close()


48 changes: 27 additions & 21 deletions sentimentAnalysisMale.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,38 @@
db = sqlite3.connect('../commentsData.db')
c = db.cursor()

c.execute("select commentBody,g.gender from comments c,commenterGender g where c.userID=g.userID and\
c.username=g.username and gender='male' ")
c.execute("CREATE TABLE IF NOT EXISTS CommentSent (commentID int,sentiment int,gender text,PRIMARY KEY (commentID))")

malePositive=0
maleNegative=0
maleNeutral=0
femalPositive=0
femaleNegative=0
femaleNeutral=0
progress=0
c.execute("select commentBody,g.gender,commentID from comments c,commenterGender g where c.userID=g.userID and\
c.username=g.username and gender='male' ")

f=open("maleSentiments","w")
sqlstat = "insert into CommentSent values(?,?,?)"

progress = 0

for t in c.fetchall():
progress+=1
comment=t[0]
gen=t[1]
com=TextBlob(comment)
progress += 1
comment = t[0]
gen = t[1]
comID = t[2]
com = TextBlob(comment)

polar = com.sentiment.polarity
sent = 0
if gen == 'male':
if polar <= -0.2:
sent = -1
elif polar >= 0.2:
sent = 1
else:
sent = 0

polar=com.sentiment.polarity
c.execute(sqlstat, (comID, sent, 'male'))

if progress % 10000 == 0:
print progress, " Comments processed"

db.commit()
db.close()

if gen == 'male':
f.write(str(polar)+"\n")

if progress%10000==0:
print progress," Comments processed"
f.close()

0 comments on commit 7fef7ba

Please sign in to comment.