class documentation

class ConcordanceIndex(object): (source)

Constructor: ConcordanceIndex(tokens, key)

View In Hierarchy

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

Method __init__ Construct a new concordance index.
Method __repr__ Undocumented
Method find_concordance Find all concordance lines given the query word.
Method offsets No summary
Method print_concordance Print concordance lines given the query word. :param word: The target word or phrase (a list of strings) :type word: str or list :param lines: The number of lines to display (default=25) :type lines: int :param width: The width of each line, in characters (default=80) :type width: int :param save: The option to save the concordance...
Method tokens No summary
Instance Variable _key Function mapping each token to an index key (or None).
Instance Variable _offsets Dictionary mapping words (or keys) to lists of offset indices.
Instance Variable _tokens The document (list of tokens) that this concordance index was created from.
def __init__(self, tokens, key=(lambda x: x)): (source)

Construct a new concordance index.

Parameters
tokensThe document (list of tokens) that this concordance index was created from. This list can be used to access the context of a given word occurrence.
keyA 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.
def __repr__(self): (source)

Undocumented

def find_concordance(self, word, width=80): (source)

Find all concordance lines given the query word.

Provided with a list of words, these will be found as a phrase.

def offsets(self, word): (source)
Returns
list(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.
def print_concordance(self, word, width=80, lines=25): (source)

Print concordance lines given the query word. :param word: The target word or phrase (a list of strings) :type word: str or list :param lines: The number of lines to display (default=25) :type lines: int :param width: The width of each line, in characters (default=80) :type width: int :param save: The option to save the concordance. :type save: bool

def tokens(self): (source)
Returns
list(str)The document that this concordance index was created from.

Function mapping each token to an index key (or None).

_offsets = (source)

Dictionary mapping words (or keys) to lists of offset indices.

The document (list of tokens) that this concordance index was created from.