-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.py
More file actions
76 lines (62 loc) · 2.29 KB
/
check.py
File metadata and controls
76 lines (62 loc) · 2.29 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
# -*- coding: utf-8 -*-
from spellchecker import SpellChecker
import process
spell = SpellChecker()
NOT_ACCEPTABLE_LANGUAGE = ['kid', 'kids', 'pal', 'pals', 'folks', 'mate', 'mates', 'stupid',
'dumb', 'so', 'guy', 'guys', 'teens', 'too']
symbols = [".", ",", ":", "-", "!", "?", " ", '', '\n']
def find_mistakes(s, tumbler=True):
responde = s
if tumbler:
responde = process.array_to_string(process.count_words(s))
responde = process.array_to_string(words(responde))
responde = process.array_to_string(comma(responde))
responde = process.array_to_string(shortcut(responde))
return responde
def shortcut(s):
a = process.divide_to_words(s)
def check_forshortcut(word):
shortcuts = ["'re", "`re", "`m", "'m", "n`t", "n't", "`ll", "'ll"]
for letter in word:
if letter == "'" or letter == "`":
for shortcut in shortcuts:
if shortcut in word:
return True
return False
responde = []
for i in a:
if check_forshortcut(i):
responde.append(i + "(K1 ❌)(Shortcuts are not allowed!)")
else:
responde.append(i)
return responde
def comma(s):
a = process.divide_to_words(s)
yes_comma = ['which', 'but']
no_comma = ['that', 'because']
for i in range(len(a)):
if a[i].lower() in yes_comma:
if a[i - 2] != ',' and a[i - 1] != ',':
a[i] = a[i] + '(K5 ❌)(Missing comma)'
if a[i].lower() in no_comma:
if a[i - 2] == ',' or a[i - 1] == ',':
a[i] = a[i] + '(K5 ❌)(Extra comma)'
return a
def words(a):
a = process.divide_to_words(a)
responde = []
for i in a:
if i in NOT_ACCEPTABLE_LANGUAGE:
responde.append(i + f"(К3 ❌)")
elif i not in symbols:
if i == "i":
responde.append(i + f"(К5 ❌)(Expect \"I\" instead of \"i\" !) ")
elif i.lower() == 'cannot':
responde.append(i)
elif "'" or "`" in i:
responde.append(i)
elif spell.correction(i.lower()) != i.lower() and ('[' not in i) and (']' not in i):
responde.append(i + f"(К5 ❌)")
else:
responde.append(i)
return responde