Next / Previous / Contents / Shipman's homepage

4.3. Using the KwicRef class

Each instance of the KwicRef class describes one line in which the keyword occurred. Its interface:

KwicRef(prefix, word, suffix, userData)

The prefix argument is the contents of the line up to but not including the keyword, with leading and trailing blanks stripped; word is the keyword; and suffix is the contents of the line after the keyword, also stripped of blanks.

The userData value may be any type.

.prefix

As passed to the constructor, read-only.

.word

As passed to the constructor, read-only.

.suffix

As passed to the constructor, read-only.

.userData

As passed to the constructor, read-only.

.__cmp__(self, other)

The standard comparison method that orders instances according to the sequence defined in Section 8.1, “ref-key .

.__str__(self)

Returns a string representation of self. In particular, the form depends on whether the prefix and suffix are empty. In the example column below, the keyword is italicized.

PrefixWordSuffixResultExample
"P""W""S""W S, P" "Miss Daisy, Driving"
"""W""S""W S" "Driving Miss Daisy"
"P""W""""W, P" "Daisy, Driving Miss"
"""W""""W""Daisy"