def pretreatment(self, q_p="", action_p="seg"): str_t = "" dic_p = {} url_p = config.dic_config["url_api"] + "api" values = {"action": action_p, "q": q_p} try: dic_p = json.loads(inc_crawler_fast.get_html_post(url_p, values)) except: pass return dic_p
def intent_is(self, dic_p={}, action_p="gossip"): result_p = "" if (action_p == "gossip"): url_p = config.dic_config["url_api"] + "api" values = {"action": "cf_lr_gossip", "q": dic_p["segment"]} #print (url_p,values) #调试用 try: txt_json = inc_crawler_fast.get_html_post(url_p, values) except: pass if (txt_json != ""): result_p = self.result_txt_json(str_t=txt_json, name_p="classify") return result_p return result_p
def similar_keyword(self, q_p="", a_p="", action_p="similar_shorttxt"): result_p = {} if (q_p.strip() == "" or q_p.strip() == ""): return result_p url_p = config.dic_config["url_api"] + "api" values = {"action": action_p, "q": q_p, "answer": a_p} #print (url_p,values,inc_crawler_fast.get_html_post(url_p,values))# 调试用 try: result_p = json.loads(inc_crawler_fast.get_html_post( url_p, values)) except: pass #print ("结果字典:",result_p) # 调试用 return result_p
def inner_get(self, str_p="", action_p="cf_cnn_bilstm"): result_p = 0 str_t = "" dic_p = {} url_p = config.dic_config["url_api"] + "api" values = {"action": action_p, "q": str_p} #print (url_p,values,inc_crawler_fast.get_html_post(url_p,values))# 调试用 try: dic_p = json.loads(inc_crawler_fast.get_html_post(url_p, values)) except: pass #print ("结果字典:",dic_p) # 调试用 if (dic_p): result_p = dic_p return result_p
def question_if(self, str_p="", action_p="question_if"): result_p = 0 str_t = "" dic_p = {} url_p = config.dic_config["url_api"] + "api" values = {"action": action_p, "q": str_p} #print (url_p,values,inc_crawler_fast.get_html_post(url_p,values))# 调试用 try: dic_p = json.loads(inc_crawler_fast.get_html_post(url_p, values)) except: pass #print ("结果字典:",dic_p) # 调试用 if (dic_p): if ("result" in dic_p): result_p = dic_p["result"] return result_p
def answer_noindex(self, dic_m={}, conn_p=""): code_p = "" sql_head = "" sql_where = "" sql_foot = "" sql = "" url_p = config.dic_config["url_api"] + "api" values = {"action": "pseg", "q": dic_m["question"]} txt_json = "" try: txt_json = inc_crawler_fast.get_html_post(url_p, values) except: pass if (txt_json != ""): dic_m["pseg"] = self.dic_txt_json(str_t=txt_json) #print ("词性标注",dic_m["pseg"]) #调试用 # 按词性 进行简单礼貌语判别 if (dic_m["pseg"]): i = 1 for x in dic_m["pseg"]: print(dic_m["pseg"][str(i)]) # 调试用 if (dic_m["pseg"][str(i)]["pseg"] == "a" or dic_m["pseg"][str(i)]["pseg"] == "v" or dic_m["pseg"][str(i)]["pseg"] == "l" or dic_m["pseg"][str(i)]["pseg"] == "i" or "n" in dic_m["pseg"][str(i)]["pseg"]): dic_m["list_search"].append(dic_m["pseg"][str(i)]["name"]) i += 1 print("待查询队列", dic_m["list_search"]) if (dic_m["list_search"]): # 闲聊语料判别 if (dic_m["intent"]["gossip"] == 1): table_name_p = "qa_gossip" # 实质性问题知识库判别 if (dic_m["intent"]["gossip"] == 0): table_name_p = "qa" row_name_p = "question" sql_head = "select question,answer from " + table_name_p + " " sql_foot = " order by LENGTH(question),LENGTH(answer),rand() limit 1" for x in dic_m["list_search"]: sql_where += " " + row_name_p + " like '%" + x + "%' and" if (sql_where != ""): sql_where = sql_where[:-3] sql_where += " and answer is not null" sql_where = "where " + sql_where sql = sql_head + sql_where + sql_foot res_p, rows_p = conn_p.read_sql(sql) # 闲聊问答语料表的问题部分能满足匹配条件 if (res_p > 0): code_p = rows_p[0][1] else: # 匹配闲聊问答语料表的答案部分 row_name_p = "answer" sql_where = "" for x in dic_m["list_search"]: sql_where += " " + row_name_p + " like '%" + x + "%' and" if (sql_where != ""): sql_where = sql_where[:-3] sql_where += " and answer is not null" sql_where = "where " + sql_where sql = sql_head + sql_where + sql_foot res_p, rows_p = conn_p.read_sql(sql) if (res_p > 0): code_p = rows_p[0][1] else: # 未成功 改为宽松 匹配 sql_where = "" for x in dic_m["list_search"]: sql_where += " " + row_name_p + " like '%" + x + "%' or" if (sql_where != ""): sql_where = sql_where[:-3] sql_where += " and answer is not null" sql_where = "where " + sql_where sql = sql_head + sql_where + sql_foot res_p, rows_p = conn_p.read_sql(sql) if (res_p > 0): code_p = rows_p[0][1] #print("最后匹配的问题",rows_p[0][0],"最后生效的匹配查询",sql) # 调试用 return code_p