-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTr_Main.py
More file actions
81 lines (64 loc) · 3.12 KB
/
Tr_Main.py
File metadata and controls
81 lines (64 loc) · 3.12 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import sys
from Layout_Manager import Layout_Manager
from quiz_creator import Quiz_Creator
def get_paths():
# ディレクトリパスを取得
if getattr(sys, 'frozen', False):
base_dir = sys._MEIPASS
else:
base_dir = os.path.dirname(os.path.abspath(__file__))
# 相対パスで指定
return {
"jp_csv": os.path.join(base_dir, "config", "jp_norm.csv"),
"th_csv": os.path.join(base_dir, "config", "th_norm.csv"),
"in_file": os.path.join(base_dir, "data", "input.xlsx"),
"out_file": os.path.join(base_dir, "data", "output.xlsx"),
"template_file": os.path.join(base_dir, "templates", "Driver'sLisence_MockTest.xlsx"),
"json_file": os.path.join(base_dir, "quizApp","questions.js"),
"checked_file" : os.path.join(base_dir, "data", "output_checked.xlsx")
}
def main(mode="all",limit=None,targets=None, input_file_path=None, threshold=0.75, num_beams=1):
if targets is None:
targets = ["question"]
paths = get_paths()
# UIから渡されたファイルパスがあれば、デフォルトの in_file を上書き
if input_file_path:
paths["in_file"] = input_file_path
if mode == "create_quiz":
print("webアプリ作成モード")
quiz_input = paths["checked_file"]
if input_file_path:
quiz_input = input_file_path
Quiz_Creator.create_questions_js(quiz_input, paths["json_file"])
if mode in ["all","translate"]:
print("翻訳モード")
# 各クラスのインスタンス化
# 翻訳機能を使う場合のみ重いライブラリをインポートする
from batch_translator import Batch_Translator
from row_translator import Row_Translator
from excel_manager import Excel_Manager
bt = Batch_Translator()
rt = Row_Translator(bt)
em = Excel_Manager(paths["jp_csv"], paths["th_csv"], bt, rt)
for target in targets:
current_in = paths["in_file"] if target == targets[0] else paths["out_file"]
em.execute(current_in, paths["out_file"], batch_size=16, mode=target, limit=limit, num_beams=num_beams)
if mode in ["all","layout"]:
print("整形モード")
lm = Layout_Manager()
# layoutモードの対象ファイルを決定 (UIから指定があればそれ、なければデフォルト)
target_layout_file = input_file_path if input_file_path else paths["out_file"]
lm.sync_layout(paths["template_file"], target_layout_file, target_layout_file)
if mode == "check":
print("チェックモード")
from Similarity_Checker import SimilarityChecker
target_file = input_file_path if input_file_path else paths["out_file"]
columns = {
'問題文': '問題文',
'ปัญหา': 'ปัญหา',
'解説': '解説',
'คำอธิบาย': 'คำอธิบาย'
}
checker = SimilarityChecker()
return checker.check_file(target_file, columns, threshold=threshold)