Newer
Older
from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet
class ActionSearchBirthplace(Action):
def name(self):
return 'action_search_birthplace'
def run(self, dispatcher, tracker, domain):
import re
#dispatcher.utter_message("Searching for Birthplace")
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_birthplace = None
with open('birthplace.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
if name_regex.match(row['name']):
actual_birthplace = row['birthplace']
if actual_birthplace is None:
return[SlotSet('birthplace', [])]
return [SlotSet('birthplace', actual_birthplace if actual_birthplace is not None else [])]
class ActionUtterBirthplace(Action):
return 'action_utter_birthplace'
person = tracker.get_slot('physicist')
birthplace = tracker.get_slot('birthplace')
if birthplace == None:
dispatcher.utter_message("Error: Birthplace of " + person + "not known.")
else:
dispatcher.utter_message("The birthplace of " + person + " is " + birthplace + ".")