class documentation
class ConcordanceIndex(object): (source)
Constructor: ConcordanceIndex(tokens, key)
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 |
Find all concordance lines given the query word. |
Method | offsets |
No summary |
Method | print |
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. |
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 occurrence. |
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. |
Find all concordance lines given the query word.
Provided with a list of words, these will be found as a phrase.
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. |
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