本文整理汇总了Python中dictionary.Dictionary.find_similar方法的典型用法代码示例。如果您正苦于以下问题:Python Dictionary.find_similar方法的具体用法?Python Dictionary.find_similar怎么用?Python Dictionary.find_similar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dictionary.Dictionary
的用法示例。
在下文中一共展示了Dictionary.find_similar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkFile
# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import find_similar [as 别名]
def checkFile(file_name, dictionary_file="words.dat"):
# Set up dictionary based on words.dat
d = Dictionary(file_name=dictionary_file)
d.statistics()
file_in = open(file_name, 'r')
file_out = open("{}.out".format(file_name), 'w')
current_word = ""
starting_sentence = True
while True:
# Read one character at a time from the input file
next_char = file_in.read(1)
# Exit the loop when there's nothing else to read
if not next_char:
break
if next_char in d.ALLOWED_LETTERS:
current_word += next_char
elif current_word:
# Verify the current_word with the dictionary
resp, current_word = d.verify(current_word,
begins_sentence=starting_sentence)
if not resp: # Word was not found in dictionary
resp, new_word = getUserResponse(current_word,
d.find_similar(current_word))
d.update(resp, current_word, new_word)
current_word = new_word
file_out.write(current_word)
current_word = ""
file_out.write(next_char)
# Reset the sentence tracker
starting_sentence = False
else:
file_out.write(next_char)
if next_char == '.':
# After we've already handled the word, then check if we're
# starting a new sentence.
starting_sentence = True
file_in.close()
file_out.close()
print("Spellchecked file written to {}.out.".format(file_name))