def reverse_label(label):
if label.endswith(u"-B"):
label = u"B-" + label[:-2]
elif label.endswith(u"-I"):
label = u"I-" + label[:-2]
else:
pass
return label
def read_file():
with open('../old_corpus.txt', "r", encoding="utf8") as fr:
lines = fr.readlines()
for line in lines:
if u"-B" in line or u"-I" in line:
original_label = line.split(u"\t")[2]
target_label = reverse_label(original_label)
line = line.replace(original_label, target_label)
with open('../new_corpus.txt', 'a', encoding=u"utf8") as fw:
fw.write(line)
if __name__ == '__main__':
read_file()
B-I-标签转换-I-B
最新推荐文章于 2021-06-03 18:49:11 发布