-
Notifications
You must be signed in to change notification settings - Fork 0
/
complement.py
48 lines (43 loc) · 1.37 KB
/
complement.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
# coding: utf-8
import sys
from collections import defaultdict
def main():
# jev
word2level = defaultdict(str)
fin = open(sys.argv[1], "r")
for line in fin:
line = line.strip().split(",")
if "初級" in line[3]:
level = "1"
elif "中級" in line[3]:
level = "2"
elif "上級" in line[3]:
level = "3"
else:
continue
word2level[line[1]] = level
fin.close()
# word-level-japanese
fout = open("word-level-japanese.out", "w")
fin = open("word-level-japanese.tsv", "r")
for line in fin:
word, level = line.strip().split("\t")
if level == "?":
level = word2level[word]
fout.write("%s\t%s\n" % (word, level))
fin.close()
fout.close()
# simple-ppdb-japanese
fout = open("simple-ppdb-japanese.out", "w")
fin = open("simple-ppdb-japanese.tsv", "r")
for line in fin:
paraprob, complex_word, simple_word, level_complex, level_simple = line.strip().split("\t")
if level_complex == "?":
level_complex = word2level[complex_word]
if level_simple == "?":
level_simple = word2level[simple_word]
fout.write("%s\t%s\t%s\t%s\t%s\n" % (paraprob, complex_word, simple_word, level_complex, level_simple))
fin.close()
fout.close()
if __name__ == '__main__':
main()