Reputation: 137
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.
Upvotes: 3
Views: 1955
Reputation: 122112
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)
Upvotes: 7