从NLTK一致性中获得所有结果 [英] Get all results from NLTK concordance
本文介绍了从NLTK一致性中获得所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用NLTK查找单词的一致性,但是我不知道如何获取所有结果并将其放入list
或set
中.
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
.
例如:
text.concordance(word)
仅打印前25个结果.
推荐答案
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)
这篇关于从NLTK一致性中获得所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文