MCPcopy Create free account
hub / github.com/RingBDStack/GDAP / annotate_span

Method annotate_span

data_convert/format/text2target.py:29–126  ·  view source on GitHub ↗

src: et + + RT + + source text 为 t5-base 分隔符 traget: ((Role)) 只对role进行生成, 如果同一个et同样的rt存在多个role, 则生成 ((Role)(Role)...) :param tokens: US President George W. Bush told Canadian Prime Minister Jean Chretien by telephone Monday that he looked forw

(tokens, predicate_arguments, mark_tree=False, zh=False, isTest=False)

Source from the content-addressed store, hash-verified

27
28 @staticmethod
29 def annotate_span(tokens, predicate_arguments, mark_tree=False, zh=False, isTest=False):
30 """
31 src: et + </s> + RT + </s> + source text </s> 为 t5-base 分隔符
32 traget: ((Role)) 只对role进行生成, 如果同一个et同样的rt存在多个role, 则生成 ((Role)(Role)...)
33 :param tokens:
34 US President George W. Bush told Canadian Prime Minister Jean Chretien by telephone Monday that he looked forward
35 to seeing him at the upcoming summit of major industrialized nations and Russia , the White House said Tuesday .
36 :param predicate_arguments:
37
38 :return:
39 """
40
41 token_separator = '' if zh else ' '
42
43 event_str_rep_list = list()
44
45 source_list = []
46 target_list = []
47
48 # 若出现单句多个相同 type 事件, 则将其合并
49 et_rt_index_dict = {}
50 et_rt_span_dict = {} # 若出现span重复的情况则进行合并
51
52
53 # 加载 schema文件中的信息, 目前每次都会读取文件, 很低效, 后续将这一步改为传参优化处理
54 if zh:
55 schema = EventSchema.read_from_file("data/raw_data/duee/event.schema")
56 et_rt_dict = schema.type_role_dict
57 schema_et_list = schema.type_list
58 else:
59 schema = EventSchema.read_from_file("data/raw_data/dyiepp_ace2005/event.schema")
60 et_rt_dict = schema.type_role_dict
61 schema_et_list = schema.type_list
62
63 et_set = set() # 文本已经包含的事件类型
64
65 # 遍历event
66 for predicate_argument in predicate_arguments:
67 event_type = predicate_argument['type']
68 et_set.add(event_type)
69
70 # 遍历role
71 for role_type, role_tokens in predicate_argument['arguments']:
72 if role_type == event_type:
73 continue
74
75 if event_type + "-" + role_type not in et_rt_span_dict:
76 et_rt_span_dict[event_type + "-" + role_type] = set()
77
78 role_text = get_str_from_tokens(role_tokens, tokens, separator=token_separator)
79
80 # 判断role是否出现过
81 if role_text in et_rt_span_dict[event_type + "-" + role_type]: continue
82 et_rt_span_dict[event_type + "-" + role_type].add(role_text) # 将当前role加入set中
83
84 # role_str = ' '.join([type_start, role_type, role_text, type_end])
85 role_str = ' '.join([type_start, role_text, type_end])
86

Callers

nothing calls this directly

Calls 2

get_str_from_tokensFunction · 0.85
read_from_fileMethod · 0.80

Tested by

no test coverage detected