i = arcs[i - 1][0] if i in des: hit = True if hit: newdes.append(idx + 1) if entity.attrib.get("isresult") == "true": wordidx.add(idx) if entity.attrib.get("internode") == "true": des = newdes return wordidx if __name__ == "__main__": from Chatbot.configs import Configs cfg = Configs() cfg.dp_template_path = "./templates/template.xml" cfg.ltp_seg_model_path = "../utils/ltp/models/cws.models" cfg.ltp_seg_lexicon_path = "../utils/ltp/user_lexicon.txt" cfg.ltp_pos_model_path = "../utils/ltp/models/pos.models" cfg.ltp_rec_model_path = "../utils/ltp/models/ner.models" cfg.ltp_par_model_path = "../utils/ltp/models/parser.models" dp_nlu = DpNLU(cfg) from Chatbot.sessions.statement import Statement from Chatbot.utils.preprocessor import Preprocessor input_str = "我想听周杰伦的稻香" pp = Preprocessor(cfg) stmt = pp.process(Statement(text=input_str))
# PREPROCESS stmt = self.preprocessor.process( Statement(text=sentence, from_user=True)) # NLU intent, ne = self.nlu.process(stmt) # DM status, target, policy = self.dm.process(stmt, None, intent, ne) # NLG response = self.nlg.process(status, target, policy) # 保存CONTEXT信息,持久化 pass return response if __name__ == "__main__": from Chatbot.configs import Configs configs = Configs() chatbot = Chatbot(configs) while True: speech = input(">> ") res = chatbot.listen(speech) print(res)
return seg, pos def dependency_parse(self, seg, pos): # 调用pyltp进行依存句法分析 arcs = self.ltp_util.Parser(seg, pos) parse_result = [] for item in list(arcs): parse_result.append((item.head - 1, item.relation)) return parse_result def emotion_analysis(self, text, contexts): # 返回情感分析结果 return None if __name__ == "__main__": from Chatbot.sessions.statement import Statement from Chatbot.configs import Configs cfg = Configs() cfg.ltp_seg_model_path = "./ltp/models/cws.model" cfg.ltp_seg_lexicon_path = "./ltp/user_lexicon.txt" cfg.ltp_pos_model_path = "./ltp/models/pos.model" cfg.ltp_rec_model_path = "./ltp/models/ner.model" cfg.ltp_par_model_path = "./ltp/models/parser.model" p = Preprocessor(configs=cfg) stmt = p.process(Statement(u"这是一个测试句子。"))
elif "SEARCHBYTYPE" in res: # 按歌曲类型搜索 type = res.strip().split(":")[-1] return "SearchByType", {"type": type} elif "SEARCHBYSCENE" in res: # 按场景搜索 scene = res.strip().split(":")[-1] return "SearchByScene", {"scene": scene} else: return None, None def entity_recognizer(self, text): # 通过字典匹配、知识图谱等等技术手段判断实体类型 pass return "SINGER" if __name__ == "__main__": from Chatbot.configs import Configs from Chatbot.sessions.statement import Statement cfg = Configs() cfg.aiml_nlu_path = "../aiml/nlu-startup.xml" nlu = AimlNLU(cfg) nlu.process(Statement(text="搜 haoting 的歌"))