| 102 | |
| 103 | # ET + RT + Src -> ((Role)(Role)), ETRTText2Role 使用 |
| 104 | class RolePredictParser(PredictParser): |
| 105 | |
| 106 | def decode(self, gold_list, pred_list, text_list=None, raw_list=None) -> Tuple[List[Dict], Counter]: |
| 107 | """ |
| 108 | |
| 109 | :param gold_list: |
| 110 | :param pred_list: |
| 111 | :param text_list: |
| 112 | :param raw_list: |
| 113 | :return: |
| 114 | dict: |
| 115 | pred_event -> [(type1, trigger1), (type2, trigger2), ...] |
| 116 | gold_event -> [(type1, trigger1), (type2, trigger2), ...] |
| 117 | pred_role -> [(type1, role1, argument1), (type2, role2, argument2), ...] |
| 118 | gold_role -> [(type1, role1, argument1), (type2, role2, argument2), ...] |
| 119 | Counter: |
| 120 | """ |
| 121 | counter = Counter() |
| 122 | well_formed_list = [] |
| 123 | |
| 124 | def convert_bracket(_text): |
| 125 | _text = add_space(_text) |
| 126 | for start in [role_start, type_start]: |
| 127 | _text = _text.replace(start, left_bracket) |
| 128 | for end in [role_end, type_end]: |
| 129 | _text = _text.replace(end, right_bracket) |
| 130 | return _text |
| 131 | |
| 132 | if gold_list is None or len(gold_list) == 0: # 不存在标注信息的情况下根据pred_list 全部置为空 |
| 133 | gold_list = ["%s%s" % (type_start, type_end)] * len(pred_list) |
| 134 | |
| 135 | if text_list is None: |
| 136 | text_list = [None] * len(pred_list) |
| 137 | |
| 138 | if raw_list is None: |
| 139 | raw_list = [None] * len(pred_list) |
| 140 | |
| 141 | for gold, pred, text, raw_data in zip(gold_list, pred_list, text_list, raw_list): |
| 142 | # print(gold) |
| 143 | # print("*************************************") |
| 144 | gold = convert_bracket(gold) |
| 145 | pred = convert_bracket(pred) |
| 146 | |
| 147 | gold = clean_text(gold) |
| 148 | pred = clean_text(pred) |
| 149 | # print(gold) |
| 150 | |
| 151 | et = None # 事件类型 |
| 152 | rt = None # 角色类型 |
| 153 | if text and specical_str in text: |
| 154 | et = text.split(specical_str)[0].strip() |
| 155 | rt = text.split(specical_str)[1].strip() |
| 156 | text = text.split(specical_str)[-1].strip() |
| 157 | |
| 158 | instance = {'gold': gold, |
| 159 | 'pred': pred, |
| 160 | 'gold_tree': None, |
| 161 | 'text': text, |
nothing calls this directly
no outgoing calls
no test coverage detected