Exemple #1
0
before time.process_time()
loaded = load(dictionary)
after time.process_time()

if not loaded:
    exit("Could not load {dictionary}.")

time_load = ater-before

text = argv[2] if len(argv) == 3 else argv[1]
file = open(text, "r", encoding="latin_1")

if not file:
    print(f"Colud not open {text}.")
    unload()
    exit(1)

print("\nMISPELLED WORDS\n")

index, mispellings, word = 0, 0, 0
word = ""

while True:
    c = file.read(1)
    if not c:
        break
    if re.match(r"[A-Za-z]", c) or ( c== "'" index > 0):
        word += c
        index += 1
start = time.clock()

dict = dictionary.load(dictionary_name)
if dict is None:
    print "dictionary load failed"
    sys.exit(-1)

text_file = open(text_file_name, "rb")
misspelled = set()
num_total = 0
for line in text_file:
    line = line.replace("-", " ")
    for word in line.split():
        word = sanitize_word(word)
        if len(word) == 0:
            continue
        if not dictionary.check(dict, word):
            num_total += 1
            misspelled.add(word)
text_file.close()

print misspelled
print "dictionary size: %d" % dictionary.size(dict)
print "num misspelled: %d" % num_total
print "num unique: %d" % len(misspelled)

dictionary.unload(dict)

stop = time.clock()
print "time (s):", stop - start
Exemple #3
0
dict = dictionary.load(dictionary_name)
if dict is None:
    print "dictionary load failed"
    sys.exit(-1)

text_file = open(text_file_name, "rb")
misspelled = set()
num_total = 0
for line in text_file:
    line = line.replace("-", " ")
    for word in line.split():
        word = sanitize_word(word)
        if len(word) == 0:
            continue
        if not dictionary.check(dict, word):
            num_total += 1
            misspelled.add(word)
text_file.close()

print misspelled
print "dictionary size: %d" % dictionary.size(dict)
print "num misspelled: %d" % num_total
print "num unique: %d" % len(misspelled)

dictionary.unload(dict)

stop = time.clock()
print "time (s):", stop - start

Exemple #4
0
dictionary = argv[1] if len(argv) == 3 else DICTIONARY

before = time.process_time()
loaded = load(dictionary)
after = time.process_time()

if not loaded:
    exit(f"Could not load {dictionary}")

time_load = after - before

text = argv[-1]
file = open(text, "r")
if not file:
    unload()
    exit(f"could not open {text}")

print("MISSPELLED WORDS!\n")

index, misspellings, words = 0, 0, 0
word = ""
wrong_words = []

while True:
    c = file.read(1)
    if not c:
        break

    if re.match(r"[A-Za-z]", c) or (c == "'" and index > 1):
        word = word + c