def template_message(self, intent, price=None): print 'template:', intent, price template = self.retrieve_response_template(intent, category=self.kb.category, role=self.kb.role) # changed part: add print for test print "template:" # {'category': ..., 'template': ..., 'logp': ..., 'source': 'rule', 'tag': ..., 'role': ..., 'context': ..., 'id': ..., 'context_tag': ...} print template # if '{price}' in template['template']: price = price or self.state.my_price else: price = None # changed part: add print for test print("price of system: {}".format(price)) # lf = LF(intent, price=price) text = self.fill_template(template['template'], price=price) # changed part: add print for test print("text: {}".format(text)) # utterance = Utterance(raw_text=text, logical_form=lf, template=template) return self.message(utterance)
def final_call(self): lf = LF('final_call', price=self.bottomline) template = self._final_call_template() text = template.format(price=self.bottomline) utterance = Utterance(raw_text=text, logical_form=lf, template=template) return self.message(utterance)
def template_message(self, intent): template = self.retrieve_response_template(intent) lf = LF(intent) text = template['template'] utterance = Utterance(raw_text=text, logical_form=lf, template=template) return self.message(utterance)
def inform(self): intent = 'inform' context_title = self.state.curr_title template = self.retrieve_response_template(intent, context_title=context_title) if template['context_title'] != context_title: return self.template_message('ask') lf = LF(intent) text = template['template'] utterance = Utterance(raw_text=text, logical_form=lf, template=template) return self.message(utterance)
def inform_title(self): intent = 'inform-new-title' title = self.choose_title() print 'chosen title:', title template = self.retrieve_response_template(intent, title=title) titles = [Entity.from_elements(surface=title, value=title, type='title')] lf = LF(intent, titles=titles) text = template['template'] utterance = Utterance(raw_text=text, logical_form=lf, template=template) return self.message(utterance)
def template_message(self, intent, price=None): print 'template:', intent, price template = self.retrieve_response_template(intent, category=self.kb.category, role=self.kb.role) if '{price}' in template['template']: price = price or self.state.my_price else: price = None lf = LF(intent, price=price) text = self.fill_template(template['template'], price=price) utterance = Utterance(raw_text=text, logical_form=lf, template=template) return self.message(utterance)
def send(self): action = self.manager.choose_action(state=self.state) print("action: {}".format(action)) if action == 'done': return self.done() else: lf = LF("placeholder_intent") text = random.choice(self.personas) utterance = Utterance(raw_text=text, logical_form=lf) return self.message(utterance) raise Exception('Uncaught case')
def clarify(self): lf = LF('clarify', proposal=self.state.my_proposal) s = [ "so i get {my_offer}, right?", "so you get {their_offer}?", "ok, i'll take {my_offer}.", ] template = random.choice(s) text = self.fill_handcoded_template(template, self.state.my_proposal) utterance = Utterance(raw_text=text, logical_form=lf, template=template) return self.message(utterance)
def inform(self, intent): entities = self.choose_entities() print 'choose entities:', entities if len(entities) == 1 and self.entity_counts[entities[0]] == 0: intent = 'negative' signature = self.parser.signature(entities) template = self.retrieve_response_template(intent, signature=signature) if template is None: template = self.parser.default_template(entities) text = self.fill_template(template, entities) lf = LF(intent, entities=entities) utterance = Utterance(raw_text=text, logical_form=lf, template=template) return self.message(utterance)
def propose(self, proposal, intent='propose'): proposal_for_me = {self.parser.ME: proposal[self.agent]} proposal_type = self.parser.proposal_to_str(proposal_for_me, self.item_counts) template = self.retrieve_response_template(intent, proposal_type=proposal_type) if template is None: template = "i would like {my_offer}." text = self.fill_handcoded_template(template, proposal) else: text = self.fill_proposal_template(template['template'], proposal_for_me) lf = LF(intent, proposal=proposal) utterance = Utterance(raw_text=text, template=template, logical_form=lf) return self.message(utterance)
def reject(self): utterance = Utterance(logical_form=LF('reject')) self.state.update(self.agent, utterance) metadata = self.metadata(utterance) return super(BaseRulebasedSession, self).reject(metadata=metadata)
def offer(self, price): utterance = Utterance(logical_form=LF('offer', price=price)) self.state.update(self.agent, utterance) metadata = self.metadata(utterance) return super(BaseRulebasedSession, self).offer({'price': price}, metadata=metadata)
def select(self, split): utterance = Utterance(logical_form=LF('select', split=split)) self.state.update(self.agent, utterance) metadata = self.metadata(utterance) return super(RulebasedSession, self).select(split, metadata=metadata)
def select(self, split): print "came to rulebased select, should not happen" utterance = Utterance(logical_form=LF('select', split=split)) self.state.update(self.agent, utterance) metadata = self.metadata(utterance) return super(RulebasedSession, self).select(split, metadata=metadata)