-
Notifications
You must be signed in to change notification settings - Fork 1
/
restore_conllu_lines.py
70 lines (40 loc) · 1.78 KB
/
restore_conllu_lines.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import re
import os
import codecs
import fileinput
def get_plaintext(pred, base):
pred_sents = pred.split("\n\n")
base_sents = base.split("\n\n")
out = ""
for psent,bsent in zip(pred_sents,base_sents):
pwords = psent.split("\n")
bwords = bsent.split("\n")
for pword,bword in zip(pwords,bwords):
if not pword.startswith("#") and not pword == "" :
pcols = pword.split("\t")
bcols = bword.split("\t")
out += pcols[0]+"\t"+pcols[1]+"\t"+pcols[2]+"\t"+pcols[3]+"\t"+pcols[4]+"\t"+pcols[5]+"\t"+pcols[6]+"\t"+pcols[7]+"\t"+bcols[8]+"\t"+bcols[9]+"\n"
else:
out += pword+"\n"
out += "\n"
return out
if __name__=="__main__":
pred_filename = sys.argv[1]
base_filename = sys.argv[2]
pred=codecs.open(pred_filename, encoding='utf-8', errors='ignore')
base=codecs.open(base_filename, encoding='utf-8', errors='ignore')
write_file = codecs.open("final_output.conllu", "w", "utf-8")
pred_sents = pred.read().split("\n\n")
base_sents = base.read().split("\n\n")
for psent,bsent in zip(pred_sents,base_sents):
pwords = psent.split("\n")
bwords = bsent.split("\n")
for pword,bword in zip(pwords,bwords):
if not pword.startswith("#") and not pword == "" :
pcols = pword.split("\t")
bcols = bword.split("\t")
write_file.write(pcols[0]+"\t"+pcols[1]+"\t"+pcols[2]+"\t"+pcols[3]+"\t"+pcols[4]+"\t"+pcols[5]+"\t"+pcols[6]+"\t"+pcols[7]+"\t"+bcols[8]+"\t"+bcols[9]+"\n")
else:
write_file.write(pword+"\n")
write_file.write("\n")