Datasets:
Commit
·
b410b5f
1
Parent(s):
7ed6316
Update multiconer_v2.py
Browse files- multiconer_v2.py +43 -36
multiconer_v2.py
CHANGED
|
@@ -289,40 +289,47 @@ class MultiCoNER2(datasets.GeneratorBasedBuilder):
|
|
| 289 |
content = open(filepath, 'r').read().strip()
|
| 290 |
lines = content.split('\n')
|
| 291 |
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 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 len(line.strip()) < 3:
|
| 304 |
-
if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
|
| 305 |
-
yield guid, {
|
| 306 |
-
"id": str(guid),
|
| 307 |
-
"sample_id": str(s_id),
|
| 308 |
-
"tokens": tokens,
|
| 309 |
-
"ner_tags": ner_tags,
|
| 310 |
-
}
|
| 311 |
-
s_id = None
|
| 312 |
-
tokens = []
|
| 313 |
-
ner_tags = []
|
| 314 |
-
else:
|
| 315 |
-
continue
|
| 316 |
-
else:
|
| 317 |
-
# Separator is " _ _ "
|
| 318 |
-
splits = line.split()
|
| 319 |
-
if len(splits) > 2:
|
| 320 |
-
tokens.append(splits[0].strip())
|
| 321 |
-
ner_tags.append(splits[-1].strip())
|
| 322 |
-
if s_id:
|
| 323 |
-
yield guid, {
|
| 324 |
-
"id": str(guid),
|
| 325 |
-
"sample_id": str(s_id),
|
| 326 |
-
"tokens": tokens,
|
| 327 |
-
"ner_tags": ner_tags,
|
| 328 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
content = open(filepath, 'r').read().strip()
|
| 290 |
lines = content.split('\n')
|
| 291 |
|
| 292 |
+
yield 1, {
|
| 293 |
+
"id": '1',
|
| 294 |
+
"sample_id": lines[0],
|
| 295 |
+
"tokens": lines[1:5],
|
| 296 |
+
"ner_tags": lines[5:10],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
}
|
| 298 |
+
|
| 299 |
+
# guid = -1
|
| 300 |
+
# s_id = None
|
| 301 |
+
# tokens = []
|
| 302 |
+
# ner_tags = []
|
| 303 |
+
|
| 304 |
+
# for line in lines:
|
| 305 |
+
# if line.startswith("# id"):
|
| 306 |
+
# s_id = line.split('\t')[0].split(' ')[-1].strip()
|
| 307 |
+
# guid += 1
|
| 308 |
+
# tokens = []
|
| 309 |
+
# ner_tags = []
|
| 310 |
+
# elif len(line.strip()) < 3:
|
| 311 |
+
# if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
|
| 312 |
+
# yield guid, {
|
| 313 |
+
# "id": str(guid),
|
| 314 |
+
# "sample_id": str(s_id),
|
| 315 |
+
# "tokens": tokens,
|
| 316 |
+
# "ner_tags": ner_tags,
|
| 317 |
+
# }
|
| 318 |
+
# s_id = None
|
| 319 |
+
# tokens = []
|
| 320 |
+
# ner_tags = []
|
| 321 |
+
# else:
|
| 322 |
+
# continue
|
| 323 |
+
# else:
|
| 324 |
+
# # Separator is " _ _ "
|
| 325 |
+
# splits = line.split()
|
| 326 |
+
# if len(splits) > 2:
|
| 327 |
+
# tokens.append(splits[0].strip())
|
| 328 |
+
# ner_tags.append(splits[-1].strip())
|
| 329 |
+
# if s_id:
|
| 330 |
+
# yield guid, {
|
| 331 |
+
# "id": str(guid),
|
| 332 |
+
# "sample_id": str(s_id),
|
| 333 |
+
# "tokens": tokens,
|
| 334 |
+
# "ner_tags": ner_tags,
|
| 335 |
+
# }
|