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 csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_birthplace = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_birthplace = row['birthplace']
return [SlotSet('birthplace', actual_birthplace
if actual_birthplace is not None and actual_birthplace is not ""
else "not known")]
class ActionUtterBirthplace(Action):
return 'action_utter_birthplace'
person = tracker.get_slot('physicist')
birthplace = tracker.get_slot('birthplace')
dispatcher.utter_message("Birthplace of {} is {}.".format(person, birthplace))
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#
# Birthdate
#
class ActionUtterBirthdate(Action):
def name(self):
return 'action_utter_birthdate'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
birthdate = tracker.get_slot('birthdate')
dispatcher.utter_message("Birthdate of {} is {}.".format(person, birthdate))
return []
class ActionSearchBirthdate(Action):
def name(self):
return 'action_search_birthdate'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_birthdate = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_birthdate = row['birthdate']
return [SlotSet('birthdate', actual_birthdate
if actual_birthdate is not None and actual_birthdate is not ""
else "not known")]
#
# Day of death
#
class ActionSearchDayOfDeath(Action):
def name(self):
return 'action_search_day_of_death'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_day_of_death = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_day_of_death = row['day_of_death']
return [SlotSet('day_of_death', actual_day_of_death
if actual_day_of_death is not None and actual_day_of_death is not ""
else "not known")]
class ActionUtterDayOfDeath(Action):
def name(self):
return 'action_utter_day_of_death'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
day_of_death = tracker.get_slot('day_of_death')
dispatcher.utter_message("The day of death of {} is {}.".format(person, day_of_death))
return []
#
# Place of death
#
class ActionSearchPlaceOfDeath(Action):
def name(self):
return 'action_search_place_of_death'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_place_of_death = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_place_of_death = row['place_of_death']
return [SlotSet('place_of_death', actual_place_of_death
if actual_place_of_death is not None and actual_place_of_death is not ""
else "not known")]
class ActionUtterPlaceOfDeath(Action):
def name(self):
return 'action_utter_place_of_death'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
place_of_death = tracker.get_slot('place_of_death')
dispatcher.utter_message("The place of death of {} is {}.".format(person, place_of_death))
return []
#
# Is alive
#
class ActionSearchIsAlive(Action):
def name(self):
return 'action_search_is_alive'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_is_alive = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_is_alive = row['is_alive']
return [SlotSet('is_alive', actual_is_alive
if actual_is_alive is not None and actual_is_alive is not ""
else "not known")]
def name(self):
return 'action_utter_is_alive'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
is_alive = tracker.get_slot('is_alive')
dispatcher.utter_message("{} is {}.".format(person, is_alive))
return []
#
# num spouses
#
class ActionSearchNumSpouses(Action):
def name(self):
return 'action_search_num_spouses'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_num_spouses = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_num_spouses = row['num_spouses']
return [SlotSet('num_spouses', actual_num_spouses
if actual_num_spouses is not None and actual_num_spouses is not ""
else "not known")]
class ActionUtterNumSpouses(Action):
def name(self):
return 'action_utter_num_spouses'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
num_spouses = tracker.get_slot('num_spouses')
dispatcher.utter_message("The Number of spouses of {} is {}.".format(person, num_spouses))
return []
#
# Primary Education
#
class ActionSearchPrimaryEducation(Action):
def name(self):
return 'action_search_primary_education'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_primary_education = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_primary_education = row['primary_education']
return [SlotSet('primary_education', actual_primary_education
if actual_primary_education is not None and actual_primary_education is not ""
else "not known")]
class ActionUtterPrimaryEducation(Action):
def name(self):
return 'action_utter_primary_education'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
primary_education = tracker.get_slot('primary_education')
dispatcher.utter_message("The primary education of {} is {}.".format(person, primary_education))
return []
#
# University
#
class ActionSearchUniversity(Action):
def name(self):
return 'action_search_university'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_university = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_university = row['university']
return [SlotSet('university', actual_university
if actual_university is not None and actual_university is not ""
else "not known")]
class ActionUtterUniversity(Action):
return 'action_utter_university'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
university = tracker.get_slot('university')
dispatcher.utter_message("The University of {} is {}.".format(person, university))
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#
# Area of Research
#
class ActionSearchAreaOfResearch(Action):
def name(self):
return 'action_search_area_of_research'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_area_of_research = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_area_of_research = row['area_of_research']
return [SlotSet('area_of_research', actual_area_of_research
if actual_area_of_research is not None and actual_area_of_research is not ""
else "not known")]
class ActionUtterAreaOfResearch(Action):
def name(self):
return 'action_utter_area_of_research'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
area_of_research = tracker.get_slot('area_of_research')
dispatcher.utter_message("{} did research in {}.".format(person, area_of_research))
return []
#
# Workplace
#
class ActionSearchWorkplace(Action):
def name(self):
return 'action_search_workplace'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_workplace = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_workplace = row['workplace']
return [SlotSet('workplace', actual_workplace
if actual_workplace is not None and actual_workplace is not ""
else "not known")]
class ActionUtterWorkplace(Action):
def name(self):
return 'action_utter_workplace'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
workplace = tracker.get_slot('workplace')
dispatcher.utter_message("The Workplace of {} is {}.".format(person, workplace))
return []
#
# Awards
#
class ActionSearchAwards(Action):
def name(self):
return 'action_search_awards'
def run(self, dispatcher, tracker, domain):
import csv
import re
person = tracker.get_slot('physicist')
name_regex = re.compile(person, re.IGNORECASE)
actual_awards = None
with open('data.tsv') as csvfile:
spamreader = csv.DictReader(csvfile, delimiter='\t')
for row in spamreader:
if name_regex.match(row['name']):
actual_awards = row['awards']
return [SlotSet('awards', actual_awards
if actual_awards is not None and actual_awards is not ""
else "not known")]
class ActionUtterAwards(Action):
def name(self):
return 'action_utter_awards'
def run(self, dispatcher, tracker, domain):
person = tracker.get_slot('physicist')
awards = tracker.get_slot('awards')
dispatcher.utter_message("The Awards of {} are {}".format(person, awards))