MCPcopy Index your code
hub / github.com/RingBDStack/GDAP / decode

Method decode

extraction/predict_parser/target_predict_parser.py:226–309  ·  view source on GitHub ↗

:param gold_list: :param pred_list: :param text_list: :param raw_list: :return: dict: pred_event -> [(type1, trigger1), (type2, trigger2), ...] gold_event -> [(type1, trigger1), (type2, trigger2), ...]

(self, gold_list, pred_list, text_list=None, raw_list=None)

Source from the content-addressed store, hash-verified

224class ETPredictParser(PredictParser):
225
226 def decode(self, gold_list, pred_list, text_list=None, raw_list=None) -> Tuple[List[Dict], Counter]:
227 """
228
229 :param gold_list:
230 :param pred_list:
231 :param text_list:
232 :param raw_list:
233 :return:
234 dict:
235 pred_event -> [(type1, trigger1), (type2, trigger2), ...]
236 gold_event -> [(type1, trigger1), (type2, trigger2), ...]
237 pred_role -> [(type1, role1, argument1), (type2, role2, argument2), ...]
238 gold_role -> [(type1, role1, argument1), (type2, role2, argument2), ...]
239 Counter:
240 """
241 counter = Counter()
242 well_formed_list = []
243
244 def convert_bracket(_text):
245 _text = add_space(_text)
246 for start in [role_start, type_start]:
247 _text = _text.replace(start, left_bracket)
248 for end in [role_end, type_end]:
249 _text = _text.replace(end, right_bracket)
250 return _text
251
252 if gold_list is None or len(gold_list) == 0: # 不存在标注信息的情况下根据pred_list 全部置为空
253 gold_list = ["%s%s" % (type_start, type_end)] * len(pred_list)
254
255 if text_list is None:
256 text_list = [None] * len(pred_list)
257
258 if raw_list is None:
259 raw_list = [None] * len(pred_list)
260
261 for gold, pred, text, raw_data in zip(gold_list, pred_list, text_list, raw_list):
262 # print(gold)
263 # print("*************************************")
264 gold = convert_bracket(gold)
265 pred = convert_bracket(pred)
266
267 gold = clean_text(gold)
268 pred = clean_text(pred)
269 # print(gold)
270
271 et = None # 事件类型
272 rt = None # 角色类型
273 if text and specical_str in text:
274 et = text.split(specical_str)[0].strip()
275 rt = text.split(specical_str)[1].strip()
276 text = text.split(specical_str)[-1].strip()
277
278 instance = {'gold': gold,
279 'pred': pred,
280 'gold_tree': None,
281 'text': text,
282 'raw_data': raw_data
283 }

Callers

nothing calls this directly

Calls 3

get_event_listMethod · 0.95
clean_textFunction · 0.85

Tested by

no test coverage detected