| 339 | |
| 340 | # ET + Src -> ((Tri)(Tri)), ETText2Tri 使用 |
| 341 | class TriPredictParser(PredictParser): |
| 342 | |
| 343 | def decode(self, gold_list, pred_list, text_list=None, raw_list=None) -> Tuple[List[Dict], Counter]: |
| 344 | counter = Counter() |
| 345 | well_formed_list = [] |
| 346 | |
| 347 | def convert_bracket(_text): |
| 348 | _text = add_space(_text) |
| 349 | for start in [role_start, type_start]: |
| 350 | _text = _text.replace(start, left_bracket) |
| 351 | for end in [role_end, type_end]: |
| 352 | _text = _text.replace(end, right_bracket) |
| 353 | return _text |
| 354 | |
| 355 | if gold_list is None or len(gold_list) == 0: # 不存在标注信息的情况下根据pred_list 全部置为空 |
| 356 | gold_list = ["%s%s" % (type_start, type_end)] * len(pred_list) |
| 357 | |
| 358 | if text_list is None: |
| 359 | text_list = [None] * len(pred_list) |
| 360 | |
| 361 | if raw_list is None: |
| 362 | raw_list = [None] * len(pred_list) |
| 363 | |
| 364 | for gold, pred, text, raw_data in zip(gold_list, pred_list, text_list, raw_list): |
| 365 | # print(gold) |
| 366 | # print("*************************************") |
| 367 | gold = convert_bracket(gold) |
| 368 | pred = convert_bracket(pred) |
| 369 | |
| 370 | gold = clean_text(gold) |
| 371 | pred = clean_text(pred) |
| 372 | # print(gold) |
| 373 | |
| 374 | et = None # 事件类型 |
| 375 | rt = None # 角色类型 |
| 376 | if text and specical_str in text: |
| 377 | et = text.split(specical_str)[0].strip() |
| 378 | rt = text.split(specical_str)[1].strip() |
| 379 | text = text.split(specical_str)[-1].strip() |
| 380 | |
| 381 | instance = {'gold': gold, |
| 382 | 'pred': pred, |
| 383 | 'gold_tree': None, |
| 384 | 'text': text, |
| 385 | 'raw_data': raw_data |
| 386 | } |
| 387 | |
| 388 | # 重点修改部分 |
| 389 | instance['pred_event'], instance['pred_role'], instance['pred_record'] = self.get_event_list( |
| 390 | span_str=instance["pred"], |
| 391 | text=instance['text'], |
| 392 | et = et, |
| 393 | rt = rt |
| 394 | ) |
| 395 | instance['gold_event'], instance['gold_role'], instance['gold_record'] = self.get_event_list( |
| 396 | span_str=instance["gold"], |
| 397 | text=instance['text'], |
| 398 | et = et, |
nothing calls this directly
no outgoing calls
no test coverage detected