This part of the documentation covers all the interfaces of rake_nltk.

Metric Object

class rake_nltk.Metric(value)[source]

Different metrics that can be used for ranking.

DEGREE_TO_FREQUENCY_RATIO = 0
WORD_DEGREE = 1
WORD_FREQUENCY = 2

Rake Object

class rake_nltk.Rake(stopwords: Optional[Set[str]] = None, punctuations: Optional[Set[str]] = None, language: str = 'english', ranking_metric: rake_nltk.rake.Metric = Metric.DEGREE_TO_FREQUENCY_RATIO, max_length: int = 100000, min_length: int = 1, include_repeated_phrases: bool = True, sentence_tokenizer: Optional[Callable[[str], List[str]]] = None, word_tokenizer: Optional[Callable[[str], List[str]]] = None)[source]

Rapid Automatic Keyword Extraction Algorithm.

extract_keywords_from_sentences(sentences: List[str])[source]

Method to extract keywords from the list of sentences provided.

Parameters

sentences – Text to extraxt keywords from, provided as a list of strings, where each string is a sentence.

extract_keywords_from_text(text: str)[source]

Method to extract keywords from the text provided.

Parameters

text – Text to extract keywords from, provided as a string.

get_ranked_phrases() List[str][source]

Method to fetch ranked keyword strings.

Returns

List of strings where each string represents an extracted keyword string.

get_ranked_phrases_with_scores() List[Tuple[float, str]][source]

Method to fetch ranked keyword strings along with their scores.

Returns

List of tuples where each tuple is formed of an extracted keyword string and its score. Ex: (5.68, ‘Four Scoures’)

get_word_degrees() Dict[str, int][source]

Method to fetch the degree of words in the given text. Degree can be defined as sum of co-occurances of the word with other words in the given text.

Returns

Dictionary (defaultdict) of the format word -> degree.

get_word_frequency_distribution() Dict[str, int][source]

Method to fetch the word frequency distribution in the given text.

Returns

Dictionary (defaultdict) of the format word -> frequency.