#!/usr/local/bin/python #-- # kwictest: Test driver for KWIC objects. # $Revision: 1.1 $ $Date: 2003/08/02 22:32:25 $ #-- from __future__ import generators # Allow generators import sys # System streams/arguments from kwic import * # KwicIndex object # - - - - - m a i n - - - - - EXCLUSION_FILE = "exclusion" testStrings = [ "Now is the time for all good men to come to the aid OF their planet", "Planets are fun", "The Icon programming language", "icon setting", "Ileaf icons", "icon text" ] # [ kwicIndex := a new, empty KwicIndex object, excluding keywords # from exclusionFile ] kwicIndex = KwicIndex ( exclusionFileName=EXCLUSION_FILE ) # [ kwicIndex := kwicIndex with all strings from testStrings added, # the corresponding value the string's index ] for i in range(len(testStrings)): kwicIndex.add(testStrings[i], i) # [ sys.stdout +:= permuted index from kwicIndex ] for ref in kwicIndex.genRefs(): # [ line := ref, permuted as per kwicIndex ] line = kwicIndex.permute(ref) # [ sys.stdout +:= line ] print line