Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fixes, Minor Changes and Improvements #4

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env
Booldum_Metin.txt
94 changes: 56 additions & 38 deletions booldum_nodocx.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,89 +50,107 @@ class Booldum:
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 = []
def __init__(self) -> None:
self.__text: str = ""
self.__corrected_words_file_name: str = "correct_words.txt"
self.__wrong_words_file_name: str = "wrong_words.txt"
self.__correct_words: list[str] = []
self.__wrong_words: list[str] = []
self.__set_words()

def __word_in_text(self, word):
"""Returns desired word in a part of text
def __word_in_text(self, word_index: int, length: int) -> str:
"""Returns context around given index according to the length of the word.

Parameters
----------
word : str
Desired word to be return in text
word_index : int
Desired word index to be returned

length: int
Length of the word
"""
length = len(word)
position = self.__text.find(word)
new_text = self.__text[position:position + length + 15]
new_text = self.__text[word_index:word_index + length + 15]
return new_text

def __set_words(self):
def __set_words(self) -> None:
"""Set word lists by word files
"""
for corrected_word in self.__corrected_words_file:
self.__correct_words.append(corrected_word[:-1])
with open(self.__corrected_words_file_name, "r") as corrected_words_file:
for corrected_word in 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])
with open(self.__wrong_words_file_name, "r") as wrong_words_file:
for wrong_word in wrong_words_file:
self.__wrong_words.append(wrong_word[:-1])

def change_wrong_words(self):
def change_wrong_words(self) -> None:
"""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:

# Metinde boş satır varsa çalışmıyor.
self.__text = input("Lütfen metninizi giriniz:\n")

# Burası bayağı değişti, pull requestte anlattığım nedenlerden ötürü.
i = 0
start = 0
while i < len(self.__wrong_words):
# Bu eklenti bugı tam düzeltmese de "Ankara" kelimesindeki "kar"ı bulmasını engelliyor.
wrong_word = self.__wrong_words[i]
wrong_word_index = self.__text.find(wrong_word, start)

if wrong_word_index >= 0: # 1. kelime yanlış olunca oluşan bugı düzeltiyor.
# Ankara kelimesindeki "kar" gibi kelimelerin okuyucuya sorulmadan elenmesi amaçlandı.
if wrong_word_index != 0 and self.__text[wrong_word_index - 1] not in [" ", "\t", "\n"]:
start = wrong_word_index + len(wrong_word)
continue
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" +
f"'...{self.__word_in_text(wrong_word_index, len(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
correct_word = self.__correct_words[i]
self.__text = self.__text[:wrong_word_index] + correct_word + self.__text[(wrong_word_index + len(correct_word)):]
elif change.upper() == "H":
print(f"Kelime '{wrong_word}' aynı bırakıldı!")
start = wrong_word_index + len(wrong_word)
else:
raise(IndexError(f"Geçersiz işlem komutu: {change}"))
except IndexError as e:
except IndexError:
print("İşlem atlandı!")
print(f"Kelime '{wrong_word}' aynı bırakıldı!")
else:
i += 1
start = 0

def __write_txt(self):
def __write_txt(self) -> None:
"""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):
def write_edited_text(self) -> None:
"""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}")
# Okunabilirlik için birkaç tane newline ekledim.
print(f"\nİşte metninizdeki şapka hatalarının Booldum tarafından " +
"düzeltilmiş hâli:\n\n\n" +
f"{self.__text}\n\n")

def get_text(self):
def get_text(self) -> str:
"""Returns text
"""
return self.__text

def exit(self):
def exit(self) -> None:
"""Exits app
"""
self.__corrected_words_file.close()
self.__wrong_words_file.close()
print("Yazının düzeltilmiş haline Booldum_Metin dosyasından ulaşabilirsiniz.")
input("Kapatmak için Enter tuşuna basınız...")

if __name__ == "__main__":
Expand Down
Loading