cryptexcode commited on
Commit
395e152
1 Parent(s): c4a4815

Update multiconer_v2.py

Browse files
Files changed (1) hide show
  1. 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
- 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
- if '_ _' in line:
311
- # Separator is " _ _ "
312
- splits = line.split("_ _")
313
- tokens.append(splits[0].strip())
314
- ner_tags.append(splits[1].strip())
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
+ }