Get all results from NLTK concordance

萝らか妹 提交于 2019-12-08 03:30:32

问题


I'm using NLTK to find the concordance of a word, but I don't know how to get all the results and put them in a list or set.

For example:

text.concordance(word)

prints just the first 25 results.


回答1:


TL;DR

text.concordance(lines=100)

From the code, 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)


来源:https://stackoverflow.com/questions/41135369/get-all-results-from-nltk-concordance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!