Skip to content
Snippets Groups Projects
Commit 45063937 authored by Sam Neupane's avatar Sam Neupane
Browse files

hw

parent 7e3eca38
No related branches found
No related tags found
No related merge requests found
Test.py 0 → 100644
import unittest
class MyTestCase(unittest.TestCase):
def test_sentim(self):
self.assertEqual(method_11)
if __name__ == '__main__':
unittest.main()
...@@ -4,28 +4,19 @@ from builtins import input ...@@ -4,28 +4,19 @@ from builtins import input
def main(): def main():
average = list()
reviews=list() reviews=list()
try: try:
with open('sentiment.txt') as s: with open('sentiment.txt') as s:
reviews = list(s) reviews = list(s)
print(len(reviews)) # print(len(reviews))
except OSError: except OSError:
print('Does not exist') print('Does not exist')
sentiments={} sentiments={}
for review in reviews: word = method_11(reviews, sentiments)
words = review.split() #print(len(sentiments['arty']))
for word in words:
if word != review[0]:
if word in sentiments.keys():
sentiments[word].append(int(review[0]))
else:
sentiments[word] = list()
sentiments[word].append(int(review[0]))
print(sentiments['arty'])
print(len(sentiments['arty']))
# x = input("Enter a word") # x = input("Enter a word")
# if x in sentiments: # if x in sentiments:
# #
...@@ -69,6 +60,7 @@ def main(): ...@@ -69,6 +60,7 @@ def main():
y=x, num=0, av='None' y=x, num=0, av='None'
) )
print(output) print(output)
average = list()
if y==2 or y==3: if y==2 or y==3:
file=input('Enter a file') file=input('Enter a file')
try: try:
...@@ -95,68 +87,50 @@ def main(): ...@@ -95,68 +87,50 @@ def main():
else: else:
print ('The average score of words in {y} is {av}'.format(y=file, av=average_words)) print ('The average score of words in {y} is {av}'.format(y=file, av=average_words))
print('The overall sentiment of {y} is neutral'.format(y=file)) print('The overall sentiment of {y} is neutral'.format(y=file))
except IOError:
print('File could not be found')
if y==3: if y==3:
rating = sum(sentiments[x])/len(sentiments[x]) #rating = sum(sentiments[x])/len(sentiments[x])
split_file= file.split()
#
highest_score = max(average) highest_score = max(average)
lowest_score = min(average) lowest_score = min(average)
p= average.append(sum_word)
for check_word in split_file:
for file_word, rate in rating.items(): if check_word in sentiments:
if rate == highest_score: method_11(check_word)
j = file_word sum_word = sum(method_11(check_word))/len(method_11(check_word))
if rate == lowest_score:
y == file_word
print ('The most positive word is {phrase} with a score of {j}'.format(phrase=j, j=highest_score))
print('The most negative word is {phrase} with a score of {min}'.format(phrase=y, min=lowest_score))
for file_word, rate in sum_word.items():
if rate == highest_score:
j = file_word
if rate == lowest_score:
j== file_word
print ('The most positive word is {phrase} with a score of {j}'.format(phrase=j, j=highest_score))
print('The most negative word is {phrase} with a score of {min}'.format(phrase=j, min=lowest_score))
except IOError:
print('File could not be found')
def method_11(reviews, sentiments):
for review in reviews:
words = review.split()
for word in words:
if word != review[0]:
if word in sentiments:
sentiments[word].append(int(review[0]))
else:
sentiments[word] = list()
sentiments[word].append(int(review[0]))
# print(sentiments['arty'])
return word
if __name__ == '__main__': if __name__ == '__main__':
......
from unittest import TestCase
class TestMethod_11(TestCase):
def test_method_11(self,reviews,sentiments):
self.assertEqual(['arty'], )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment