从 NLTK 索引中获取所有结果

zak*_*aki 2 python text nlp nltk python-3.4

我正在使用 NLTK 来查找单词的索引,但我不知道如何获取所有结果并将它们放在 a listor 中set

例如:

text.concordance(word)

只打印前 25 个结果。

alv*_*vas 6

TL; 博士

text.concordance(lines=100)
Run Code Online (Sandbox Code Playgroud)

从代码,https : //github.com/nltk/nltk/blob/develop/nltk/text.py#L323

def concordance(self, word, width=79, lines=25):
    """
    Print a concordance for ``word`` with the specified context window.
    Word matching is not case-sensitive.
    :seealso: ``ConcordanceIndex``
    """
    if '_concordance_index' not in self.__dict__:
        #print("Building index...")
        self._concordance_index = ConcordanceIndex(self.tokens,
                                                   key=lambda s:s.lower())

    self._concordance_index.print_concordance(word, width, lines)
Run Code Online (Sandbox Code Playgroud)