Datasets:
cryptexcode
commited on
Commit
·
395e152
1
Parent(s):
c4a4815
Update multiconer_v2.py
Browse files- multiconer_v2.py +34 -31
multiconer_v2.py
CHANGED
@@ -285,37 +285,40 @@ class MultiCoNER2(datasets.GeneratorBasedBuilder):
|
|
285 |
|
286 |
def _generate_examples(self, filepath):
|
287 |
logger.info("⏳ Generating examples from = %s", filepath)
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
tokens = []
|
297 |
ner_tags = []
|
298 |
-
elif len(line.strip()) == 0:
|
299 |
-
if s_id and len(tokens) >=1 and len(tokens) == len(ner_tags):
|
300 |
-
yield guid, {
|
301 |
-
"id": s_id,
|
302 |
-
"tokens": tokens,
|
303 |
-
"ner_tags": ner_tags,
|
304 |
-
}
|
305 |
-
guid += 1
|
306 |
-
s_id = None
|
307 |
-
tokens = []
|
308 |
-
ner_tags = []
|
309 |
else:
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
# last example
|
317 |
-
yield guid, {
|
318 |
-
"id": s_id,
|
319 |
-
"tokens": tokens,
|
320 |
-
"ner_tags": ner_tags,
|
321 |
-
}
|
|
|
285 |
|
286 |
def _generate_examples(self, filepath):
|
287 |
logger.info("⏳ Generating examples from = %s", filepath)
|
288 |
+
|
289 |
+
content = open(filepath, 'r').read().strip()
|
290 |
+
lines = content.split('\n')
|
291 |
+
|
292 |
+
guid = -1
|
293 |
+
s_id = None
|
294 |
+
tokens = []
|
295 |
+
ner_tags = []
|
296 |
+
|
297 |
+
for line in lines:
|
298 |
+
if line.startswith("# id"):
|
299 |
+
s_id = line.split('\t')[0].split(' ')[-1].strip()
|
300 |
+
guid += 1
|
301 |
+
tokens = []
|
302 |
+
ner_tags = []
|
303 |
+
elif '_ _' in line:
|
304 |
+
# Separator is " _ _ "
|
305 |
+
splits = line.split("_ _")
|
306 |
+
tokens.append(splits[0].strip())
|
307 |
+
ner_tags.append(splits[1].strip())
|
308 |
+
elif len(line.strip()) == 0:
|
309 |
+
if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
|
310 |
+
yield guid, {
|
311 |
+
"id": s_id,
|
312 |
+
"tokens": tokens,
|
313 |
+
"ner_tags": ner_tags,
|
314 |
+
}
|
315 |
+
s_id = None
|
316 |
tokens = []
|
317 |
ner_tags = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
else:
|
319 |
+
continue
|
320 |
+
yield guid, {
|
321 |
+
"id": s_id,
|
322 |
+
"tokens": tokens,
|
323 |
+
"ner_tags": ner_tags,
|
324 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|