基于nltk的快速自动关键词提取算法的python实现
rake-nltk的Python项目详细描述
rake简称快速自动关键词提取算法,是一个领域 尝试确定密钥的独立关键词提取算法 从词频分析语篇中的短语 以及它与文本中其他词的共现。
设置
使用pip
pip install rake-nltk
直接从存储库
git clone https://github.com/csurfer/rake-nltk.git python rake-nltk/setup.py install
设置后
如果你看到一个stopwords错误,这意味着你没有语料库
stopwords
从nltk下载。您可以使用下面的命令下载它。
python -c "import nltk; nltk.download('stopwords')"
基本用法
fromrake_nltkimportRaker=Rake()# Uses stopwords for english from NLTK, and all puntuation characters.r.extract_keywords_from_text(<texttoprocess>)r.get_ranked_phrases()# To get keyword phrases ranked highest to lowest.
高级用法
fromrake_nltkimportMetric,Rake# To use it with a specific language supported by nltk.r=Rake(language=<language>)# If you want to provide your own set of stop words and punctuations tor=Rake(stopwords=<listofstopwords>,punctuations=<stringofpuntuationstoignore>)# If you want to control the metric for ranking. Paper uses d(w)/f(w) as the# metric. You can use this API with the following metrics:# 1. d(w)/f(w) (Default metric) Ratio of degree of word to its frequency.# 2. d(w) Degree of word only.# 3. f(w) Frequency of word only.r=Rake(ranking_metric=Metric.DEGREE_TO_FREQUENCY_RATIO)r=Rake(ranking_metric=Metric.WORD_DEGREE)r=Rake(ranking_metric=Metric.WORD_FREQUENCY)# If you want to control the max or min words in a phrase, for it to be# considered for ranking you can initialize a Rake instance as below:r=Rake(min_length=2,max_length=4)
参考文献
这是本文中提到的算法的python实现 Automatic keyword extraction from individual documents by Stuart Rose, Dave Engel, Nick Cramer and Wendy Cowley
为什么我选择自己实施?
- 通过阅读论文来实现算法是非常有趣的。它是 数字版的DIY工具包。
- 在python(aneesha/RAKE)和 节点(waseem18/node-rake),但两者似乎都没有使用NLTK的能力。通过制作nltk 实现的一个组成部分,我得到灵活性和权力,以延长它在其他 创造性的方法,如果我以后觉得合适的话,不用自己去实现所有的东西。
- 我计划在我的其他宠物项目中使用它,并希望它是 模块化和可调,这样我有完全的控制。