diff --git a/Facts b/Facts index 77d461b..4280429 100644 --- a/Facts +++ b/Facts @@ -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 diff --git a/Queries.txt b/Queries.txt index 59246fe..5f117b1 100644 --- a/Queries.txt +++ b/Queries.txt @@ -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 diff --git a/femaleSentiments b/femaleSentiments new file mode 100644 index 0000000..e69de29 diff --git a/sentimentAnalysisFemale.py b/sentimentAnalysisFemale.py index f15bf39..a270044 100644 --- a/sentimentAnalysisFemale.py +++ b/sentimentAnalysisFemale.py @@ -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() + diff --git a/sentimentAnalysisMale.py b/sentimentAnalysisMale.py index 02bde73..9174f35 100644 --- a/sentimentAnalysisMale.py +++ b/sentimentAnalysisMale.py @@ -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()