Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
veeragandhi authored May 15, 2017
1 parent d50efa0 commit e9db0b6
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
69 changes: 69 additions & 0 deletions CalculateCredibilityMapperDate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python



import sys,math,nltk,itertools

def readFileandReturnAnArray(fileName, readMode, isLower):
myArray=[]
with open(fileName, readMode) as readHandle:
for line in readHandle.readlines():
lineRead = line
if isLower:
lineRead = lineRead.lower()
myArray.append(lineRead.strip().lstrip())
readHandle.close()
return myArray



for line in sys.stdin:
try:
line = line.strip()
#if line!="" and line is not None:
date = line[-12:]
line = line[:-12]
Tokens = nltk.word_tokenize(line)
cnt = len(Tokens)
sample_space = cnt * cnt
if sample_space!=0:
individual = (float((2 * cnt) - 1)) / (sample_space)
topicfiles = ["foodtopic1", "foodtopic2", "foodtopic3"]
for i in topicfiles:
alphabet = readFileandReturnAnArray(i, "r", True)
topicId = alphabet.pop(0)
for subset in itertools.combinations(alphabet, 2):
if subset.__len__() != 0:
first = Tokens.count(subset[0])
words = nltk.word_tokenize(subset[0])
if(words.__len__()==2):
cnt1 = Tokens.count(words[0])
cnt2 = Tokens.count(words[1])
if (cnt1 == cnt2):
first = cnt1
elif (cnt1 < cnt2):
first = cnt1
else:
first = cnt2
second = Tokens.count(subset[1])
words1 = nltk.word_tokenize(subset[1])
if (words1.__len__() == 2):
cnt1 = Tokens.count(words1[0])
cnt2 = Tokens.count(words1[1])
if (cnt1 == cnt2):
second = cnt1
elif (cnt1 < cnt2):
second = cnt1
else:
second = cnt2
result = 0
if first != 0 and second != 0:
intermediate = 2.00/sample_space
firstresult = (float(first)) * intermediate
secresult = (float(second)) * intermediate
combine = float(firstresult) + secresult
final = (float(combine)) / (individual * individual)
result = math.log(final)
print '%s\t%s\t%s' % (topicId, result, date)
except ValueError:
continue
33 changes: 33 additions & 0 deletions CalculateObjectivityMapperDate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

from textblob import TextBlob

import sys

def readFileandReturnAnArray(fileName, readMode, isLower):
myArray=[]
with open(fileName, readMode) as readHandle:
for line in readHandle.readlines():
lineRead = line
if isLower:
lineRead = lineRead.lower()
myArray.append(lineRead.strip().lstrip())
readHandle.close()
return myArray



for line in sys.stdin:
line = line.strip()
if line!="" and line is not None:
date = line[-12:]
line = line[:-12]
tweets_text=line
topicfiles = ["foodtopic1", "foodtopic2", "foodtopic3"]
for i in topicfiles:
alphabet = readFileandReturnAnArray(i, "r", True)
topicId = alphabet.pop(0)
for symbol in alphabet:
if symbol in tweets_text :
objectivityTruthful = TextBlob(tweets_text)
print '%s\t%s\t%s' % (topicId, objectivityTruthful.subjectivity,date)
35 changes: 35 additions & 0 deletions CalculateTruthfulnessMapperDate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python



from textblob import TextBlob

import sys

def readFileandReturnAnArray(fileName, readMode, isLower):
myArray=[]
with open(fileName, readMode) as readHandle:
for line in readHandle.readlines():
lineRead = line
if isLower:
lineRead = lineRead.lower()
myArray.append(lineRead.strip().lstrip())
readHandle.close()
return myArray



for line in sys.stdin:
line = line.strip()
if line!="" and line is not None:
date = line[-12:]
line = line[:-12]
tweets_text=line
topicfiles = ["foodtopic1", "foodtopic2", "foodtopic3"]
for i in topicfiles:
alphabet = readFileandReturnAnArray(i, "r", True)
topicId = alphabet.pop(0)
for symbol in alphabet:
if symbol in tweets_text:
objectivityTruthful = TextBlob(tweets_text)
print '%s\t%s\t%s' % (topicId, objectivityTruthful.polarity,date)

0 comments on commit e9db0b6

Please sign in to comment.