2011-09-30 | Paul Boddie | file changeset files shortlog | Added a wrapper for text files and changed the basic functions to use the API provided by the wrapper. Fixed the copyright information. |
paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | from simplex import * |
paul@0 | 4 | import sys, time |
paul@0 | 5 | |
paul@0 | 6 | filename, step = sys.argv[1:3] |
paul@0 | 7 | terms = sys.argv[3:] |
paul@0 | 8 | |
paul@0 | 9 | f = open(filename) |
paul@1 | 10 | tf = TextFile(f) |
paul@0 | 11 | try: |
paul@0 | 12 | t = time.time() |
paul@1 | 13 | l = index_file(tf, int(step)) |
paul@0 | 14 | print "Indexed in %s seconds." % (time.time() - t) |
paul@0 | 15 | |
paul@0 | 16 | # Now use the index. |
paul@0 | 17 | |
paul@0 | 18 | for term in terms: |
paul@0 | 19 | t = time.time() |
paul@1 | 20 | line = find_with_index(tf, l, term) |
paul@0 | 21 | if line: |
paul@0 | 22 | print "Found (at %s seconds)...\n%s" % (time.time() - t, line) |
paul@0 | 23 | |
paul@0 | 24 | finally: |
paul@0 | 25 | f.close() |
paul@0 | 26 | |
paul@0 | 27 | # vim: tabstop=4 expandtab shiftwidth=4 |