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 3 개의 첫 번째 소개 단락으로 구성됩니다. 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
Language_Code- 내장 된 스톱워드 세트를 사용할 문자열로 언어 코드를 제공합니다. 사용 가능한 언어 목록을 참조하십시오. 언어가 지정되지 않은 경우 알고리즘은 CLD2로 언어를 결정하고 해당 스톱워드 세트를 사용하려고 시도합니다. 기본값 없음
Stopwords- 스톱워드 자체 모음을 제공합니다 (바람직하게는 세트, 하단). 지정된 경우 language_code 무시합니다. 기본값 없음
language_code 와 stopwords 제공 None 제공된 텍스트에서 스톱워드가 생성됩니다.
lang_detect_threshold- CLD2 (0-100)에서 탐지 된 언어의 확률에 대한 임계 값. 기본 50
max_words_unknown_lang- max_words 와 동일하지만 언어가 알려지지 않고 제공된 텍스트에서 stopword가 생성되는 경우 사용됩니다. 일반적으로 최상의 결과는 생성 된 스톱워드의 부재 및 사용으로 인해 키워드가 예쁘지 않을 수 있으며 예를 들어 미리 정의 된 언어에 대한 2 단어 키워드를 생성하는 것이 좋을 수 있습니다. 기본 2
Generated_stopwords_percentile- 스톱워드를 생성하려면 주파수별로 모든 단어를 텍스트로 분포합니다. 이 백분위 수 위의 단어 (0-10)는 후보자가 스톱워드가되는 것으로 간주됩니다. 기본 80
Generated_stopwords_max_len- 생성 된 스톱워드의 최대 문자 길이. 기본 3
Generated_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 지정할 수 있습니다.
레이크 알고리즘은 Rose, S., Engel, D., Cramer, N., & Cowley, W. (2010)에 설명 된대로 작동합니다. 개별 문서에서 자동 키워드 추출. MW Berry & J. Kogan (eds.), 텍스트 마이닝 : 이론 및 응용 : John Wiley & Sons
이 구현은 다국어 지원으로 다른 구현과 다릅니다. 기본적으로 당신은 명시적인 스톱워드 목록없이 언어를 모르고 (키릴 또는 라틴 알파벳으로 작성해야 함) 텍스트를 제공 할 수 있습니다. 최상의 결과는 철저하게 구성된 스톱워드 목록으로 달성됩니다.
후드 아래에서 일어나는 일 :
text and text_for_stopwords 에서 생성됩니다 우리는 텍스트에서 단어의 주파수 분포를 생성하여 stopwords를 생성하고 generated_stopwords_percentile , generated_stopwords_max_len , generated_stopwords_min_freq 로 필터링합니다. 우리는 그것들을 완벽하게 생성 할 수는 없지만 기사와 전치사를 찾는 것은 쉽습니다. 일반적으로 3-4 자로 구성되어 자주 나타나기 때문입니다. 구두점 구분 구동 자와 결합 된 이러한 스톱워드는 이해하지 못하는 언어에 대해 괜찮은 결과를 얻을 수 있습니다.
레이크 초기화 중에 언어 코드 만 사용해야합니다.
저장소에는 Linter, 테스트 및 범위가 구성되었습니다.
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 레이크 알고리즘 : Rose, S., Engel, D., Cramer, N., & Cowley, W. (2010). 개별 문서에서 자동 키워드 추출. MW Berry & J. Kogan (eds.), 텍스트 마이닝 : 이론 및 응용 : John Wiley & Sons
기본으로 Fabianvf의 레이크 구현이 사용되었습니다.
Stopwords : Trec-Kba, 순위 NL