Skip to content
Snippets Groups Projects

Ians branch

Closed courtneymflohr requested to merge courtneymflohr/sentiment:ians_branch into master
2 files
+ 74
1
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 63
1
@@ -12,8 +12,70 @@ class MenuOption(Enum):
EXIT = 'Exit the program'
with open('sentiment.txt') as a_file:
try:
reviews = []
tokens = set()
for line in a_file:
stripped_line = line.strip()
stripped_line_tokens = stripped_line[2:].split()
for element in stripped_line_tokens:
tokens.add(element)
reviews.append(stripped_line)
except FileNotFoundError:
print("File could not be read.")
print(reviews[0])
def display_menu(options):
print('Choose an option:')
for i in range(len(options)):
print('\t\t' + str(i + 1) + '. ' + options[i].value)
def show_reviews():
beginning = int(input('Enter a beginning review number from 1 to 8529:')) - 1
ending = int(input('Enter an ending review number from 2 to 8529:')) - 1
while beginning <= ending:
print('Review #' + str(beginning + 1) + ": " + reviews[beginning])
beginning += 1
def show_tokens():
token = str(input('Enter a Token: '))
token = token.lower()
print()
if token in tokens:
print(f'The token {token} is one of the {len(tokens)} unique tokens that appear in the training data.')
else:
print(f'The token {token} is not one of the {len(tokens)} unique tokens that appear in the training data.')
print()
def choose_option(options):
x = 2
while x > 0:
display_menu(options)
try:
choice = int(input('Enter a number from 1 to 8:'))
if choice is 8:
break
elif 1 > choice > 8:
raise ValueError
elif choice is 1:
show_reviews()
elif choice is 2:
show_tokens()
else:
print(options[choice-1])
except ValueError:
print('Please enter a valid, in-range number.')
def main():
pass
options = tuple(MenuOption)
choose_option(options)
if __name__ == '__main__':
Loading