Skip to content

Commit

Permalink
Merge pull request #46 from robwilkes/build-events
Browse files Browse the repository at this point in the history
Added: building of events defined in user_says.yaml.
  • Loading branch information
treethought committed Nov 30, 2017
2 parents 7390afb + bbb7d22 commit 75987a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api_ai/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def add_action(self, action_name, parameters=[]):
'messages': [] # TODO: possibly register action responses to call from intent object directly
}]
# self.responses.append(new_response)

def add_event(self, event_name):
self.events.append({'name': event_name})

@property
def serialize(self):
Expand Down
9 changes: 7 additions & 2 deletions api_ai/schema_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def build_user_says(self, intent):
if intent_data:
phrases = intent_data.get('UserSays', [])
annotations = intent_data.get('Annotations', [])
events = intent_data.get('Events', [])
mapping = {}
for a in [a for a in annotations if a]:
for annotation, entity in a.items():
Expand All @@ -201,7 +202,8 @@ def build_user_says(self, intent):
if phrase != '':
intent.add_example(phrase, templ_entity_map=mapping)


for event in [e for e in events if e]:
intent.add_event(event)


def push_intent(self, intent):
Expand Down Expand Up @@ -366,6 +368,7 @@ def create_user_says_skeleton(self):
d = yaml.compat.ordereddict()
d['UserSays'] = [None, None]
d['Annotations'] = [None, None]
d['Events'] = [None]

# d['Annotations'] = self.parse_annotations_from_action_mappings(intent)

Expand All @@ -380,7 +383,9 @@ def create_user_says_skeleton(self):
f.write('# - red is my favorite color\n\n')
f.write('# Annotations:\n')
f.write('# - blue: sys.color # maps param value -> entity\n')
f.write('# - red: sys.color\n\n\n\n')
f.write('# - red: sys.color\n\n')
f.write('# Events:\n')
f.write('# - event1 # adds a triggerable event named \'event1\' to the intent\n\n\n\n')
# f.write(header)
yaml.dump(skeleton, f, default_flow_style=False, Dumper=yaml.RoundTripDumper)

Expand Down

0 comments on commit 75987a4

Please sign in to comment.