pyhanlp进行关键词提取,融入自定义词表

# 加入词表前
from pyhanlp import *
if __name__ == '__main__':
  text = "基于知识融合的数据挖掘与分析技术"
  keyword_list = HanLP.extractKeyword(text, 5)
  print(keyword_list)
  '''
  	["融合","知识","数据挖掘","技术"]
  '''
  • 1、首先定义自己的词表new_add.txt,格式为:一行一个词语,可以没有词性和频率;
  • 2、将词表放在pyhanlp的路径下lib/python3.7/site-packages/pyhanlp/static/data/dictionary/custom文件夹下
  • 3、修改hanlp.properties文件内容,路径为lib/python3.7/site-packages/pyhanlp/static/hanlp.properties
    具体做法:在文件第20行,将new_add.txt添加到自定义词典路径中,
    CustomDictionaryPath=data/dictionary/custom/CustomDictionary.txt; new_add.txt; 现代汉语补充词库.txt …
  • 4、删除缓存文件,lib/python3.7/site-packages/pyhanlp/static/data/dictionary/custom/CustomDictionary.txt.bin
  • 5、重新运行程序
# 加入词表后
'''
词表命名为new_add.txt
内容只有一个词语:
数据挖掘与分析
结果如下所示
'''
from pyhanlp import *
if __name__ == '__main__':
  text = "基于知识融合的数据挖掘与分析技术"
  keyword_list = HanLP.extractKeyword(text, 5)
  print(keyword_list)
  '''
  	["融合","知识","数据挖掘与分析","技术"]
  '''

猜你喜欢

转载自blog.csdn.net/tailonh/article/details/112666350