Skip to content

Instantly share code, notes, and snippets.

@Bundi-py
Last active April 11, 2020 16:37
Show Gist options
  • Save Bundi-py/18468915ed5fdf10565dfc1bd811cac5 to your computer and use it in GitHub Desktop.
Save Bundi-py/18468915ed5fdf10565dfc1bd811cac5 to your computer and use it in GitHub Desktop.
33. Spell Checker
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
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