Skip to content

Yake

YAKEKeywordExtraction

Bases: KeywordExtractionBase

Class for keyword extraction using YAKE.

Source code in src/keyword_extraction/yake.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class YAKEKeywordExtraction(KeywordExtractionBase):
    """
    Class for keyword extraction using YAKE.
    """

    def __init__(self, stopwords_path=None, min_characters=3, **kwargs):
        super().__init__()
        self.stopwords = self.load_stopwords(stopwords_path)
        self.model = yake.KeywordExtractor(stopwords=self.stopwords, **kwargs)
        self.min_chars = min_characters

    def get_keywords(self, text: str) -> List[str]:
        """
        Returns the keywords of the text.
        :param text:
        :return:
        """
        return self.model.extract_keywords(text)

    @staticmethod
    def load_stopwords(path: str) -> List[str]:
        with open(path, 'rt') as f:
            stopwords = f.read().splitlines()
        return stopwords

get_keywords(text)

Returns the keywords of the text.

Parameters:

Name Type Description Default
text str
required

Returns:

Type Description
List[str]
Source code in src/keyword_extraction/yake.py
19
20
21
22
23
24
25
def get_keywords(self, text: str) -> List[str]:
    """
    Returns the keywords of the text.
    :param text:
    :return:
    """
    return self.model.extract_keywords(text)