报错代码如下:
## 代码片段
import os
import jieba
from pyltp import Postagger, Parser
sent = '2018年7月26日,华为创始人任正非向5G极化码(Polar码)之父埃尔达尔教授举行颁奖仪式,表彰其对于通信领域做出的贡献。'
jieba.add_word('Polar码')
jieba.add_word('5G极化码')
jieba.add_word('埃尔达尔')
jieba.add_word('之父')
words = list(jieba.cut(sent))
print(words)
# 词性标注
pos_model_path = os.path.join(os.path.dirname(__file__), 'data/pos.model')
postagger = Postagger()
postagger.load(pos_model_path)
postags = postagger.postag(words)
解决方案:
最后一段代码改成:
# 词性标注
postagger = Postagger(os.path.join("data", "pos.model"))
postags = postagger.postag(words)
print("\t".join(postags))
# postagger = Postagger()
# postagger.load(pos_model_path)
# postags = postagger.postag(words)
转载自[1]
Reference:
[1]AttributeError: 'pyltp.Postagger' object has no attribute 'load'