Skip to content

Commit 4335d55

Browse files
committed
Add utility iobes_to_bilou
1 parent de84655 commit 4335d55

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

hanlp/utils/span_util.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,18 @@ def bmes_of(sentence, segmented):
8080
chars = list(sentence)
8181
tags = ['S'] * len(chars)
8282
return chars, tags
83+
84+
85+
def iobes_to_bilou(src, dst):
86+
with open(src) as src, open(dst, 'w') as out:
87+
for line in src:
88+
line = line.strip()
89+
if not line:
90+
out.write('\n')
91+
continue
92+
word, tag = line.split('\t')
93+
if tag.startswith('E-'):
94+
tag = 'L-' + tag[2:]
95+
elif tag.startswith('S-'):
96+
tag = 'U-' + tag[2:]
97+
out.write(f'{word}\t{tag}\n')

0 commit comments

Comments
 (0)