def KGQA_answer(): question = request.args.get('name') target_array = get_target_array(str(question)) if len(target_array) == 1: json_data = query(str(target_array[0])) elif len(target_array) == 0: json_data = query(question) else: json_data = get_KGQA_answer(target_array) return jsonify(json_data)
def KGQA_answer(): # question 是搜索框中输入的语句 question = request.args.get('name') # json_data 是KGQA返回的结果 # str() 将对象转化为适于人阅读的形式 # get_target_array() 得到有关实体和关系的数组,如['贾珠','母亲','贾珠'] # get_KGQA_answer() 返回一个数组,包含查出来的所有路径上的实体,查出实体的详细信息,查出实体的图片 json_data = get_KGQA_answer(get_target_array(str(question))) print("返回的json:") print(json_data) return jsonify(json_data)
def KGQA_answer(): question = request.args.get('name') classifier = QuestionClassifier() parser = QuestionPaser() res_classify = classifier.classify(question) res_sql = parser.parser_main(res_classify) print(res_sql) json_data = get_KGQA_answer(res_sql) print(json_data) return jsonify(json_data)
def KGQA_answer_list(): # question 是搜索框中输入的语句 question = request.args.get('name') # question = "孔庆东的作品" print("question:") print(question) # json_data 是KGQA返回的结果 # str() 将对象转化为适于人阅读的形式 # get_target_array() 得到有关实体和关系的数组,如['贾珠','母亲','贾珠'] # get_KGQA_answer() 返回一个数组,包含查出来的所有路径上的实体,查出实体的详细信息,查出实体的图片 json_data = get_KGQA_answer(get_target_array(str(question))) print("返回的json:") print(json_data) # 添加评分和评分人数 print("测试:") with open('./spider/json/data.json', encoding='utf-8') as f1: data1 = json.load(f1) cnt = 0 for index, i in enumerate(json_data[0]['data']): # if i['category'] < 3: # del json_data[0]['data'][cnt] if i['category'] > 2: for j in data1[i['name']]: try: if j == '评分': i['score'] = data1[i['name']][j] if j == '评论条数': i['hot'] = data1[i['name']][j] if j == '书名': i['book'] = data1[i['name']][j] if j == '作者': i['author'] = data1[i['name']][j] except: continue cnt = cnt + 1 print("返回的json:") print(json_data) newdata = {'data': [], "code": 0} for item in json_data[0]['data']: if i['category'] < 3: continue if 'book' not in item.keys(): continue newdata['data'].append(item) print(newdata) return jsonify(newdata)
def KGQA_answer(): question = request.args.get('name') json_data = get_KGQA_answer(get_target_array(str(question))) return jsonify(json_data)