pip install multi-rake如果安装因cld错误narrowing conversions失败,则可以安装
CFLAGS= " -Wno-narrowing " pip install multi-rake英语文本,我们没有明确指定语言或止版列表(使用内置列表)。
from multi_rake import Rake
text_en = (
'Compatibility of systems of linear constraints over the set of '
'natural numbers. Criteria of compatibility of a system of linear '
'Diophantine equations, strict inequations, and nonstrict inequations '
'are considered. Upper bounds for components of a minimal set of '
'solutions and algorithms of construction of minimal generating sets '
'of solutions for all types of systems are given. These criteria and '
'the corresponding algorithms for constructing a minimal supporting '
'set of solutions can be used in solving all the considered types of '
'systems and systems of mixed types.'
)
rake = Rake ()
keywords = rake . apply ( text_en )
print ( keywords [: 10 ])
# ('minimal generating sets', 8.666666666666666),
# ('linear diophantine equations', 8.5),
# ('minimal supporting set', 7.666666666666666),
# ('minimal set', 4.666666666666666),
# ('linear constraints', 4.5),
# ('natural numbers', 4.0),
# ('strict inequations', 4.0),
# ('nonstrict inequations', 4.0),
# ('upper bounds', 4.0),
# ('mixed types', 3.666666666666667),用爱斯佩兰托(Esperanto)撰写的文字(有关自由主义的文章)。没有此语言的停止词列表,它们将从提供的文本中生成。
text由三个介绍的第一段组成。 text_for_stopwords所有其他文本。
text = (
'Liberalismo estas politika filozofio aŭ mondrigardo konstruita en '
'ideoj de libereco kaj egaleco. Liberaluloj apogas larĝan aron de '
'vidpunktoj depende de sia kompreno de tiuj principoj, sed ĝenerale '
'ili apogas ideojn kiel ekzemple liberaj kaj justaj elektoj, '
'civitanrajtoj, gazetara libereco, religia libereco, libera komerco, '
'kaj privata posedrajto. Liberalismo unue iĝis klara politika movado '
'dum la Klerismo, kiam ĝi iĝis populara inter filozofoj kaj '
'ekonomikistoj en la okcidenta mondo. Liberalismo malaprobis heredajn '
'privilegiojn, ŝtatan religion, absolutan monarkion kaj la Didevena '
'Rajto de Reĝoj. La filozofo John Locke de la 17-a jarcento ofte '
'estas meritigita pro fondado de liberalismo kiel klara filozofia '
'tradicio. Locke argumentis ke ĉiu homo havas naturon rekte al vivo, '
'libereco kaj posedrajto kaj laŭ la socia '
'kontrakto, registaroj ne rajtas malobservi tiujn rajtojn. '
'Liberaluloj kontraŭbatalis tradician konservativismon kaj serĉis '
'anstataŭigi absolutismon en registaroj per reprezenta demokratio kaj '
'la jura hegemonio.'
)
rake = Rake ( max_words_unknown_lang = 3 )
keywords = rake . apply ( text , text_for_stopwords = other_text )
print ( keywords )
# ('serĉis anstataŭigi absolutismon', 9.0) # sought to replace absolutism
# ('filozofo john locke', 8.5), # philosopher John Locke
# ('locke argumentis', 4.5) # Locke argues
# ('justaj elektoj', 4.0), # fair elections
# ('libera komerco', 4.0), # free trade
# ('okcidenta mondo', 4.0), # western world
# ('ŝtatan religion', 4.0), # state religion
# ('absolutan monarkion', 4.0), # absolute monarchy
# ('didevena rajto', 4.0), # Dominican Rights
# ('socia kontrakto', 4.0), # social contract
# ('jura hegemonio', 4.0), # legal hegemony
# ('mondrigardo konstruita', 4.0) # worldview built
# ('vidpunktoj depende', 4.0), # views based
# ('sia kompreno', 4.0), # their understanding
# ('tiuj principoj', 4.0), # these principles
# ('gazetara libereco', 3.5), # freedom of press
# ('religia libereco', 3.5), # religious freedom
# ('privata posedrajto', 3.5), # private property
# ('libereco', 1.5), # liberty
# ('posedrajto', 1.5)] # property因此,我们能够在没有明确的停止词的情况下获得体面的结果。
初始化耙子对象
from multi_rake import Rake
rake = Rake (
min_chars = 3 ,
max_words = 3 ,
min_freq = 1 ,
language_code = None , # 'en'
stopwords = None , # {'and', 'of'}
lang_detect_threshold = 50 ,
max_words_unknown_lang = 2 ,
generated_stopwords_percentile = 80 ,
generated_stopwords_max_len = 3 ,
generated_stopwords_min_freq = 2 ,
)MIN_CHARS-如果其长度为> = min_chars,则选择Word作为关键字的一部分。默认3
max_words-被认为是关键字的短语中的最大单词数。默认3
MIN_FREQ-将视为关键字的短语发生的最小数量。默认1
Lanaging_code-提供语言代码作为字符串,以使用内置的停止字样。请参阅可用语言列表。如果未指定语言,算法将尝试使用CLD2确定语言,并使用相应的内置停止字样。默认没有
停止词- 提供自己的停止词的集合(最好是集合,下降)。覆盖language_code (如果指定)。默认没有
将language_code和stopwords保留为None ,并且将从提供的文本中生成停止字。
lang_detect_threshold- cld2中检测到的语言概率的阈值(0-100)。默认50
max_words_unknown_lang-与max_words相同,但如果语言未知并且从提供的文本生成停止字词,则将使用。通常,当使用专门精心制作的停止字样时,获得最佳结果,如果它不存在并且使用产生的止版词的使用情况可能不那么漂亮,例如,可能是一个好主意,例如,为未知语言制作2个字的关键字,以及使用PEDEDEDEDENED SEETSETSETSSETS SETSSETS的语言进行2字关键字。默认2
生成的_stopwords_percentile-要生成stopwords,我们按频率创建每个单词的分布。高于此百分位数(0-100)的单词将被视为候选人成为停止词。默认80
生成的_STOPWORDS_MAX_LEN-生成的停止词的最大字符长度。默认3
生成的_STOPWORDS_MIN_FREQ-发行中生成的停止词的最小频率。默认2
将耙子对象应用于文本。
keywords = rake . apply (
text ,
text_for_stopwords = None ,
)文本- 包含应生成关键字的文本的字符串。
text_for_stopwords-包含文本的字符串将用于与text一起生成stopwords。例如,您的文章带有介绍和几个小节。您知道,出于您的目的,介绍的关键字就足够了,您不知道文本语言,也不知道停止文字的列表。因此,可以从文本本身以及您拥有的文本越多,就可以生成停止词。比您可能指定的text=introduction, text_for_stopwords=rest_of_your_text 。
Rake算法如Rose S.,Engel,D.,Cramer,N。和Cowley,W。(2010)所述的工作。从各个文档中提取自动关键字。在MW Berry&J。Kogan(编辑)中,文本挖掘:理论与应用:John Wiley&Sons
通过其多语言支持,这种实现与其他实现不同。基本上,您可以在不知道其语言的情况下提供文本(应该用西里尔语或拉丁字母编写),而无需明确的停止词列表并获得体面的结果。尽管最佳的结果是通过彻底构建的止词列表来实现的。
引擎盖下发生了什么:
text和text_for_stopwords生成的我们通过在文本中创建单词的频率分布并使用参数generated_stopwords_percentile , generated_stopwords_max_len , generated_stopwords_min_freq来生成停止字词。我们将无法完美地生成它们,但是很容易找到文章和介词,因为它们通常由3-4个字符组成,并且经常出现。这些停止词,再加上标点符号的定界符,使我们能够为我们不了解的语言获得体面的结果。
在耙初始化期间,仅应使用语言代码。
存储库已经配置了衬里,测试和覆盖范围。
在Multi_rake文件夹中创建新的虚拟环境以使用它。
python3 -m venv env
source env/bin/activate
make install-dev # install dependencies
make lint # run linter
make test # run tests and coverage Rake算法:Rose,S.,Engel,D.,Cramer,N。,&Cowley,W。(2010)。从各个文档中提取自动关键字。在MW Berry&J。Kogan(编辑)中,文本挖掘:理论与应用:John Wiley&Sons
作为Fabianvf实施的基础耙子。
停止词:TREC-KBA,排名NL