def answer_question(self, question_str): question = Question() question.set_question(question_str) question = self.__question_classifier.classify(question) logging.info('开始处理Question:' + question.get_question() + '问题类型:' + str(question.get_question_type())) if question.get_question_type() == QuestionType.Open: return self.tl_chat(question_str) if question.get_question_type() != QuestionType.Solution: question = self.kb_based_answer_question(question) else: question = self.ir_based_answer_question(question) logging.info('候选答案: ' + question.get_expect_answer()) return question.get_expect_answer()
def answer_question(self, question_str): question = Question() question.set_question(question_str) question = self.__question_classifier.classify(question) logging.info('开始处理Question:' + question.question_string + question.question_type.value) logging.info(question.body + question.medicine + question.disease) if question.question_type == QuestionType.Medicine: answer = self.kb_based_answer_question(question) if not answer: answer = self.ir_based_answer_question(question) elif question.question_type == QuestionType.Definition \ and len(question.body+question.medicine+question.disease) == 1: answer = self.baike_based_answer_question( (question.body + question.medicine + question.disease)[0]) if not answer: answer = self.ir_based_answer_question(question) else: answer = self.ir_based_answer_question(question) del question logging.info('候选答案: ' + answer) return answer
:param question_a: 问题类 """ logging.info('问句相似度开始') question1 = question_a.word_list question2 = question_b.word_list class_score = class_sim(question_a.question_type, question_b.question_type) key_score = key_sim(question_a, question_b) wmd_score = wmd_sim(question1, question2) # semantic_score = semantic_sim(question1, question2) word_score = word_sim(question1, question2) order_score = order_sim(question1, question2) char_tfidf_score = char_tfidf_sim(question_a.question_string, question_b.question_string) score = weights['class_weight']*class_score + weights['key_weight']*key_score + weights['wmd_weight']*wmd_score + \ weights['word_weight']*word_score + weights['order_weight']*order_score + \ weights['char_tfidf_weight']*char_tfidf_score logging.info('问句相似度结束,得分为{}\n\n'.format(score)) return score if __name__ == '__main__': q = Question() q.set_question('感冒了怎么办') que = input() while que != 'end': q2 = Question() q2.set_question(que) # q.set_question_type(QuestionType.Doctor) combination_sim() que = input()