代码
# 要写入新内容的文件是Resumedata(BIO)/dev1.txt
train = open('Resumedata(BIO)/dev1.txt', 'w', encoding='utf-8')
# 旧文件是Resumedata(BIO)/dev.txt
with open('Resumedata(BIO)/dev.txt', encoding='utf-8') as f:
a = f.read()
train.write(a.replace('M-NAME', 'I-NAME').replace('E-NAME', 'I-NAME').replace('S-NAME', 'B-NAME').replace('M-CONT',
'I-CONT').replace(
'E-CONT', 'I-CONT').replace('S-CONT', 'B-CONT').replace('M-RACE', 'I-RACE').replace('E-RACE', 'I-RACE').replace(
'S-RACE', 'B-RACE').replace('M-TITLE', 'I-TITLE').replace('E-TITLE', 'I-TITLE').replace('M-EDU',
'I-EDU').replace(
'E-EDU', 'I-EDU').replace('M-ORG', 'I-ORG').replace('E-ORG', 'I-ORG').replace('S-ORG', 'B-ORG').replace(
'M-PRO', 'I-PRO').replace('E-PRO', 'I-PRO').replace('M-LOC', 'I-LOC').replace('E-LOC', 'I-LOC'))
总结起来就一句话:疯狂用replace。
网友评论