diff --git a/Test.py b/Test.py new file mode 100644 index 0000000000000000000000000000000000000000..450c17078419c4166e4fc920bf2f55033110c2f7 --- /dev/null +++ b/Test.py @@ -0,0 +1,10 @@ +import unittest + + +class MyTestCase(unittest.TestCase): + def test_sentim(self): + self.assertEqual(method_11) + + +if __name__ == '__main__': + unittest.main() diff --git a/sentiment.py b/sentiment.py index c1acbd0bd072884da45768147d30c6ecc0c92da3..3ffb8ac46cbe2fc938463c398b2c8146dd680faf 100644 --- a/sentiment.py +++ b/sentiment.py @@ -4,28 +4,19 @@ from builtins import input def main(): - average = list() + reviews=list() try: with open('sentiment.txt') as s: reviews = list(s) - print(len(reviews)) + # print(len(reviews)) except OSError: print('Does not exist') sentiments={} - for review in reviews: - words = review.split() - 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'])) + word = method_11(reviews, sentiments) + #print(len(sentiments['arty'])) # x = input("Enter a word") # if x in sentiments: # @@ -69,6 +60,7 @@ def main(): y=x, num=0, av='None' ) print(output) + average = list() if y==2 or y==3: file=input('Enter a file') try: @@ -95,68 +87,50 @@ def main(): else: 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)) - except IOError: - print('File could not be found') - - - if y==3: - rating = sum(sentiments[x])/len(sentiments[x]) - highest_score = max(average) - lowest_score = min(average) - - - for file_word, rate in rating.items(): - if rate == highest_score: - j = file_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)) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + if y==3: + #rating = sum(sentiments[x])/len(sentiments[x]) + split_file= file.split() + # + highest_score = max(average) + lowest_score = min(average) + p= average.append(sum_word) + for check_word in split_file: + if check_word in sentiments: + method_11(check_word) + sum_word = sum(method_11(check_word))/len(method_11(check_word)) + 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__': diff --git a/test_method_11.py b/test_method_11.py new file mode 100644 index 0000000000000000000000000000000000000000..e0c1744eb6a1d93770668ecc3559cbd6117cf50e --- /dev/null +++ b/test_method_11.py @@ -0,0 +1,6 @@ +from unittest import TestCase + + +class TestMethod_11(TestCase): + def test_method_11(self,reviews,sentiments): + self.assertEqual(['arty'], )