-
Notifications
You must be signed in to change notification settings - Fork 18
/
query_map.py
268 lines (245 loc) · 7.1 KB
/
query_map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: Xiaoy Li
# Last update: 2019.04.29
# First create: 2019.02.03
# Description:
# query_map to produce query based NER
# --------------------------------------------------------------
# Chinese and English Corpus involved in.
# --------------------------------------------------------------
# English:
# 1. OntoNotes 5.0
# 2. CoNLL 2003
# Chinese:
# 1. MSRA (3) 人名,地名,机构名
# * NS --- Location
# * NR --- Personal Name
# * NT --- Organization
# 2. Resume (8)
# * ORG --- Organization
# * NAME --- Personal Name
# * RACE --- Ethnicity Background
# * TITLE --- Job Title
# * EDU --- Educational Institution
# * LOC --- Location
# * PRO --- Profession
# * CONT --- Country
# 3. OntoNotes 5.0 (4)
# * LOC --- Non-GPE locations, mountain ranges, bodies of water
# * PER --- People, including fictional
# * GPE --- Countries, cities, states
# * ORG --- Organization
# ---------------------------------------------------------------------------------
# different query strategy can used in experiments
import os
import sys
root_path = "/".join(os.path.realpath(__file__).split("/")[:-3])
if root_path not in sys.path:
sys.path.insert(0, root_path)
en_onto_ner = {
"tags": ['LAW', 'EVENT', 'CARDINAL', 'FAC', 'TIME', 'DATE', 'ORDINAL', 'ORG', 'QUANTITY',
'PERCENT', 'WORK_OF_ART',
'LOC', 'LANGUAGE', 'NORP', 'MONEY', 'PERSON', 'GPE', 'PRODUCT'],
"natural_query": {
"LAW": "named documents made into laws",
"EVENT": "named hurricanes, battles, wars, sports events",
"CARDINAL": "numerals that do not fall under another type",
"FAC": "buildings, airports, highways, bridges, etc",
"TIME": "times smaller than a day",
"DATE": "absolute or relative dates or periods",
"ORDINAL": "first or second",
"ORG": "companies, agencies, institutions",
"QUANTITY": "measurements, as of weight or distance",
"PERCENT": "percentage including %",
"WORK_OF_ART": "titles of books, songs",
"LOC": "not geographical locations, mountain ranges, bodies of water",
"LANGUAGE": "any named language",
"NORP": "nationalities or religious or political groups",
"MONEY": "monetary values, including unit",
"PERSON": "people, including fictional",
"GPE": "countries, cities, state",
"PRODUCT": "vehicles, weapons, foods, etc. not services"
},
"psedo_query": {
"LAW": "law",
"EVENT": "event",
"CARDINAL": "numeral",
"FAC": "facility",
"TIME": "time",
"DATE": "date",
"ORDINAL": "ordinal",
"ORG": "organization",
"QUANTITY": "quantity",
"PERCENT": "percentage",
"WORK_OF_ART": "title",
"LOC": "location",
"LANGUAGE": "language",
"NORP": "group",
"MONEY": "money",
"PERSON": "person",
"GPE": "geographical entity",
"PRODUCT": "product"
}
}
en_conll03_ner = {
"tags": ["ORG", "PER", "LOC", "MISC"],
"natural_query": {
"ORG": "companies, agencies, institutions",
"LOC": "not geographical locations, mountain ranges, bodies of water",
"PER": "people, including fictional",
"MISC": "miscellaneous entity"
},
"psedo_query": {
"ORG": "organization",
"PER": "person",
"LOC": "location",
"MISC": "miscellaneous entity"
}
}
zh_msra_ner = {
"tags": ["NS", "NR", "NT"],
# new_1
# "natural_query": {
# "NS": "国家,城市,山川等抽象或具体的地点",
# "NR": "真实和虚构的人名",
# "NT": "公司,商业机构,社会组织等组织机构"
# },
# new_2
# "natural_query": {
# "NS": "国家,城市,州,山川,河流,海洋等抽象或具体的地点",
# "NR": "真实和虚构的人名",
# "NT": "公司,商业机构,社会组织,党派等组织机构"
# },
# new_3
"natural_query": {
"NS": "抽象和具体的地点",
"NR": "真实和虚构的人名",
"NT": "公司,党派等组织机构"
},
"psedo_query": {
"NS": "地点",
"NR": "人名",
"NT": "组织机构"
}
}
zh_onto_ner = {
"tags": ["LOC", "PER", "GPE", "ORG"],
"natural_query": {
"LOC": "一",
"PER": "二",
"GPE": "三",
"ORG": "四"
},
"psedo_query": {
"LOC": "地点",
"PER": "人名",
"GPE": "位置",
"ORG": "组织"
}
}
zh_resume_ner = {
"tags": ["ORG", "NAME", "RACE", "TITLE", "EDU", "LOC", "PRO", "CONT"],
"psedo_query": {
"ORG": "组织机构",
"LOC": "地点",
"NAME": "个名",
"RACE": "种族背景",
"TITLE": "工作职称",
"EDU": "教育机构",
"PRO": "职业专业",
"CONT": "国家"
}
}
# 自然的地点
zh_onto_ner_loc = {
"tags": ["LOC"],
"natural_query": {
# "LOC": "山脉,水体等具体的地点",
"LOC": "自然的地点",
},
"psedo_query": {
"LOC": "具体的地点",
}
}
zh_onto_ner_per = {
"tags": ["PER"],
"natural_query": {
"PER": "人名,角色",
},
"psedo_query": {
"PER": "人名",
}
}
zh_onto_ner_gpe = {
"tags": ["GPE"],
"natural_query": {
# "GPE": "抽象的地理位置",
"GPE": "抽象的地点",
},
"psedo_query": {
"GPE": "位置",
}
}
zh_onto_ner_org = {
"tags": ["ORG"],
"natural_query": {
"ORG": "公司,服务机构,社会组织"
},
"psedo_query": {
"ORG": "组织机构"
}
}
en_conll03_ner_org = {
"tags": ["ORG"],
"natural_query": {
"ORG": "companies, agencies, institutions",
},
}
zh_resume_ner = {
"tags": ["ORG", "NAME", "RACE", "TITLE", "EDU", "LOC", "PRO", "CONT"],
"natural_query": {
"ORG": "组织或机构",
"LOC": "地点",
"NAME": "姓名",
"RACE": "种族",
"TITLE": "职称",
"EDU": "教育机构",
"PRO": "职业背景",
"CONT": "国家"
},
"psedo_query": {
"ORG": "组织",
"LOC": "地点",
"NAME": "姓名",
"RACE": "种族",
"TITLE": "职称",
"EDU": "教育",
"PRO": "职业",
"CONT": "国家"
}
}
genia_ner = {
"tags": ['cell_line', 'cell_type', 'DNA', 'RNA', 'protein'],
"natural_query": {
'cell_line': "cell line",
'cell_type': "cell type",
'DNA': "DNA",
'RNA': "RNA",
'protein': "protein"
},
"psedo_query": 1
}
query_sign_map = {
"en_onto_ner": en_onto_ner,
"en_conll03_ner": en_conll03_ner,
"en_conll03_ner_org": en_conll03_ner_org,
"zh_msra_ner": zh_msra_ner,
"zh_onto_ner": zh_onto_ner,
"zh_onto_ner_loc": zh_onto_ner_loc,
"zh_onto_ner_per": zh_onto_ner_per,
"zh_onto_ner_gpe": zh_onto_ner_gpe,
"zh_onto_ner_org": zh_onto_ner_org,
"genia_ner": genia_ner,
# "zh_resume_ner": zh_resume_ner
}