以下代码实现了通过LAC分析关键词的词性
from LAC import LAC
import tqdm
# 装载LAC模型
lac = LAC(mode='lac')
# 单个样本输入,Python3不用加u
#text = "这是我第一个Pyhton练习"
#lacResult = lac.run(text)
allwords = []
f = open("words_2-5.txt")
lines = f.readlines() #读取全部内容 ,并以列表方式返回
for line in tqdm.tqdm(lines):
lacResult = lac.run(line.strip())
linStr = lacResult[0][0] + ',' + lacResult[1][0] + '\n'
allWords.append(linStr)
with open("words_2_5_result.txt", "w") as f:
for word in allWords:
f.write(str(word))