Next / Previous / Contents / Shipman's homepage

4.2. Using the KwicWord class

Each instance of the KwicWord class is a container for all the indexed lines that contain a specific word. Here is the class interface.

KwicWord(word)

The word argument is a keyword. This constructor returns a new, empty KwicWord instance for that keyword.

.word

As passed to the constructor, read-only.

.add(prefix, suffix, userData)

Adds one reference to the instance. The prefix argument is the contents of the original line up to the occurrence of the keyword, with leading and trailing blanks stripped; suffix is the contents of the original line starting after the occurrence of the keyword, also with leading and trailing blanks stripped. The userData value may be any type.

.genRefs()

This method generates all of the references for its keyword as a sequence of KwicRef instances. The entries are in ascending order, with the suffix as the primary key and the prefix as the secondary key.

.getKey()

This method is intended for use as a key extractor function for the skip list used to order the keywords. It returns self.word upshifted.