使用pyltp对分词后的结果进行词性标记

当我们使用其他分词工具进行分词之后,我们可以使用pyltp对已经分词后的语句进行词性标注。

from pyltp import Postagger
def posttagger(words):
    postagger = Postagger()
    postagger.load("/home/liusenubuntu/program/ltp_data/pos.model")
    posttags = postagger.postag(words)  #词性标注
    postags = list(posttags)
    postagger.release()  #释放模型
    return postags
file=open("/home/liusenubuntu/file/sentence/宫腔粘连MMseg分词.txt",'r',encoding='utf8')
outfile=open("/home/liusenubuntu/file/sentence/宫腔粘连MMseg分词词性标注.txt",'w',encoding='utf8')
for words in file:
    words=words.strip().split('  ')
    postags = posttagger(words)
    for postag, word in zip(postags, words):
        outfile.write(word + "|" + postag+" ")
        print(word + " | " + postag)
    outfile.write("\n")
outfile.close()
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页