-
Notifications
You must be signed in to change notification settings - Fork 2
/
TrainingUI.py
152 lines (118 loc) · 4.06 KB
/
TrainingUI.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
import tkinter
from tkinter import *
import re
import dictionary
import tkinter.messagebox
root=Tk()
root.title('TrainingUI')
SourcePath=StringVar()
SourceFile=StringVar()
TargetFile=StringVar()
QueryResult=StringVar()
head=Frame(root,borderwidth=10)
sp_text=Entry(head,width=40,textvariable=SourcePath)
sf_text=Entry(head,width=20,textvariable=SourceFile)
queryButton=Button(head,text='Query',command=lambda foo=0:Query())
queryLabel=Label(head,textvariable=QueryResult,font=('Helvectica',20))
text_fr=Frame(root,borderwidth=10)
tail=Frame(root,borderwidth=10)
text =Text(bg='white', height=20,font=('Helvectica',26))
global unmodified_flag
unmodified_flag=True
ctrl_flag=False
c_flag=False
def Load():
global unmodified_flag
if not(unmodified_flag):
answer=tkinter.messagebox.askquestion("Save", "Sure To Load? Something modified may be lost.")
if answer=='no': return
s=SourcePath.get()+SourceFile.get()
f=open(s,'r',encoding='UTF-8')
text.delete(0.0,END)
text.insert(END,f.read())
f.close()
TargetFileName=str(re.findall(r'[0-9]+',s)[0])+'-std.txt'
TargetFile.set(TargetFileName)
unmodified_flag=False
def Save():
global unmodified_flag
answer=tkinter.messagebox.askquestion("Save", "Sure To Save?")
if answer=='yes' :
unmodified_flag=True
TargetFileStr=SourcePath.get()+TargetFile.get()
f=open(TargetFileStr,'w',encoding='UTF-8')
f.write(text.get(0.0,END))
f.close
index=int(re.findall(r'[0-9]+',SourceFile.get())[0])
SourceFileStr=SourceFile.get()
SourceFileStr=re.sub(r'[0-9]+',repr(index+1),SourceFileStr)
SourceFile.set(SourceFileStr)
unmodified_flag=True
def Query():
dic,url_list=dictionary.getdict()
word_list=[]
for ele in dic:
word_list.append(ele["Word"])
queryword=queryLabel.clipboard_get()
if queryword in word_list:QueryResult.set(queryword+' is IN dictionary')
else:QueryResult.set(queryword +' is NOT in dictionary')
def check(flag):
if (flag):Query()
def boolassign(assignstr):
print(assignstr)
exec(assignstr)
def reportEvent(event):
Query()
def main():
unmodified_flag=True
tf_text=Entry(tail,width=20,textvariable=TargetFile)
#<head>
#<SourcePath>
label1=Label(head,text="SourcePath")
label1.pack(side=LEFT,)
SourcePath.set('corpus/')
sp_text.pack(side=LEFT,)
#<SourcePath/> var:SourcePath
#<SourceFile>
label2=Label(head,text="SourceFile")
label2.pack(side=LEFT,)
start_index=input("Which article to train first('x' or 'x-fmm')")
SourceFile.set(start_index+'.txt')
sf_text.pack(side=LEFT)
#<SourceFile/>var:SourceFile
#<Button>
ButtonLoad=Button(head,text='Load',command=lambda foo=0:Load())
ButtonLoad.pack(side=LEFT)
head.pack(side=TOP,expand=YES,anchor=NW,fill=X)
#<Button/>
##<head/>
##<text_frame>
#<text>
text.bind('<Control-q>',reportEvent)
## text.bind('<Control_R>',reportEvent)
## text.bind('<C>',reportEvent)
## text.bind('<KeyPress>',reportEvent)
text.pack(side=TOP,fill=Y)
#<text/>
text_fr.pack(expand=NO)
queryButton.pack(side=LEFT,fill=X)
queryLabel.pack(side=LEFT,fill=X,padx=10)
##<text_frame/>
##<tail>
#<TargetFile>
label_instruct=Label(tail,text="说明:使用Ctrl+c将待查文字复制到剪贴板\n使用Ctrl+q快速查询\n会自动更新保存位置与下一篇待训练文章,注意检查其是否正确\n")
label_instruct.pack(side=TOP,expand=NO,anchor=W)
label3=Label(tail,text="TargetFile")
label3.pack(side=LEFT,expand=YES,fill=X)
TargetFile.set('TargetFile')
tf_text.pack(side=LEFT,expand=YES,fill=X)
#<TargetFile/>var:TargetFile
#<ButtonSave>
ButtonSave=Button(tail,text='Save',command=lambda foo=0:Save())
ButtonSave.pack(side=LEFT)
#<ButtonSave//>
tail.pack(side=TOP)
##<tail>
ButtonLoad.focus()
mainloop()
main()