Next / Previous / Contents / Shipman's homepage

12. kwictest: A small test driver

Here is a script that demonstrates KWIC indexing. When you run it, you will note that the words “Mae” and “Driving” occur multiple times, and the occurrences differ in their capitalization. In the resulting report, the headings for each new word use whatever case was first encountered in the text, but the reference entries always show the case that was used in that reference.

#!/usr/bin/env python
# kwictest: Test driver for
# Do not edit this file.  It is automatically extracted from the
# documentation at this location:

# - - - - -   I m p o r t s

import sys
from kwic import KwicIndex

# - - - - -   M a n i f e s t   c o n s t a n t s

  "Driving Miss Daisy",
  "Daisy MAE is driving",
  "For Mae West amongst the former hundred sixty" ]

# - - -   m a i n

def main():
    '''Main program.
    kwic = KwicIndex()
    print "=== Input lines:"
    for line in TEST_LIST:
        print line

    for kw in kwic.genWords():

    print "=== Only entries starting with D:"
    for kw in kwic.genWords("D"):
        if kw.word[0].upper() == 'D':

# - - -   w o r d R e p o r t

def wordReport(word):
    '''Report on one KwicWord.
    print "=== %s" % word.word
    for ref in word.genRefs():
        print ref

# - - - - -   E p i l o g u e

if __name__ == '__main__':