1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Read a file containing a 0 or 1 on each line (`feature_file`), output |
---|
5 | all lines from stdin for which that value was 1 |
---|
6 | |
---|
7 | TODO: no need to read the feature_file into memory here, just iterate in |
---|
8 | parallel. |
---|
9 | |
---|
10 | usage: %prog feature_file < ... |
---|
11 | """ |
---|
12 | |
---|
13 | import psyco_full |
---|
14 | |
---|
15 | import sys |
---|
16 | |
---|
17 | def __main__(): |
---|
18 | |
---|
19 | feature_file = sys.argv[1] |
---|
20 | |
---|
21 | if len( sys.argv ) > 2: |
---|
22 | match = int( sys.argv[2] ) |
---|
23 | else: |
---|
24 | match = 1 |
---|
25 | |
---|
26 | feature_vector = [ int( line ) for line in file( feature_file ) ] |
---|
27 | |
---|
28 | for index, line in enumerate( sys.stdin ): |
---|
29 | if feature_vector[ index ] == match: print line, |
---|
30 | |
---|
31 | if __name__ == "__main__": __main__() |
---|