Skip to content
Snippets Groups Projects

Resolve "process_poleval plain text"

2 files
+ 65
0
Compare changes
  • Side-by-side
  • Inline

Files

@@ -510,3 +510,45 @@ def map_json_to_iob(json_ann, iob):
@@ -510,3 +510,45 @@ def map_json_to_iob(json_ann, iob):
out_iob += line
out_iob += line
failed_to_add = len(token_dict) - successfully_added
failed_to_add = len(token_dict) - successfully_added
return out_iob, successfully_added, failed_to_add, derives
return out_iob, successfully_added, failed_to_add, derives
 
 
 
def is_continued(annotation, next_annotations):
 
if next_annotations == ['O']:
 
return False
 
searched_ann = 'I-{0}'.format(annotation)
 
return searched_ann in next_annotations
 
 
 
def iob2_to_iob(iob2_text):
 
iob2_list = []
 
iob1_list = []
 
for line in iob2_text.split('\n'):
 
split = line.split(' ')
 
iob2_list.append((split[0], split[1].split('#')))
 
for i, line in enumerate(iob2_list):
 
current_ann = []
 
if len(iob2_list) == 1:
 
for ann in line[1]:
 
split = ann.split('-')
 
if split[0] == 'B':
 
current_ann.append('I-{0}'.format(split[1]))
 
else:
 
current_ann.append(ann)
 
iob1_list.append((line[0], '#'.join(current_ann)))
 
elif i == len(iob2_list)-1:
 
for ann in line[1]:
 
split = ann.split('-')
 
if split[0] == 'B':
 
current_ann.append('I-{0}'.format(split[1]))
 
else:
 
current_ann.append(ann)
 
iob1_list.append((line[0], '#'.join(current_ann)))
 
else:
 
for ann in line[1]:
 
split = ann.split('-')
 
if split[0] == 'B' and not is_continued(split[1], iob2_list[i+1][1]):
 
current_ann.append('I-{0}'.format(split[1]))
 
else:
 
current_ann.append(ann)
 
iob1_list.append((line[0], '#'.join(current_ann)))
 
return '\n'.join(map(lambda x: '{} {}'.format(x[0], x[1]) , iob1_list))
 
\ No newline at end of file
Loading