pred_process_with_golden_type
()
| 53 | |
| 54 | |
| 55 | def predict_data_2_eval(): |
| 56 | """pred_process_with_golden_type""" |
| 57 | pred_trigger_path = sys.argv[2] |
| 58 | pred_role_path = sys.argv[3] |
| 59 | schema_path = sys.argv[4] |
| 60 | save_path = sys.argv[5] |
| 61 | if not pred_trigger_path or not pred_role_path or not schema_path or not save_path: |
| 62 | raise Exception( |
| 63 | "must set pred_trigger_path and pred_role_path and schema_path and save_path" |
| 64 | ) |
| 65 | print(u"predict data 2 eval data start") |
| 66 | |
| 67 | trigger_data_list = utils.read_by_lines(pred_trigger_path) |
| 68 | trigger_datas = {} |
| 69 | for d in trigger_data_list: |
| 70 | d_json = json.loads(d) |
| 71 | trigger_datas[d_json["event_id"]] = d_json |
| 72 | print(u"load trigger predict datas {} from {}".format( |
| 73 | len(trigger_datas), pred_trigger_path)) |
| 74 | |
| 75 | role_data_list = utils.read_by_lines(pred_role_path) |
| 76 | role_datas = {} |
| 77 | for d in role_data_list: |
| 78 | d_json = json.loads(d) |
| 79 | role_datas[d_json["event_id"]] = d_json |
| 80 | print(u"load role predict datas {} from {}".format( |
| 81 | len(role_datas), pred_role_path)) |
| 82 | |
| 83 | schema_data_list = utils.read_by_lines(schema_path) |
| 84 | schema_datas = {} |
| 85 | for d in schema_data_list: |
| 86 | d_json = json.loads(d) |
| 87 | schema_datas[d_json["event_type"]] = [ |
| 88 | r["role"] for r in d_json["role_list"] |
| 89 | ] |
| 90 | print(u"load schema datas {} from {}".format( |
| 91 | len(schema_data_list), schema_path)) |
| 92 | |
| 93 | all_events = {} |
| 94 | for t_json in trigger_datas.values(): |
| 95 | text = t_json["sentence"] |
| 96 | _id = utils.cal_md5(text.encode("utf-8")) |
| 97 | exist_event_type = set() |
| 98 | for tri_info in t_json["trigger_ret"]: |
| 99 | event_type = tri_info["event_type"] |
| 100 | if event_type in exist_event_type: |
| 101 | continue |
| 102 | trigger = tri_info["text"] |
| 103 | role_type_set = set(schema_datas[event_type]) |
| 104 | |
| 105 | r_json = role_datas[t_json["event_id"]] |
| 106 | arguments = [] |
| 107 | for p_r in r_json["roles_ret"]: |
| 108 | role_type = p_r["role_type"] |
| 109 | if role_type in role_type_set: |
| 110 | arguments.append({ |
| 111 | u"role": role_type, |
| 112 | u"argument": p_r["text"] |