-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbooldum_nodocx.py
143 lines (124 loc) · 4.47 KB
/
booldum_nodocx.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
# -*- coding: utf-8 -*-
"""
@author: Burak Alanyalıoğlu
GitHub: @felsefesinde
Instagram: @felsefesinde
YouTube: Felsefesinde
Twitter: @felsefesinde & @binichburak
@author: Berkay Gündüz
Github: @berkaygunduzz
Instagram: berkay.gz
"""
class Booldum:
"""
A class which represents Booldum app
...
Attributes
----------
__text : str
text to be corrected
__corrected_words_file : file
a file that contains corrected words
__correct_words : list
a list that contains coreect words
__wrong_words_file : file
a file that contains wrong words
__correct_words : list
a list that contains wrong words
Methods
-------
__word_in_text(word)
Returns desired word in a part of text
__set_words()
Set word lists by word files
change_wrong_words()
Correct wrong words if user wants to change
__write_txt()
Create a .txt file that contains text
write_edited_text()
Create a folder that contains text and print the text
get_tect()
Returns text
exit()
Exits app
"""
def __init__(self):
self.__text = ""
self.__corrected_words_file = open("correct_words.txt", "r")
self.__correct_words = []
self.__wrong_words_file = open("wrong_words.txt", "r")
self.__wrong_words = []
self.__set_words()
def __word_in_text(self, word):
"""Returns desired word in a part of text
Parameters
----------
word : str
Desired word to be return in text
"""
length = len(word)
position = self.__text.find(word)
new_text = self.__text[position:position + length + 15]
return new_text
def __set_words(self):
"""Set word lists by word files
"""
for corrected_word in self.__corrected_words_file:
self.__correct_words.append(corrected_word[:-1])
for wrong_word in self.__wrong_words_file:
self.__wrong_words.append(wrong_word[:-1])
def change_wrong_words(self):
"""Correct wrong words if user wants to change
"""
print("Booldum uygulamasına hoş geldiniz!")
self.__text = input("Lütfen metninizi giriniz: ")
for wrong_word in self.__wrong_words:
wrong_word_index = self.__text.find(wrong_word)
if wrong_word_index > 0:
change = input(f"Metninizde geçen '{wrong_word}'\n" +
"ifadesinin şapka ile yazılıp " +
"yazılmayacağını kontrol ediniz.\n" +
"Metindeki yeri şu şekilde:" +
f"'...{self.__word_in_text(wrong_word)}...'\n" +
"Gerekli değişiklik yapılsın mı? " +
"[Evet: e | Hayır: h]: ")
try:
if change.upper() == "E":
wrong_word_index = self.__wrong_words.index(wrong_word)
correct_word = self.__correct_words[wrong_word_index]
edited = self.__text.replace(wrong_word, correct_word)
self.__text = edited
elif change.upper() == "H":
print(f"Kelime '{wrong_word}' aynı bırakıldı!")
else:
raise(IndexError(f"Geçersiz işlem komutu: {change}"))
except IndexError as e:
print("İşlem atlandı!")
print(f"Kelime '{wrong_word}' aynı bırakıldı!")
def __write_txt(self):
"""Create a .txt file that contains text
"""
with open("Booldum_Metin.txt", "w", encoding="utf-8") as edited:
edited.write(self.__text)
def write_edited_text(self):
"""Create a folder that contains text and print the text
"""
self.__write_txt()
print(f"İşte metninizdeki şapka hatalarının Booldum tarafından " +
"düzeltilmiş hâli:\n" +
f"{self.__text}")
def get_text(self):
"""Returns text
"""
return self.__text
def exit(self):
"""Exits app
"""
self.__corrected_words_file.close()
self.__wrong_words_file.close()
input("Kapatmak için Enter tuşuna basınız...")
if __name__ == "__main__":
booldum = Booldum()
booldum.change_wrong_words()
booldum.write_edited_text()
booldum.exit()