【发布时间】:2016-12-14 05:19:52
【问题描述】:
我正在使用 NLTK 查找单词的一致性,但我不知道如何获取所有结果并将它们放入 list 或 set。
例如:
text.concordance(word)
只打印前 25 个结果。
【问题讨论】:
标签: python text nlp nltk python-3.4
我正在使用 NLTK 查找单词的一致性,但我不知道如何获取所有结果并将它们放入 list 或 set。
例如:
text.concordance(word)
只打印前 25 个结果。
【问题讨论】:
标签: python text nlp nltk python-3.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)
【讨论】:
text.concordance_list(lines=100) 将返回一个list。