cryptexcode commited on
Commit
0f83d1c
·
1 Parent(s): 5b7f6c0

Update multiconer_v2.py

Browse files
Files changed (1) hide show
  1. multiconer_v2.py +11 -5
multiconer_v2.py CHANGED
@@ -287,28 +287,34 @@ class MultiCoNER2(datasets.GeneratorBasedBuilder):
287
  logger.info("⏳ Generating examples from = %s", filepath)
288
  with open(filepath, encoding="utf-8") as f:
289
  guid = 0
 
290
  tokens = []
291
  ner_tags = []
292
  for line in f.read().strip().split('\n'):
293
- if line.startswith("# id") or line == "" or line == "\n" or "_ _" not in line:
294
- if tokens:
 
 
 
 
295
  yield guid, {
296
- "id": str(guid),
297
  "tokens": tokens,
298
  "ner_tags": ner_tags,
299
  }
300
  guid += 1
 
301
  tokens = []
302
  ner_tags = []
303
  else:
304
  # Separator is " _ _ "
305
- splits = line.split("_ _")
306
  tokens.append(splits[0].strip())
307
  ner_tags.append(splits[1].strip())
308
 
309
  # last example
310
  yield guid, {
311
- "id": str(guid),
312
  "tokens": tokens,
313
  "ner_tags": ner_tags,
314
  }
 
287
  logger.info("⏳ Generating examples from = %s", filepath)
288
  with open(filepath, encoding="utf-8") as f:
289
  guid = 0
290
+ s_id = None
291
  tokens = []
292
  ner_tags = []
293
  for line in f.read().strip().split('\n'):
294
+ if line.startswith("# id"):
295
+ s_id = line.split('\t')[0].split(' ')[-1].strip()
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
  # Separator is " _ _ "
311
+ splits = line.split(" _ _ ")
312
  tokens.append(splits[0].strip())
313
  ner_tags.append(splits[1].strip())
314
 
315
  # last example
316
  yield guid, {
317
+ "id": s_id,
318
  "tokens": tokens,
319
  "ner_tags": ner_tags,
320
  }