forked from TdP-2024/Lab04
-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
64 lines (53 loc) · 2 KB
/
controller.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
import time
import flet as ft
import model as md
class SpellChecker:
def __init__(self, view):
self._multiDic = md.MultiDictionary()
self._view = view
def handleSentence(self, txtIn, language, modality):
txtIn = replaceChars(txtIn.lower())
words = txtIn.split()
paroleErrate = " - "
match modality:
case "Default":
t1 = time.time()
parole = self._multiDic.searchWord(words, language)
for parola in parole:
if not parola.corretta:
paroleErrate = paroleErrate + str(parola) + " - "
t2 = time.time()
return paroleErrate, t2 - t1
case "Linear":
t1 = time.time()
parole = self._multiDic.searchWordLinear(words, language)
for parola in parole:
if not parola.corretta:
paroleErrate = paroleErrate + str(parola) + " "
t2 = time.time()
return paroleErrate, t2 - t1
case "Dichotomic":
t1 = time.time()
parole = self._multiDic.searchWordDichotomic(words, language)
for parola in parole:
if not parola.corretta:
paroleErrate = paroleErrate + str(parola) + " - "
t2 = time.time()
return paroleErrate, t2 - t1
case _:
return None
def printMenu(self):
print("______________________________\n" +
" SpellChecker 101\n"+
"______________________________\n " +
"Seleziona la lingua desiderata\n"
"1. Italiano\n" +
"2. Inglese\n" +
"3. Spagnolo\n" +
"4. Exit\n" +
"______________________________\n")
def replaceChars(text):
chars = "\\`*_{}[]()>#+-.!$?%^;,=_~"
for c in chars:
text = text.replace(c, "")
return text