def process_dialog(cls, msg, use_task=True): """ Dialog strategy: use sub-task to handle dialog firstly, if failed, use retrieval or generational func to handle it. """ # Task response. if use_task: task_response, cls.dialog_status = TaskCore.task_handle( msg, cls.dialog_status) else: task_response = None # Search response. if len(cls.dialog_status.context) >= 3 and ch_count(msg) <= 4: user_msgs = cls.dialog_status.context[::2][-3:] msg = "<s>".join(user_msgs) mode = "cr" else: mode = "qa" msg_tokens = NlpUtil.tokenize(msg, True) search_response, sim_score = SearchCore.search(msg_tokens, mode=mode) # Seq2seq response. seq2seq_response = cls._predict_via_seq2seq(msg_tokens) log_print("search_response=%s" % search_response) log_print("seq2seq_response=%s" % seq2seq_response) if task_response: response = task_response elif sim_score >= 1.0: response = search_response else: response = seq2seq_response return response
def intent_update(msg, dialog_status): if (ch_count(msg) <= 8 and not not_match_pattern.search(msg) and len(dialog_status.context) == 1 and start_pattern.search(msg) and not dialog_status.start_flag): dialog_status.intent = "start" dialog_status.start_flag = True return dialog_status
def intent_update(msg, dialog_status): msg = bracket_pattern.sub("括", msg) if ch_count(msg) <= 4 and match_pattern.search(msg): if not ch_pattern.search(msg) or not not_match_pattern.search(msg): dialog_status.intent = "short_query" return dialog_status
def intent_update(msg,dialog_status): if ch_count(msg) <= 8 and finish_pattern.search(msg): dialog_status.intent = "finish" return dialog_status