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

type ConcordanceIndex

source code

object --+
         |
        ConcordanceIndex

An index that can be used to look up the offset locations at which a given word occurs in a document.

Instance Methods [hide private]
 
__init__(self, tokens, key=<function <lambda> at 0x7a01f0>)
Construct a new concordance index.
source code
list of token
tokens(self)
Returns: The document that this concordance index was created from.
source code
list of int
offsets(self, word)
Returns: A list of the offset positions at which the given word occurs.
source code
 
__repr__(self) source code
 
print_concordance(self, word, width=75, lines=25)
Print a concordance for word with the specified context window.
source code
Instance Variables [hide private]
  _tokens
The document (list of tokens) that this concordance index was created from.
  _key
Function mapping each token to an index key (or None).
  _offsets
Dictionary mapping words (or keys) to lists of offset indices.
Method Details [hide private]

__init__(self, tokens, key=<function <lambda> at 0x7a01f0>)
(Constructor)

source code 

Construct a new concordance index.

Parameters:
  • tokens - The document (list of tokens) that this concordance index was created from. This list can be used to access the context of a given word occurance.
  • key - A function that maps each token to a normalized version that will be used as a key in the index. E.g., if you use key=lambda s:s.lower(), then the index will be case-insensitive.
Overrides: object.__init__

tokens(self)

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

offsets(self, word)

source code 
Returns: list of int
A list of the offset positions at which the given word occurs. If a key function was specified for the index, then given word's key will be looked up.

__repr__(self)
(Representation operator)

source code 
Overrides: object.__repr__
(inherited documentation)

print_concordance(self, word, width=75, lines=25)

source code 

Print a concordance for word with the specified context window.

Parameters:
  • word (str) - The target word
  • width (int) - The width of each line, in characters (default=80)
  • lines (int) - The number of lines to display (default=25)