def parse_message(self, event, dialogue_state): tokens = self.lexicon.link_entity(tokenize(event.data)) utterance = Utterance(raw_text=event.data, tokens=tokens) intent = self.classify_intent(utterance) split = None proposal_type = None ambiguous_proposal = False if intent == 'propose': proposal, proposal_type, ambiguous_proposal = self.parse_proposal( utterance.tokens, self.kb.item_counts) if proposal: # NOTE: YOU/ME in proposal is from the partner's perspective split = { self.agent: proposal[self.YOU], self.partner: proposal[self.ME] } if dialogue_state.partner_proposal and split[ self.partner] == dialogue_state.partner_proposal[ self.partner]: intent = 'insist' lf = LF(intent, proposal=split, proposal_type=proposal_type) utterance.lf = lf utterance.template = self.extract_template(tokens, dialogue_state) utterance.ambiguous_template = ambiguous_proposal return utterance
def parse_message(self, event, dialogue_state): tokens = self.lexicon.link_entity(event.data) tokens = [x.lower() if not is_entity(x) else x for x in tokens] utterance = Utterance(raw_text=event.data, tokens=tokens) intent = "placeholder_intent" template = self.extract_template(tokens, dialogue_state) utterance.lf = LF(intent, topic="placeholder") utterance.template = template return utterance
def parse_message(self, event, dialogue_state): tokens = self.lexicon.link_entity(event.data) tokens = [x.lower() if not is_entity(x) else x for x in tokens] utterance = Utterance(raw_text=event.data, tokens=tokens) intent = self.classify_intent(utterance, dialogue_state) template = self.extract_template(tokens, dialogue_state) utterance.lf = LF(intent, titles=self.get_entities(tokens, 'title')) utterance.template = template return utterance
def parse_offer(self, event): intent = 'offer' try: price = float(event.data.get('price')) except TypeError: price = None return Utterance(logical_form=LF(intent, price=price), template=['<offer>'])
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 parse_message(self, event, dialogue_state): tokens = self.lexicon.link_entity(tokenize(event.data), kb=self.kb, scale=False) template = self.extract_template(tokens, dialogue_state) utterance = Utterance(raw_text=event.data, tokens=tokens) tokens_with_parsed_price = self.parse_prices(tokens, dialogue_state) intent = self.classify_intent(utterance, tokens_with_parsed_price, dialogue_state) proposed_price = self.get_proposed_price(tokens_with_parsed_price, dialogue_state) utterance.lf = LF(intent, price=proposed_price) utterance.template = template return utterance
def parse_select(self, event): matched = False for item in self.kb.items: if item == event.data: matched = True return Utterance(logical_form=LF(event.action, item=event.data, matched=matched), template=['<select>'])
def parse_message(self, event, dialogue_state): tokens = self.lexicon.link_entity( tokenize(event.data), kb=self.kb, mentioned_entities=dialogue_state.mentioned_entities, known_kb=False) utterance = Utterance(raw_text=event.data, tokens=tokens) intent = self.classify_intent(utterance) exclude_entities = [] entities = [] for i, token in enumerate(tokens): if is_entity(token): if i > 0 and tokens[i - 1] in self.neg_words: exclude_entities.append(token.canonical) else: entities.append(token.canonical) if len(entities) == 0 and len(exclude_entities) > 0: intent = 'negative' signature = '' if self.is_negative(utterance) and intent == 'inform': utterance.ambiguous_template = True elif entities: signature = self.signature(entities) elif exclude_entities: signature = self.signature(exclude_entities) if intent == 'negative' and not exclude_entities: exclude_entities = dialogue_state.my_entities lf = LF(intent, entities=entities, exclude_entities=exclude_entities, signature=signature) utterance.lf = lf utterance.template = self.extract_template(tokens, dialogue_state) return utterance