2011-09-30 | Paul Boddie | file changeset files shortlog | Added the initial version of the indexing module and some test programs to demonstrate the motivation behind the project. |
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@0 | 10 | try: |
paul@0 | 11 | t = time.time() |
paul@0 | 12 | l = index_by_lines(f, int(step)) |
paul@0 | 13 | print "Indexed in %s seconds." % (time.time() - t) |
paul@0 | 14 | |
paul@0 | 15 | # Now use the index. |
paul@0 | 16 | |
paul@0 | 17 | for term in terms: |
paul@0 | 18 | t = time.time() |
paul@0 | 19 | line = find_line_with_index(f, l, term) |
paul@0 | 20 | if line: |
paul@0 | 21 | print "Found (at %s seconds)...\n%s" % (time.time() - t, line) |
paul@0 | 22 | |
paul@0 | 23 | finally: |
paul@0 | 24 | f.close() |
paul@0 | 25 | |
paul@0 | 26 | # vim: tabstop=4 expandtab shiftwidth=4 |