Created
April 11, 2020 16:36
-
-
Save Bundi-py/6cec10e2d3804455e4c5e5240c8ca00d to your computer and use it in GitHub Desktop.
33. Spell Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import re | |
import string | |
import sys | |
wordlist_recnik = {} | |
# Otvori listu engleskih reči u odnosu na koje će dati tekst biti proveravan. | |
# Napravi rečnik u kojem je svaka od reči key. Value je 0, jer nikada neće biti korišćeno. | |
with open('c:/FAJLOVI/Python_School/Stephenson_ThePythonWorkbook/wordlist.txt', "r", encoding='utf-8') as recnik: | |
reci = recnik.readlines() | |
reci[:] = [line.rstrip('\n') for line in reci] | |
for rec in reci: | |
wordlist_recnik[rec] = 0 | |
# text = input('Unesi rečenicu: ') | |
greske = [] | |
# Provera da su dati svi argumenti. | |
if len(sys.argv) != 2: | |
print("Unesi ime fajla za slovnu analizu. Npr. >> 167.py fajl.txt") | |
quit() | |
try: | |
with open(sys.argv[1], 'r', encoding='utf-8') as tekst: | |
text = tekst.read() | |
except: | |
print("Dogodila se greška pri učitavanju fajla.") | |
quit() | |
print(text) | |
def words(text): | |
samo_reci = re.sub(r'[^\w\s]','',text) | |
lista = samo_reci.lower().split() | |
for word in lista: | |
if word not in wordlist_recnik: | |
greske.append(word) | |
print() | |
print('Ovo su reči koje treba popraviti:') | |
print(*greske, sep='\n') | |
return | |
words(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment