improved and readable

pull/652/head
Fardin 2 years ago committed by GitHub
parent ac8cb179b8
commit 0b234c2c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,11 +1,12 @@
import random import random
from textblob import TextBlob from textblob import TextBlob
from textblob.np_extractors import ConllExtractor from textblob.np_extractors import ConllExtractor
extractor = ConllExtractor() extractor = ConllExtractor()
def main(): def main():
print("Hello, I am Marvin, the friendly robot.") print("Hello, I am Marvin, the friendly robot.")
print("You can end this conversation at any time by typing 'bye'") print("You can end this conversation at any time by typing 'bye'")
print("After typing each answer, press 'enter'") print("After typing each answer, press 'enter'")
print("How are you today?") print("How are you today?")
@ -13,14 +14,15 @@ def main():
# wait for the user to enter some text # wait for the user to enter some text
user_input = input("> ") user_input = input("> ")
if user_input.lower() == "bye": if user_input.lower() == "bye":
# if they typed in 'bye' (or even BYE, ByE, byE etc.), break out of the loop # if they typed in 'bye' (or even BYE, ByE, byE etc.), break out of the loop
break break
else: else:
# Create a TextBlob based on the user input. Then extract the noun phrases # Create a TextBlob based on the user input. Then extract the noun phrases
user_input_blob = TextBlob(user_input, np_extractor=extractor) user_input_blob = TextBlob(user_input, np_extractor=extractor)
np = user_input_blob.noun_phrases np = user_input_blob.noun_phrases
response = "" response = ""
if user_input_blob.polarity <= -0.5: if user_input_blob.polarity <= -0.5:
response = "Oh dear, that sounds bad. " response = "Oh dear, that sounds bad. "
elif user_input_blob.polarity <= 0: elif user_input_blob.polarity <= 0:
@ -37,7 +39,7 @@ def main():
else: else:
response = response + "Can you tell me more?" response = response + "Can you tell me more?"
print(response) print(response)
print("It was nice talking to you, goodbye!") print("It was nice talking to you, goodbye!")
# Start the program # Start the program

Loading…
Cancel
Save