Datasets:
cryptexcode
commited on
Commit
·
7f553d0
1
Parent(s):
fb75482
Update multiconer_v2.py
Browse files- multiconer_v2.py +32 -46
multiconer_v2.py
CHANGED
@@ -287,52 +287,38 @@ class MultiCoNER2(datasets.GeneratorBasedBuilder):
|
|
287 |
logger.info("⏳ Generating examples from = %s", filepath)
|
288 |
|
289 |
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
yield it
|
301 |
-
|
302 |
-
guid = -1
|
303 |
-
s_id = None
|
304 |
-
tokens = []
|
305 |
-
ner_tags = []
|
306 |
-
|
307 |
-
for line in lines:
|
308 |
-
if line.startswith("# id"):
|
309 |
-
s_id = line.split('\t')[0].split(' ')[-1].strip()
|
310 |
-
guid += 1
|
311 |
-
tokens = []
|
312 |
-
ner_tags = []
|
313 |
-
elif len(line.strip()) < 3:
|
314 |
-
if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
|
315 |
-
yield (guid, {
|
316 |
-
"id": str(guid),
|
317 |
-
"sample_id": str(s_id),
|
318 |
-
"tokens": tokens,
|
319 |
-
"ner_tags": ner_tags,
|
320 |
-
})
|
321 |
-
s_id = None
|
322 |
tokens = []
|
323 |
ner_tags = []
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
# Separator is " _ _ "
|
328 |
-
splits = line.split()
|
329 |
-
if len(splits) > 2:
|
330 |
tokens.append(splits[0].strip())
|
331 |
-
ner_tags.append(splits[
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
logger.info("⏳ Generating examples from = %s", filepath)
|
288 |
|
289 |
|
290 |
+
with open(filepath) as f:
|
291 |
+
guid = -1
|
292 |
+
s_id = None
|
293 |
+
tokens = []
|
294 |
+
ner_tags = []
|
295 |
+
|
296 |
+
for line in f:
|
297 |
+
if line.strip().startswith("# id"):
|
298 |
+
s_id = line.split('\t')[0].split(' ')[-1].strip()
|
299 |
+
guid += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
tokens = []
|
301 |
ner_tags = []
|
302 |
+
elif '_ _' in line:
|
303 |
+
# Separator is " _ _ "
|
304 |
+
splits = line.split("_ _")
|
|
|
|
|
|
|
305 |
tokens.append(splits[0].strip())
|
306 |
+
ner_tags.append(splits[1].strip())
|
307 |
+
elif len(line.strip()) == 0:
|
308 |
+
if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
|
309 |
+
yield guid, {
|
310 |
+
"id": s_id,
|
311 |
+
"tokens": tokens,
|
312 |
+
"ner_tags": ner_tags,
|
313 |
+
}
|
314 |
+
s_id = None
|
315 |
+
tokens = []
|
316 |
+
ner_tags = []
|
317 |
+
else:
|
318 |
+
continue
|
319 |
+
if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
|
320 |
+
yield guid, {
|
321 |
+
"id": s_id,
|
322 |
+
"tokens": tokens,
|
323 |
+
"ner_tags": ner_tags,
|
324 |
+
}
|