cryptexcode commited on
Commit
2593338
·
1 Parent(s): 8eda678

Update multiconer_v2.py

Browse files
Files changed (1) hide show
  1. multiconer_v2.py +38 -37
multiconer_v2.py CHANGED
@@ -297,40 +297,41 @@ class MultiCoNER2(datasets.GeneratorBasedBuilder):
297
 
298
  for it in items:
299
  yield it
300
- # guid = -1
301
- # s_id = None
302
- # tokens = []
303
- # ner_tags = []
304
-
305
- # for line in lines:
306
- # if line.startswith("# id"):
307
- # s_id = line.split('\t')[0].split(' ')[-1].strip()
308
- # guid += 1
309
- # tokens = []
310
- # ner_tags = []
311
- # elif len(line.strip()) < 3:
312
- # if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
313
- # yield guid, {
314
- # "id": str(guid),
315
- # "sample_id": str(s_id),
316
- # "tokens": tokens,
317
- # "ner_tags": ner_tags,
318
- # }
319
- # s_id = None
320
- # tokens = []
321
- # ner_tags = []
322
- # else:
323
- # continue
324
- # else:
325
- # # Separator is " _ _ "
326
- # splits = line.split()
327
- # if len(splits) > 2:
328
- # tokens.append(splits[0].strip())
329
- # ner_tags.append(splits[-1].strip())
330
- # if s_id:
331
- # yield guid, {
332
- # "id": str(guid),
333
- # "sample_id": str(s_id),
334
- # "tokens": tokens,
335
- # "ner_tags": ner_tags,
336
- # }
 
 
297
 
298
  for it in items:
299
  yield it
300
+
301
+ guid = -1
302
+ s_id = None
303
+ tokens = []
304
+ ner_tags = []
305
+
306
+ for line in lines:
307
+ if line.startswith("# id"):
308
+ s_id = line.split('\t')[0].split(' ')[-1].strip()
309
+ guid += 1
310
+ tokens = []
311
+ ner_tags = []
312
+ elif len(line.strip()) < 3:
313
+ if s_id and len(tokens) >= 1 and len(tokens) == len(ner_tags):
314
+ yield (guid, {
315
+ "id": str(guid),
316
+ "sample_id": str(s_id),
317
+ "tokens": tokens,
318
+ "ner_tags": ner_tags,
319
+ })
320
+ s_id = None
321
+ tokens = []
322
+ ner_tags = []
323
+ else:
324
+ continue
325
+ else:
326
+ # Separator is " _ _ "
327
+ splits = line.split()
328
+ if len(splits) > 2:
329
+ tokens.append(splits[0].strip())
330
+ ner_tags.append(splits[-1].strip())
331
+ if s_id:
332
+ yield (guid, {
333
+ "id": str(guid),
334
+ "sample_id": str(s_id),
335
+ "tokens": tokens,
336
+ "ner_tags": ner_tags,
337
+ })