def NER(words): entity_name, entity_type, entity_loaction = [], [], [] entities_name, entities_type, entities_location = [], [], [] result = evaluate_line(words) for i in range(len(result['entities'])): entity_name = result['entities'][i]['word'] entity_start_loction = result['entities'][i]['start'] entity_end_loction = result['entities'][i]['end'] entity_type = result['entities'][i]['type'] entities_name.append(entity_name) entities_type.append(entity_type) entities_location.append({entity_start_loction, entity_end_loction}) a = '' t = 0 if result['entities'][i]['type'] == 'VER': a = result['entities'][i]['word'] t, eachline = VER(a) if t == 1: result['entities'][i]['simlity'] = ['Find'] if t == 2: result['entities'][i]['simlity'] = [eachline] if t == 0: result['entities'][i]['simlity'] = ['Lost'] # print('VER entity:') # print(ver) else: simility = [] a = result['entities'][i]['word'] # print('Normal entity:') # print(ner) t = lookfordict(a) if t == 1: result['entities'][i]['simlity'] = ['Find'] if t == 2: #print('Looking up Pinyin....'+a) word = a pyy, t = test(word) if t == 3: #print('Lost') result['entities'][i]['simlity'] = ['Lost'] elif t == 4: simility.append(pyy) result['entities'][i]['simlity'] = [simility] return entities_name, entities_type, entities_location
filePathNames = fileTools.eachFile("./resourcesTest/") #print(filePathNames) maxAllstep = len(filePathNames) process_bar1 = processBar.ShowProcess(maxAllstep) trainData = open("trainData", 'w') for path in filePathNames: process_bar1.show_process() fileNames = fileTools.eachFile(path + "/") #maxstep = len(fileNames) #process_bar = processBar.ShowProcess(maxstep) for item in fileNames: #process_bar.show_process() content = fileTools.readFile(item) #print(content) segmemtSentence = main.evaluate_line(content) print(segmemtSentence) exit() number = 0 for num in segmemtSentence: tag = num.split("/") if tag[1] in ["nr", "nrf", "nrj"]: number += 1 if number: for word in segmemtSentence: ll = word.split("/") #print(ll[0][0]) if ll[1] not in ["nr", "nrf", "nrj"]: for i in ll[0]: a = "".join([i, " ", "O", "\n"])
def first_ask(): final_dii = {'-HEIGHT': [], '-WEIGHT': [], '-EAT': [], '-BAD': [], '-EMO': []} global idd global special global all_dict global dii if request.method=='GET': return render_template('first_ask.html') if request.method=='POST': id1 = request.form.get("idtext") if id1!='': idd=id1 input_text=request.form.get("input_text") if input_text=='': return render_template('first_ask.html',res_text = '最近如何?') if input_text!='' and dii =={'-HEIGHT': [], '-WEIGHT': [], '-EAT': [], '-BAD': [], '-EMO': []}: ##有输入的话 mytext, label_list = evaluate_line(if_ask=True, another_input=input_text, save=FLAGS.ckpt_path) print(label_list,mytext) dii = dictionary(label_list=label_list, mytext=mytext) all_dict.append(dii) keras.backend.clear_session() if [] not in dii.values(): #一次输完的话 final_dii=dii print('finalllllllllllll',final_dii) suo(dii=final_dii,input_id=idd) return render_template('first_ask.html', res_text='Thankyou') if [] in dii.values(): for i, ele in enumerate(dii): if dii[ele] == []: used.append(ele) return render_template('first_ask.html', res_text='那今天的%s状况怎么样呢?\n' % (look_up[i])) if input_text!='' and dii!={'-HEIGHT': [], '-WEIGHT': [], '-EAT': [], '-BAD': [], '-EMO': []}: #第二次询问 print('2_ask') #我的身高90公分 cou = 0 for i in dii: if dii[i] != []: cou = cou + 1 for i,ele in enumerate(dii): print(i,ele,dii[ele],used) if dii[ele] ==[] and ele not in used: used.append(ele) mytext2, label_list2 = evaluate_line(if_ask=True, another_input=input_text,save=FLAGS.ckpt_path) all_dict.append(dictionary(label_list=label_list2, mytext=mytext2)) # print(i,ele) print('看看吧',all_dict) return render_template('first_ask.html', res_text='那今天的%s状况怎么样呢?\n' % (look_up[i])) elif len(used)==5-cou: ##最后一条 mytext2, label_list2 = evaluate_line(if_ask=True, another_input=input_text, save=FLAGS.ckpt_path) all_dict.append(dictionary(label_list=label_list2, mytext=mytext2)) print('看看final吧', all_dict) for diction in all_dict: for i in diction: final_dii[i] = final_dii[i] + diction[i] print('finalllllllllllll',final_dii) suo(dii=final_dii, input_id=idd) return render_template('first_ask.html', res_text='Thankyou') else: continue
def hello(): query=input('您好,有什么可以帮助您:\n') now_text=np.array(list(query)) print(now_text) print(type(now_text)) v_now=t.texts_to_sequences(now_text) print(v_now) count2=[] for i in v_now: count2 = count2 + i print(count2) pad_now= pad_sequences([count2],maxlen=maxlen,padding='post') print(pad_now) modeling=train_class() result_list=list(modeling.predict(pad_now)) # print(m.predict(X_dev))m.predict(pad_now) # # classis=np.argmax(m.predict(X_dev), axis=1) for i in result_list: if i <=0.5: class_result=input('您需要的服务是修理本公司的产品吗(回答 yes or no )?\n') if class_result=='yes': print('抱歉,修理产品系统维护中,敬请期待!') else: hello() else: body_query=input('您需要的服务是检查身体吗(回答 yes or no )?\n') if body_query=='yes': keras.backend.clear_session() height,weight=evaluate_line(if_ask=False) print(height,weight) while height==''or weight=='': body_query2=input('对不起我还不够智能,请重新告知完整的身高和体重\n') keras.backend.clear_session() height, weight = evaluate_line(if_ask=True, another_input=body_query2) reask =input('确认您的身高是'+height+'您的体重是'+weight+'(回答 yes or no)?\n') if reask=='yes': import pymongo client = pymongo.MongoClient(host='localhost', port=27017) db = client.test collection = db.students student = { 'id': '20191023', 'Height': height, 'weight': weight, } result = collection.insert(student) print('已录入数据库,稍后为您服务') else: hello() else: hello()
collection = db.students FLAGS = tf.app.flags.FLAGS look_up = [ '身高', '体重', '吃的', '抽烟喝酒', '情绪', ] all_dict = [] from mainto_diction import cut_max, get_char_list, dictionary input_id = input('请输入ID\n') # keras.backend.clear_session() mytext, label_list = evaluate_line(save=FLAGS.ckpt_path) dii = dictionary(label_list=label_list, mytext=mytext) keras.backend.clear_session() if [] in dii.values(): ##缺什么问什么 for i, key in enumerate(dii): if dii[key] == []: re_ask = input('那今天的%s状况怎么样呢?\n' % (look_up[i])) keras.backend.clear_session() mytext2, label_list2 = evaluate_line(if_ask=True, another_input=re_ask, save=FLAGS.ckpt_path) all_dict.append(dictionary(label_list=label_list2, mytext=mytext2)) for diction in all_dict: