获取NLTK一致性的所有结果

时间:2016-12-14 05:19:52

标签: python text nlp nltk python-3.4

我使用NLTK查找单词的一致性,但我不知道如何获取所有结果并将其放在listset中。

例如:

text.concordance(word)

仅打印前25个结果。

1 个答案:

答案 0 :(得分:4)

<强> TL; DR

text.concordance(lines=100)

从代码中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)