Hello,
I am working on the Alienbot project:
https://www.codecademy.com/paths/build-chatbots-with-python/tracks/rule-based-chatbots/modules/rule-based-chatbots/projects/python-chatbot-alienbot
Unfortunately, I have an issue with step 20/21 of this project and I simple cannot find my mistake.
In a nutshell, I need to create a method for this Alienbot
class selecting the corresponding intent when a match is found. In this specific case, it should evaluate to Inside .answer_why_intent()”.
My method looks like:
def match_reply(self, reply):
for intent, values in self.alienbabble.items():
for regex_pattern in values:
found_match = re.match(regex_pattern, reply.lower())
if found_match and intent == 'describe_planet_intent':
return self.describe_planet_intent()
elif found_match and intent == 'answer_why_intent':
return self.answer_why_intent()
The dictionary self.alienbabble
looks like: {'describe_planet_intent': r'.*\s*your planet.*', 'answer_why_intent': r'why.*', 'cubed_intent': r'' }
If I test the method though, it does only evaluate to one the following two responses:
def describe_planet_intent(self):
responses = ("My planet is a utopia of diverse organisms and species.","I am from Opidipus, the capital of the Wayward Galaxies. ")
return random.choice(responses)
For example:
$ python3 script.py
Hello, may I know your name please ? Peter.
Hi Peter, I'm Etcetera. I'm not from this planet. Will you help me learn about your planet? yes
Why are you here? why
My planet is a utopia of diverse organisms and species.
I have played around with the regex patterns, but still I am unable to match the intent given a match is found. Is there maybe a mistake in the method itself ?
Thanks.