Skip to content
Snippets Groups Projects
Commit 460959c6 authored by Lukas Gehrke's avatar Lukas Gehrke
Browse files

Fuegt fehlende Actions zu area_of_research und birthdate hinzu.

parent 529c9507
No related branches found
No related tags found
1 merge request!20Example
......@@ -9,11 +9,6 @@ class ActionSearchBirthplace(Action):
return 'action_search_birthplace'
def run(self, dispatcher, tracker, domain):
#person = tracker.get_slot('physicist')
#if person == None:
# dispatcher.utter_message("No Person found")
#else:
# dispatcher.utter_message("Person found:" + person)
import csv
import re
person = tracker.get_slot('physicist')
......@@ -39,6 +34,40 @@ class ActionUtterBirthplace(Action):
dispatcher.utter_message("Birthplace of {} is {}.".format(person, birthplace))
return []
#
# 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
#
......@@ -237,6 +266,39 @@ class ActionUtterUniversity(Action):
dispatcher.utter_message("The University of {} is {}.".format(person, university))
return []
#
# 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
#
......
......@@ -18,6 +18,8 @@ actions:
- utter_goodbye
- action_search_birthplace
- action_utter_birthplace
- action_search_birthdate
- action_utter_birthdate
- action_search_day_of_death
- action_utter_day_of_death
- action_search_place_of_death
......@@ -45,6 +47,8 @@ slots:
type: text
birthplace:
type: unfeaturized
birthdate:
type: unfeaturized
day_of_death:
type: unfeaturized
place_of_death:
......@@ -66,7 +70,7 @@ slots:
templates:
utter_greet:
- text: "Hi, enter Physicist to gather birthplace information."
- text: "Hi, enter Physicist to gather information."
utter_goodbye:
- text: "Bye"
......@@ -11,6 +11,11 @@
- action_search_birthplace
- action_utter_birthplace
## birthdate
* birthdate{"physicist": "albert einstein}
- action_search_birthdate
- action_utter_birthdate
## day_of_death
* day_of_death{"physicist": "albert einstein"}
- action_search_day_of_death
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment