-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvertList.py
27 lines (23 loc) · 984 Bytes
/
ConvertList.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
import os
from .Word import Word
from .SentencePair import SentencePair
class ConvertList:
@classmethod
def build(self, inputFile, dictionary, sentences):
dirname = os.path.dirname(__file__)
convertedFile = os.path.join(dirname, './output.txt')
f = open(inputFile, encoding='utf-8', errors='ignore')
lines = f.readlines()
converted = []
for line in lines:
item = line.strip()
word = next((word for word in dictionary if word.kanji == item), '')
if not word:
continue
sentence = next((pair.original() for pair in sentences if pair.ismatch(item)), '')
translation = next((pair.translation() for pair in sentences if pair.ismatch(item)), '')
string = item + "," + word.reading + "," + word.english + "," + sentence + "," + translation
converted.append(string)
with open(convertedFile, 'w', encoding='utf-8', errors='ignore') as f:
for item in converted:
f.write("%s\n" % item)