![](/img/trans.png)
[英]how to extract words following a list of keywords in python using regex?
[英]how to extract keywords using RAKE in python
我已經實現了這段代碼,但是它在屏幕上什么都不打印。
from rake_nltk import Rake
r = Rake() # Uses stopwords for english from NLTK, and all puntuation characters.
#r = Rake(english) # To use it in a specific language supported by nltk.
# If you want to provide your own set of stop words and punctuations to
# r = Rake(<list of stopwords>, <string of puntuations to ignore>)
print(r.extract_keywords_from_text('hello world'))
r.get_ranked_phrases() # To get keyword phrases ranked highest to lowest.
語句:print(r.extract_keywords_from_text('hello world'))將僅打印關鍵字,因此將打印出None。您需要打印第二行代碼,如下所示:print(r.get_ranked_phrases())。以下內容可能會有所幫助:
from rake_nltk import Rake
from nltk.corpus import stopwords
r = Rake() # Uses stopwords for english from NLTK, and all puntuation characters.Please note that "hello" is not included in the list of stopwords.
text='Hello World'
a=r.extract_keywords_from_text(text)
b=r.get_ranked_phrases()
c=r.get_ranked_phrases_with_scores()
print(b)
print(c)
output:['hello world']
[(4.0, 'hello world')]
我建議也使用包含多個字符串的文本進行嘗試。有關更多詳細信息,請參閱https://pypi.python.org/pypi/rake-nltk 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.