-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_alignment.py
More file actions
executable file
·54 lines (43 loc) · 1.06 KB
/
Copy pathsplit_alignment.py
File metadata and controls
executable file
·54 lines (43 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
import sys
import time
from alignment import *
logs = sys.stderr
def usage():
print >> logs, "cat align-union | ~/newcode/split_alignment.py [--GIZA] [--inv] file1 file2"
print >> logs, "\t-G, --GIZA\t use GIZA format: 4 5 instead of 4-5"
sys.exit(1)
giza = False
def getopts():
global giza, norm_file, invr_file
import getopt
try:
opts, args = getopt.getopt(sys.argv[1:], "G", ["GIZA", "inv"])
except:
usage()
for o, a in opts:
if o == "--GIZA":
giza = True
elif o == "--inv":
set_inverse(True)
else:
usage()
if len(args) == 2:
norm_file, invr_file = open(args[0], "w"), open(args[1], "w")
else:
usage()
def main():
for i, line in enumerate(sys.stdin): # don't zip: not lazy
if (i+1) % 10000 == 0:
print >> logs, i+1, "lines processed"
points = get_two_alignments(line, i)
print_alignment(points[0], norm_file, giza, cr=None, pr=None)
print_alignment(points[1], invr_file, giza, cr=swap, pr=None)
if __name__ == "__main__":
try:
import psyco
psyco.full()
except:
pass
getopts()
main()