Exemplo n.º 1
0
 def query_and_responses_to_rank():
     form = read_request(request)
     print(form)
     query = form['query']
     _responses = form['responses']
     cnt = Counter()
     query = segment_line(' '.join(jieba.cut(query.strip())), v, cnt)
     responses = []
     for piece in _responses.strip().split(';;;'):
         piece = segment_line(' '.join(jieba.cut(piece)), v, cnt)
         response = piece.split()
         responses.append(response)
     query = query.split()
     rank = _query_responses_to_rank(query, responses)
     res = {"rank": rank}
     print(res)
     print('------------------------')
     return json.dumps(res)
Exemplo n.º 2
0
 def query_and_responses_to_rank():
     if request.method == "POST":
         form = request.form
     if request.method == "GET":
         form = request.args
     query = form['query']
     _responses = form['responses']
     cnt = Counter()
     query = segment_line(' '.join(jieba.cut(query.strip())), v, cnt)
     responses = []
     for piece in _responses.strip().split(';;;'):
         piece = segment_line(' '.join(jieba.cut(piece)), v, cnt)
         response = piece.encode('utf8').split()
         responses.append(response)
     query = query.encode('utf8').split()
     rank = _query_responses_to_rank(query, responses)
     res = json.dumps({"rank": rank})
     return res
Exemplo n.º 3
0
 def query_and_skeleton_to_response():
     form = read_request(request)
     print(form)
     query = form['query']
     skeleton = form['skeleton']
     cnt = Counter()
     query = segment_line(' '.join(jieba.cut(query.strip())), v, cnt)
     _skeleton = []
     for piece in skeleton.strip().split(';;;'):
         piece = ' '.join(jieba.cut(piece))
         _skeleton.append(segment_line(piece, v, cnt))
     skeleton = ' <BLANK> '.join(_skeleton)
     query = query.split()
     skeleton = skeleton.split()
     responses = _query_skeletons_to_responses(query, [skeleton])
     res = {"response": responses[0]}
     print(res)
     print('------------------------')
     return json.dumps(res)
Exemplo n.º 4
0
 def query_and_retrievals_to_skeletons_and_responses():
     form = read_request(request)
     print(form)
     query = form['query']
     retrievals = form['retrievals']
     cnt = Counter()
     query = segment_line(' '.join(jieba.cut(query.strip())), v, cnt)
     responses = []
     for piece in retrievals.strip().split(';;;'):
         piece = segment_line(' '.join(jieba.cut(piece)), v, cnt)
         response = piece.split()
         responses.append(response)
     query = query.split()
     skeletons = _query_responses_to_skeletons(query, responses)
     responses = _query_skeletons_to_responses(
         query, [x.split() for x in skeletons])
     res = {"responses": responses, "skeletons": skeletons}
     print(res)
     print('------------------------')
     return json.dumps(res)
Exemplo n.º 5
0
 def query_and_retrievals_to_skeletons_and_responses():
     if request.method == "POST":
         form = request.form
     if request.method == "GET":
         form = request.args
     query = form['query']
     retrievals = form['retrievals']
     cnt = Counter()
     query = segment_line(' '.join(jieba.cut(query.strip())), v, cnt)
     responses = []
     for piece in retrievals.strip().split(';;;'):
         piece = segment_line(' '.join(jieba.cut(piece)), v, cnt)
         response = piece.encode('utf8').split()
         responses.append(response)
     query = query.encode('utf8').split()
     skeletons = _query_responses_to_skeletons(query, responses)
     responses = _query_skeletons_to_responses(
         query, [x.split() for x in skeletons])
     res = json.dumps({"responses": responses, "skeletons": skeletons})
     return res
Exemplo n.º 6
0
 def query_and_skeleton_to_response():
     print('!!!!!!!!')
     if request.method == "POST":
         form = request.form
     if request.method == "GET":
         form = request.args
     query = form['query']
     skeleton = form['skeleton']
     print(query, skeleton)
     cnt = Counter()
     query = segment_line(' '.join(jieba.cut(query.strip())), v, cnt)
     _skeleton = []
     for piece in skeleton.strip().split(';;;'):
         piece = ' '.join(jieba.cut(piece))
         _skeleton.append(segment_line(piece, v, cnt))
     skeleton = ' <BLANK> '.join(_skeleton)
     query = query.encode('utf8').split()
     skeleton = skeleton.encode('utf8').split()
     responses = _query_skeletons_to_responses(query, [skeleton])
     res = json.dumps({"response": responses[0]})
     return res