paul@0 | 1 | #!/usr/bin/env python |
paul@0 | 2 | |
paul@0 | 3 | import iixr |
paul@0 | 4 | |
paul@0 | 5 | numbers = [12345678, 0, 1] |
paul@0 | 6 | |
paul@0 | 7 | f = open("test", "wb") |
paul@0 | 8 | w = iixr.FileWriter(f) |
paul@0 | 9 | for number in numbers: |
paul@0 | 10 | w.write_number(number) |
paul@0 | 11 | w.close() |
paul@0 | 12 | |
paul@0 | 13 | f = open("test", "r") |
paul@0 | 14 | r = iixr.FileReader(f) |
paul@0 | 15 | for number in numbers: |
paul@0 | 16 | n = r.read_number() |
paul@0 | 17 | print number == n, number, n |
paul@0 | 18 | r.close() |
paul@0 | 19 | |
paul@0 | 20 | all_doc_positions = [ |
paul@0 | 21 | [ |
paul@0 | 22 | (123, [1, 3, 5, 15, 25]), |
paul@0 | 23 | (124, [0, 100]) |
paul@0 | 24 | ], |
paul@0 | 25 | [ |
paul@0 | 26 | (78, [9]), |
paul@0 | 27 | (196, [10, 11]) |
paul@0 | 28 | ] |
paul@0 | 29 | ] |
paul@0 | 30 | |
paul@0 | 31 | f = open("test", "wb") |
paul@0 | 32 | w = iixr.PositionWriter(f) |
paul@0 | 33 | for doc_positions in all_doc_positions: |
paul@0 | 34 | for docnum, positions in doc_positions: |
paul@0 | 35 | w.write_positions(docnum, positions) |
paul@0 | 36 | w.reset() |
paul@0 | 37 | w.close() |
paul@0 | 38 | |
paul@0 | 39 | f = open("test", "r") |
paul@0 | 40 | r = iixr.PositionReader(f) |
paul@0 | 41 | for doc_positions in all_doc_positions: |
paul@0 | 42 | for docnum, positions in doc_positions: |
paul@0 | 43 | d, p = r.read_positions() |
paul@0 | 44 | print docnum == d, docnum, d |
paul@0 | 45 | print positions == p, positions, p |
paul@0 | 46 | r.reset() |
paul@0 | 47 | r.close() |
paul@0 | 48 | |
paul@0 | 49 | f = open("test", "wb") |
paul@0 | 50 | w = iixr.PositionWriter(f) |
paul@0 | 51 | offsets = [] |
paul@0 | 52 | for doc_positions in all_doc_positions: |
paul@0 | 53 | offsets.append( |
paul@0 | 54 | w.write_all_positions(doc_positions) |
paul@0 | 55 | ) |
paul@0 | 56 | w.close() |
paul@0 | 57 | |
paul@0 | 58 | f = open("test", "r") |
paul@0 | 59 | r = iixr.PositionReader(f) |
paul@0 | 60 | offsets.reverse() |
paul@0 | 61 | all_doc_positions.reverse() |
paul@0 | 62 | for offset, doc_positions in zip(offsets, all_doc_positions): |
paul@0 | 63 | dp = r.read_all_positions(offset) |
paul@0 | 64 | print doc_positions == dp, doc_positions, dp |
paul@0 | 65 | r.close() |
paul@0 | 66 | |
paul@2 | 67 | terms = [ |
paul@2 | 68 | ("aardvark", 100000123), |
paul@2 | 69 | ("anteater", 100000456), |
paul@2 | 70 | ("badger", 100000789), |
paul@2 | 71 | ("bull", 1000001234), |
paul@2 | 72 | ("bulldog", 1000002345), |
paul@2 | 73 | ("cat", 1000003456) |
paul@2 | 74 | ] |
paul@2 | 75 | |
paul@2 | 76 | f = open("test", "wb") |
paul@2 | 77 | w = iixr.TermWriter(f) |
paul@2 | 78 | for term, offset in terms: |
paul@2 | 79 | w.write_term(term, offset) |
paul@2 | 80 | w.close() |
paul@2 | 81 | |
paul@2 | 82 | f = open("test", "r") |
paul@2 | 83 | r = iixr.TermReader(f) |
paul@2 | 84 | for term, offset in terms: |
paul@2 | 85 | t, o = r.read_term() |
paul@2 | 86 | print term == t, term, t |
paul@2 | 87 | print offset == o, offset, o |
paul@2 | 88 | r.close() |
paul@2 | 89 | |
paul@0 | 90 | # vim: tabstop=4 expandtab shiftwidth=4 |