コード例 #1
0
ファイル: checker.py プロジェクト: Galythia/bootcamp-python
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

コード例 #2
0
                break
            index, word = 0, ""
    elif index > 0:
        words++
        before = time.process_time()
        mispelled = not check(word)
        after = time.process_time()

        time_check += after-before

        if mispelled:
            print(word)
            mispellings++
        index, word = 0, ""
file.close()

before = time.process_time()
n = size()
after = time.process_time()

time_size = after-before

before = time.process_time()
unloaded = unload()
after = time.process_time()

if not unload:
    print(f"Could not unload  {dictionary}")
    exit(1)

コード例 #3
0
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