当前位置: 首页>>代码示例>>Python>>正文


Python Dictionary.statistics方法代码示例

本文整理汇总了Python中dictionary.Dictionary.statistics方法的典型用法代码示例。如果您正苦于以下问题:Python Dictionary.statistics方法的具体用法?Python Dictionary.statistics怎么用?Python Dictionary.statistics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dictionary.Dictionary的用法示例。


在下文中一共展示了Dictionary.statistics方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: checkFile

# 需要导入模块: from dictionary import Dictionary [as 别名]
# 或者: from dictionary.Dictionary import statistics [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))
开发者ID:tomhogans,项目名称:cs113,代码行数:47,代码来源:spellCheck.py


注:本文中的dictionary.Dictionary.statistics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。