def _print_feature_vectors_and_check_for_correct_answers(writer, rnr_search_results, qid, correct_ans_lookup):
"""
write the search results to file as a feature vector with the qid and gt labels from the query.
:param csv.writer writer:
:param list(list(str)) rnr_search_results:
:param str qid: the qid to print at the start of each feature vector
:param dict(str,int) correct_ans_lookup: label lookup for correct answer ids
:return: num_possible_correct, num_correct_answers_in_search_results
:rtype: tuple(int,int)
"""
num_possible_correct = len(correct_ans_lookup)
num_correct_answers_in_search_results = 0
for row in rnr_search_results:
gt_label = 0
doc_id = row[_ANS_ID_COL].strip()
if doc_id in correct_ans_lookup:
gt_label = correct_ans_lookup[doc_id]
num_correct_answers_in_search_results += 1
writer.writerow([qid] + row + [gt_label])
return num_possible_correct, num_correct_answers_in_search_results
generate_rnr_feature_file.py 文件源码
python
阅读 34
收藏 0
点赞 0
评论 0
评论列表
文章目录