Skip to content
Snippets Groups Projects
Commit 48ae8dcd authored by Adrian Reza  Ariffin's avatar Adrian Reza Ariffin
Browse files

Final program finished

parent f8a17498
Branches
No related tags found
No related merge requests found
TEST.py 0 → 100644
from unittest import TestCase
import sentiment
class TestPreloading(TestCase):
def test_preloading(self):
example = ['3 In its own floundering way , it gets to you .', '3 Audacious-impossible yet compelling .']
self.assertEquals(sentiment.preloading(example), (
{',': ['3'], '.': ['3', '3'], 'Auda3cious-impossible': ['3'], 'In': ['3'], 'compelling': ['3'],
'floundering': ['3'], 'gets': ['3'], 'it': ['3'], 'its': ['3'], 'own': ['3'], 'to': ['3'], 'way': ['3'],
'yet': ['3'], 'you': ['3']}))
def test_2(self):
example = ['0 never will this fail the testing .']
self.assertEquals(sentiment.preloading(example), (
{'testing': ['0'], 'this': ['0'], 'never': ['0'], '.': ['0'], 'will': ['0'], 'fail': ['0'], 'the': ['0']}))
def test_preloading12(self):
try:
with open("sentiment.txt") as file:
loading = file.read()
raw_file = loading.split('\n')
except IOError:
print("File Not Found")
average = 0
number = 0
average, number =sentiment.option1(raw_file, 'arty')
print(number)
self.assertEquals(number, 'None')
......@@ -15,13 +15,13 @@ def main():
print("File Not Found")
review= preloading(raw_file)
number = 0
print("\nEnter your choice:\n1: Get the score of a word\n2: Get the average score of words in a file (one word per line)\n3: Find the highest/lowest scoring words in a file\n4: Sort words from a file into positive.txt and negative.txt\n5: Exit the program\n")
choice = choice_input()
if choice is 1 :
key = input("Enter word to search :\n")
average = score_of_word(review,key)
print("\nScore of \"",key,"\" is ",average,"\n")
average,number = option1(review,key)
print("\nScore of \"",key,"\" appears",number," times with an average sentiment of ",average,"\n")
elif choice is 2 :
average_score(review)
elif choice is 3:
......@@ -39,7 +39,7 @@ def preloading(raw_input):
for i in range(0, len(raw_input)): #iterates over the line
tokens = raw_input[i].split()
for index in range(0, len(tokens)):#iterates over the word
for index in range(1, len(tokens)):#iterates over the word
if tokens[index] not in reviews:
reviews[tokens[index]]= [tokens[0]]
else:
......@@ -59,6 +59,25 @@ def choice_input():
except ValueError:
print("Invalid input\n")
def option1(review,key):
total_result=0
number=0
if key in review:
temp=review[key]
else:
return None , None
for total in temp:
total_result += int(total)
number+=1
average = total_result/len(temp)
if average>0:
return average,number
else:
return None, None
def score_of_word(review,key):
total_result=0
......
from unittest import TestCase
import sentiment
class TestPreloading(TestCase):
def test_preloading(self):
example = ['3 In its own floundering way , it gets to you .','3 Audacious-impossible yet compelling .']
self.assertEquals(sentiment.preloading(example),({'hello':'0' , 'this':'2', 'is': '3', 'a':'1'}))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment