nltk.ContextIndex

class nltk.ContextIndex(tokens, context_func=None, filter=None, key=<function <lambda>>)[source]

A bidirectional index between words and their ‘contexts’ in a text. The context of a word is usually defined to be the words that occur in a fixed window around the word; but other definitions may also be used by providing a custom context function.

Methods

__init__(tokens[, context_func, filter, key])
common_contexts(words[, fail_on_unknown]) Find contexts where the specified words can all appear; and return a frequency distribution mapping each context to the number of times that context was used.
similar_words(word[, n])
tokens()
rtype:list(str)
word_similarity_dict(word) Return a dictionary mapping from words to ‘similarity scores,’ indicating how often these two words occur in the same context.