-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.py
180 lines (167 loc) · 9.35 KB
/
ui.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'view.ui'
#
# Created by: PyQt5 UI code generator 5.15.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QFileDialog, QMessageBox
from os.path import expanduser
from datetime import datetime as dt
import time
#Custom Libraries
import splitWords
import collectDictionary
import countWordFreq
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(541, 403)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 20, 81, 20))
font = QtGui.QFont()
font.setFamily("Arial")
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 100, 121, 20))
font = QtGui.QFont()
font.setFamily("Arial")
self.label_2.setFont(font)
self.label_2.setLayoutDirection(QtCore.Qt.LeftToRight)
self.label_2.setObjectName("label_2")
self.Origin_context_selButton = QtWidgets.QPushButton(self.centralwidget)
self.Origin_context_selButton.setGeometry(QtCore.QRect(450, 16, 71, 31))
self.Origin_context_selButton.setObjectName("Origin_context_selButton")
self.Split_result_selButton = QtWidgets.QPushButton(self.centralwidget)
self.Split_result_selButton.setGeometry(QtCore.QRect(450, 96, 71, 31))
self.Split_result_selButton.setObjectName("Split_result_selButton")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(20, 140, 111, 20))
font = QtGui.QFont()
font.setFamily("Arial")
self.label_3.setFont(font)
self.label_3.setObjectName("label_3")
self.TF_output__selButton = QtWidgets.QPushButton(self.centralwidget)
self.TF_output__selButton.setGeometry(QtCore.QRect(450, 136, 71, 31))
self.TF_output__selButton.setObjectName("TF_output__selButton")
self.Origin_context_dir = QtWidgets.QLineEdit(self.centralwidget)
self.Origin_context_dir.setEnabled(True)
self.Origin_context_dir.setGeometry(QtCore.QRect(140, 20, 301, 21))
self.Origin_context_dir.setReadOnly(True)
self.Origin_context_dir.setObjectName("Origin_context_dir")
self.Split_result_dir = QtWidgets.QLineEdit(self.centralwidget)
self.Split_result_dir.setEnabled(True)
self.Split_result_dir.setGeometry(QtCore.QRect(140, 100, 301, 21))
self.Split_result_dir.setReadOnly(True)
self.Split_result_dir.setObjectName("Split_result_dir")
self.TF_output_dir = QtWidgets.QLineEdit(self.centralwidget)
self.TF_output_dir.setEnabled(True)
self.TF_output_dir.setGeometry(QtCore.QRect(140, 140, 301, 21))
self.TF_output_dir.setReadOnly(True)
self.TF_output_dir.setObjectName("TF_output_dir")
self.hintBox = QtWidgets.QPlainTextEdit(self.centralwidget)
self.hintBox.setEnabled(True)
self.hintBox.setGeometry(QtCore.QRect(20, 230, 501, 101))
self.hintBox.setReadOnly(True)
self.hintBox.setObjectName("hintBox")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(20, 200, 111, 20))
font = QtGui.QFont()
font.setFamily("Arial")
self.label_4.setFont(font)
self.label_4.setObjectName("label_4")
self.runButton = QtWidgets.QPushButton(self.centralwidget)
self.runButton.setGeometry(QtCore.QRect(410, 340, 113, 32))
self.runButton.setObjectName("runButton")
self.Target_res_selButton = QtWidgets.QPushButton(self.centralwidget)
self.Target_res_selButton.setGeometry(QtCore.QRect(450, 56, 71, 31))
self.Target_res_selButton.setObjectName("Target_res_selButton")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(20, 60, 111, 20))
font = QtGui.QFont()
font.setFamily("Arial")
self.label_5.setFont(font)
self.label_5.setObjectName("label_5")
self.Target_res_dir = QtWidgets.QLineEdit(self.centralwidget)
self.Target_res_dir.setEnabled(True)
self.Target_res_dir.setGeometry(QtCore.QRect(140, 60, 301, 21))
self.Target_res_dir.setReadOnly(True)
self.Target_res_dir.setObjectName("Target_res_dir")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.Origin_context_selButton.clicked.connect(lambda: self.chooseDir('origin'))
self.Target_res_selButton.clicked.connect(lambda: self.chooseDir('target'))
self.Split_result_selButton.clicked.connect(lambda: self.chooseDir('split'))
self.TF_output__selButton.clicked.connect(lambda: self.chooseDir('TF'))
self.runButton.clicked.connect(self.run)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "詞頻計算程式"))
self.label.setText(_translate("MainWindow", "原始文本目錄"))
self.label_2.setText(_translate("MainWindow", "斷詞結果輸出目錄"))
self.Origin_context_selButton.setText(_translate("MainWindow", "選取"))
self.Split_result_selButton.setText(_translate("MainWindow", "選取"))
self.label_3.setText(_translate("MainWindow", "詞頻結果輸出目錄"))
self.TF_output__selButton.setText(_translate("MainWindow", "選取"))
self.label_4.setText(_translate("MainWindow", "訊息提示"))
self.runButton.setText(_translate("MainWindow", "執行"))
self.Target_res_selButton.setText(_translate("MainWindow", "選取"))
self.label_5.setText(_translate("MainWindow", "檢測目標目錄"))
def chooseDir(self, target):
dir = QFileDialog.getExistingDirectory(
None,
"Open a folder",
expanduser("~"),
QFileDialog.ShowDirsOnly)
if dir != '':
if target == 'origin':
self.Origin_context_dir.setText(str(dir))
elif target == 'target':
self.Target_res_dir.setText(str(dir))
elif target == 'split':
self.Split_result_dir.setText(str(dir))
elif target == 'TF':
self.TF_output_dir.setText(str(dir))
def showPopup(self, title, msg, icon="NoIcon"):
mbox = QMessageBox()
mbox.setWindowTitle(title)
mbox.setText(msg)
if icon == "Question":
mbox.setIcon(QMessageBox.Question)
elif icon == "Information":
mbox.setIcon(QMessageBox.Information)
elif icon == "Warning":
mbox.setIcon(QMessageBox.Warning)
elif icon == "Critical":
mbox.setIcon(QMessageBox.Critical)
else:
mbox.setIcon(QMessageBox.NoIcon)
x=mbox.exec_()
def run(self):
self.hintBox.setPlainText('['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+']: '+'開始執行...\n')
self.hintBox.setPlainText(self.hintBox.toPlainText()+'['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+']: '+'檢查必填資料夾...\n')
if(self.Origin_context_dir.text()!='' and self.Target_res_dir.text()!='' and self.Split_result_dir.text()!='' and self.TF_output_dir.text()!=''):
self.hintBox.setPlainText(self.hintBox.toPlainText()+'['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+']: '+'完成\n')
origin_path = self.Origin_context_dir.text()
target_path = self.Target_res_dir.text()
split_path = self.Split_result_dir.text()
tf_path = self.TF_output_dir.text()
self.hintBox.setPlainText(self.hintBox.toPlainText()+'['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+']: '+'建立使用者自訂分詞字典...\n')
collectDictionary.collect(target_path)
self.hintBox.setPlainText(self.hintBox.toPlainText()+'['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+']: '+'完成\n')
self.hintBox.setPlainText(self.hintBox.toPlainText()+'['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+']: '+'將原始文本分詞中\n')
splitWords.split(origin_path, split_path)
self.hintBox.setPlainText(self.hintBox.toPlainText()+'['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+']: '+'完成\n')
self.hintBox.setPlainText(self.hintBox.toPlainText()+'['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+']: '+'計算詞頻並輸出中...\n')
self.hintBox.setPlainText(self.hintBox.toPlainText()+'['+time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+']: '+'完成\n')
countWordFreq.count(target_path, split_path, tf_path)
else:
self.showPopup('注意', '有欄位未被正確填入,請檢查後重試', 'Warning')