-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
409 lines (333 loc) · 14 KB
/
main.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
import sys
import os
import time
path = os.getcwd()
sys.path.insert(1,path + '/functions/')
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtCore import QSize, QDir, Qt,QTimer
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QPixmap, QBrush, QIcon, QPainter, QColor, QPen,QCursor
from KelimeTurkceMi import kelime_Turkcemi
from dogruYanlisKelime import dogruBilinenYanlislar
from SimurgKelimeTemizle import metin_temizle,kelime_temizle
from SimurgCumleOlustur import cumle_olustur
from EtkenEdilgen import etkenEdilgen
from OzneYuklemIliskisi import ozneYuklem
from KelimeAyirma import cumle_kelime_ayir
from EsAnlamli import *
class Kelime:
def __init__(self, indis, kelime, renk, cumleindis,cumlerenk):
self.indis = indis
self.kelime = kelime
self.renk = renk
self.cumleindis=cumleindis
self.cumlerenk=cumlerenk
class Cumle:
def __init__(self, indis, cumle, renk):
self.indis = indis
self.cumle = cumle
self.renk = renk
class MainWindow(QMainWindow):
fileName=""
sonuc_text=[]
sonuc_cumle_text=[]
RedColor=QColor(255, 0, 0)
OrangeColor=QColor(110, 125, 0)
YellowColor=QColor(250, 230, 94)
PurpleColor=QColor(0, 0, 255)
WhiteColor=QColor(0, 0, 0) #Darkmode için (255,255,255) olmalıdır.
TransparentColor=QColor("transparent")
olusturuldu=0
aktifIndis=0
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(1030, 650))
self.setWindowTitle("Simurg")
self.toolbar_init()
self.simurgSetIcon()
self.textareaMain()
self.textareaSimurg()
self.selectItem()
self.chooseSimurgFunciton()
self.showLegand()
self.fileName = None
def showLegand(self):
self.label = QLabel(' - Doğru Bilinen Yanlış Kelimeler', self)
self.label.move(47,606)
self.label.adjustSize()
self.label2 = QLabel(' - Etken-Edilgen Kuralına Uymayan Cümleler', self)
self.label2.move(47,626)
self.label2.adjustSize()
self.label3 = QLabel('- Kelime Kökeni Türkçe Mi? ', self)
self.label3.move(580,606)
self.label3.adjustSize()
self.label4 = QLabel('- Özne Yüklem Uyumsuzluğu', self)
self.label4.move(580,626)
self.label4.adjustSize()
self.show()
def paintEvent(self, e):
painter = QPainter(self)
painter.setPen(QPen(Qt.black, 1, Qt.SolidLine))
painter.setBrush(QBrush(Qt.red))
painter.drawRect(10, 610, 30,10)
painter2 = QPainter(self)
painter2.setPen(QPen(Qt.black, 1, Qt.SolidLine))
painter2.setBrush(QBrush(Qt.yellow))
painter2.drawRect(10, 630, 30,10)
painter3 = QPainter(self)
painter3.setPen(QPen(Qt.black, 1, Qt.SolidLine))
painter3.setBrush(QBrush(Qt.blue))
painter3.drawRect(540, 610, 30,10)
painter4 = QPainter(self)
painter4.setPen(QPen(Qt.black, 1, Qt.SolidLine))
painter4.setBrush(QBrush(Qt.darkYellow))
painter4.drawRect(540, 630, 30,10)
def simurgSetIcon(self):
self.setWindowIcon(QIcon(path+'/image/simurg.png'))
labelImage = QLabel(self)
pixmap = QPixmap(path + '/image/simurg.png')
labelImage.setPixmap(pixmap)
labelImage.resize(100,100)
labelImage.move(492,270)
def toolbar_init(self):
text=QPlainTextEdit()
outputText = QTextEdit()
# Ana başlık
file_toolbar = QToolBar("Dosya İşlemleri")
file_menu = self.menuBar().addMenu("&Dosya İşlemleri")
# Dosya Aç
open_file_action = QAction("Dosya Aç", self)
open_file_action.setStatusTip("Dosya Aç")
open_file_action.triggered.connect(self.chooseFile)
file_menu.addAction(open_file_action)
# Kaydet
file_toolbar.addAction(open_file_action)
save_file_action = QAction("Kaydet", self)
save_file_action.triggered.connect(self.file_save)
file_menu.addAction(save_file_action)
file_toolbar.addAction(save_file_action)
# Farklı Kaydet
saveas_file_action = QAction("Farklı Kaydet", self)
saveas_file_action.triggered.connect(self.file_saveas)
file_menu.addAction(saveas_file_action)
file_toolbar.addAction(saveas_file_action)
def update_title(self):
self.setWindowTitle("%s - PyQt5 Notepad" %(os.path.basename(self.path)
if self.path else "Untitled"))
def _save_to_path(self, path):
text = self.text.toPlainText()
try:
with open(path, 'w') as f:
f.write(text)
except Exception as e:
self.dialog_critical(str(e))
else:
self.path = path
self.update_title()
def file_save(self):
if self.fileName is None:
return self.file_saveas()
self._save_to_path(self.fileName)
def file_saveas(self):
fileName, _ = QFileDialog.getSaveFileName(self, "Save file", "",
"Text documents (*.txt);All files (*.*)")
if not fileName:
return
self._save_to_path(fileName)
def chooseSimurgFunciton(self):
pybutton = QPushButton('Fonksiyonu Uygula', self)
pybutton.resize(150,32)
pybutton.move(725, 40)
pybutton.clicked.connect(self.fonksiyonUygula)
def chooseFile(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
self.fileName, _ = QFileDialog.getOpenFileName(self,"QFileDialog.getOpenFileName()", "","All Files (*);;Python Files (*.py)", options=options)
self.text.setPlainText(open(self.fileName).read())
if self.fileName:
print(self.fileName)
def textareaMain(self):
self.text = QPlainTextEdit(self)
self.text.move(10,90) #1.para sol sağ 2. para alt-üst
self.text.resize(480,500)
self.text.textChanged.connect(self.sonucDizisiOlustur)
self.text.selectionChanged.connect(self.handleSelectionChanged)
self.text.setContextMenuPolicy(Qt.CustomContextMenu)
self.text.customContextMenuRequested.connect(self.showMenu)
def handleSelectionChanged(self):
cursor = self.text.textCursor()
self.select_start = cursor.selectionStart()
self.select_end = cursor.selectionEnd()
#print ("Selection start: %d end: %d" % (cursor.selectionStart(), cursor.selectionEnd()))
string=str(self.text.document().toPlainText())
#print("\033[1;31m"+string[cursor.selectionStart():cursor.selectionEnd()]+"\033[0m")
word=string[cursor.selectionStart():cursor.selectionEnd()]
self.selected_word=string[cursor.selectionStart():cursor.selectionEnd()]
redColor = QColor(255, 0, 0)
blue = QColor(0, 0, 255)
def showMenu(self,pos):
contextMenu = QMenu(self)
acts = list()
es_anlamlilar = list()
es_anlamlilar = es_anlamli_kelimeler(self.selected_word)
if(len(es_anlamlilar) > 0):
for i in es_anlamlilar:
acts.append(contextMenu.addAction(i))
else:
acts.append(contextMenu.addAction("-----------------------------"))
acts.append(contextMenu.addAction("Eş anlamlı kelime bulunamadı."))
acts.append(contextMenu.addAction("-----------------------------"))
action = contextMenu.exec(self.mapToGlobal(pos))
old_text = self.text.document().toPlainText()
for i in range(len(acts)):
if acts[i] == action:
new_text = old_text[0:self.select_start] + es_anlamlilar[i] + old_text[self.select_end:len(old_text)]
self.text.document().setPlainText(new_text)
#print(es_anlamlilar[i])
"""
for i in range(len(acts)):
if acts[i] == action:
print(es_anlamlilar[i])"""
def textareaSimurg(self):
self.outputText = QTextEdit(self)
self.outputText.move(540,90) #1.para sol sağ 2. para alt-üst
self.outputText.resize(480,500)
def selectItem(self):
self.combo_box = QComboBox(self)
self.combo_box.setGeometry(75,40,300,31)
geek_list = ["Lütfen Bir Fonksiyon Seçin","Doğru Bilinen Yanlışlar","Kelime Türkçe Mi?","Özne-Yüklem Uyumsuzluğu","Etken Edilgen Çatı Uyumsuzluğu","Birleşikleri Ayır"]
self.combo_box.addItems(geek_list)
self.combo_box.setCurrentIndex(0)
self.combo_box.currentIndexChanged.connect(self.selectionchange)
def selectionchange(self,i):
self.aktifIndis=i
def fonksiyonUygula(self):
if(self.aktifIndis==0):#DogruYanlişFonksiyonu
pass
if(self.aktifIndis==1):#DogruYanlişFonksiyonu
self.outputText.clear()
self.dogruYanlis()
if(self.aktifIndis==2):#KelimeTurkcemiFonksiyonu
self.outputText.clear()
self.turkceKelime()
if(self.aktifIndis==3):#OzneYüklemUyumsuzluğu
self.outputText.clear()
self.ozneYuklemKontrol()
if(self.aktifIndis==4):#EtkenEdilgenÇatıUyumsuzluğu
self.outputText.clear()
self.etkenEdilgenKontrol()
if(self.aktifIndis==5):#BirleşikKelime
self.outputText.clear()
self.text.setPlainText(cumle_kelime_ayir(self.text.document().toPlainText()))
self.olusturuldu=0
islem_goren_metin_dizisi={}
def etkenEdilgenKontrol(self):
if(self.olusturuldu==0):
self.sonucDizisiOlustur()
count=0
for i in self.sonuc_cumle_text:
#print(str(i.cumle)+str(i.indis))
s=etkenEdilgen(i.cumle)
if s==0:
if(self.sonuc_cumle_text[count].renk==self.TransparentColor):
self.sonuc_cumle_text[count].renk=self.TransparentColor
else:
self.sonuc_cumle_text[count].renk=self.YellowColor
for z in self.sonuc_text:
if(z.cumleindis==count):
z.cumlerenk=self.YellowColor
#print(z.cumlerenk)
count=count+1
self.ciktiYazdir()
def ozneYuklemKontrol(self):
if(self.olusturuldu==0):
self.sonucDizisiOlustur()
count=0
for i in self.sonuc_cumle_text:
#print(str(i.cumle)+str(i.indis))
s=ozneYuklem(i.cumle)
if s==0:
if(self.sonuc_cumle_text[count].renk==self.TransparentColor):
self.sonuc_cumle_text[count].renk=self.TransparentColor
else:
self.sonuc_cumle_text[count].renk=self.OrangeColor
for z in self.sonuc_text:
if(z.cumleindis==count):
z.cumlerenk=self.OrangeColor
#print(z.cumlerenk)
count=count+1
self.ciktiYazdir()
def turkceKelime(self):
self.outputText.clear()
metin_dizisi=[]
metin_dizisi.clear()
islenmemis_metin=[]
islenmemis_metin=str(self.text.document().toPlainText()).split(" ")
metin=self.text.document().toPlainText()
metin_dizisi=metin_temizle(metin)
if(self.olusturuldu==0):
self.sonucDizisiOlustur()
count=0
for i in self.sonuc_text:
s=kelime_Turkcemi(i.kelime)
if s in "True" :
if(self.sonuc_text[count].renk==self.WhiteColor):
self.sonuc_text[count].renk=self.WhiteColor
else:
self.sonuc_text[count].renk=self.PurpleColor
count=count+1
self.ciktiYazdir()
def dogruYanlis(self):
self.outputText.clear()
metin_dizisi=[]
metin_dizisi.clear()
islenmemis_metin=str(self.text.document().toPlainText()).split(" ")
metin=self.text.document().toPlainText()
metin_dizisi=metin_temizle(metin)
count=0
if(self.olusturuldu==0):
self.sonucDizisiOlustur()
for i in self.sonuc_text:
if str(dogruBilinenYanlislar(kelime_temizle(i.kelime))) in "None" :
if(self.sonuc_text[count].renk==self.WhiteColor):
self.sonuc_text[count].renk=self.WhiteColor
else:
self.sonuc_text[count].renk=self.RedColor
self.sonuc_text[count].kelime=str(dogruBilinenYanlislar(kelime_temizle(i.kelime)))
count=count+1
self.ciktiYazdir()
def sonucDizisiOlustur(self):
self.sonuc_text.clear()
self.sonuc_cumle_text.clear()
self.olusturuldu=1
sayacCumle=0
sayacKelime=0
cumle_isle=cumle_olustur(self.text.document().toPlainText())
for i in cumle_isle:
self.sonuc_cumle_text.append(Cumle(sayacCumle,i,self.WhiteColor))
x=str(i).split(" ")
for j in x:
self.sonuc_text.append(Kelime(sayacKelime,j,self.WhiteColor,sayacCumle,self.TransparentColor))
sayacKelime=sayacKelime+1
sayacCumle=sayacCumle+1
#metin_isle=str(self.text.document().toPlainText()).split(" ")
#for a in metin_isle:
# self.sonuc_text.append(Kelime(sayac,a,self.WhiteColor))
# sayac=sayac+1
def ciktiYazdir(self):
self.outputText.clear()
for a in self.sonuc_text:
self.outputText.setTextBackgroundColor(a.cumlerenk)
self.outputText.setTextColor(a.renk)
self.outputText.insertPlainText(a.kelime+" ")
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv) #def
mainWin = MainWindow()
mainWin.move(400,250)
splash = QSplashScreen(QPixmap(path+'/image/clutch.jpg'))
splash.resize(1030,700)
splash.move(400,210)
splash.show()
QTimer.singleShot(1500, splash.close)
mainWin.show()
sys.exit( app.exec_() )