【问题标题】:Get all results from NLTK concordance从 NLTK 索引中获取所有结果
【发布时间】:2016-12-14 05:19:52
【问题描述】:

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

例如:

text.concordance(word)

只打印前 25 个结果。

【问题讨论】:

    标签: python text nlp nltk python-3.4


    【解决方案1】:

    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)
    

    【讨论】:

    • text.concordance_list(lines=100) 将返回一个list
    • text.concordance_list 可以与 join 结合使用以获取所有单词一致性的列表。
    猜你喜欢
    • 2016-07-31
    • 2011-06-26
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 1970-01-01
    相关资源
    最近更新 更多