Package nltk :: Module text :: Class ContextIndex
[hide private]
[frames] | no frames]

type ContextIndex

source code

object --+
         |
        ContextIndex

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.

Instance Methods [hide private]
 
__init__(self, tokens, context_func=None, filter=None, key=<function <lambda> at 0x7a0070>) source code
list of token
tokens(self)
Returns: The document that this context index was created from.
source code
 
word_similarity_dict(self, word)
Return a dictionary mapping from words to 'similarity scores,' indicating how often these two words occur in the same context.
source code
 
similar_words(self, word, n=20) source code
 
common_contexts(self, words, fail_on_unknown=False)
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.
source code
Static Methods [hide private]
 
_default_context(tokens, i)
One left token and one right token, normalized to lowercase
source code
Method Details [hide private]

__init__(self, tokens, context_func=None, filter=None, key=<function <lambda> at 0x7a0070>)
(Constructor)

source code 
Overrides: object.__init__
(inherited documentation)

tokens(self)

source code 
Returns: list of token
The document that this context index was created from.

common_contexts(self, words, fail_on_unknown=False)

source code 

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.

Parameters:
  • words (str) - The words used to seed the similarity search
  • fail_on_unknown - If true, then raise a value error if any of the given words do not occur at all in the index.