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


Python Dictionary.setCount方法代码示例

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


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

示例1: Trainer

# 需要导入模块: from Dictionary import Dictionary [as 别名]
# 或者: from Dictionary.Dictionary import setCount [as 别名]
class Trainer(ResourceManager):
    """ Training corpus"""

    def __init__(self, depth=int, **kwargs):
        super().__init__(**kwargs)
        self.__totalLetter = 0
        self.depth = 1
        self.dictionary = Dictionary()


    def initialize(self, depth=int):
        root = Dictionary()
        io = IOHandler()

        io.countLetter()

        lst = io.getLetter()
        
        while True:
            try:
                tmp = lst.popitem()
                self.__totalLetter += int(tmp[1])
                root.addChild(Dictionary(tmp[1], io.mapCharacter(tmp[0]), tmp[0]))
            except KeyError:
               break
        self.dictionary = root
        self.dictionary.setCount(self.__totalLetter)



        if depth <= 2:
            return False

        for currentDepth in range(2, depth + 1):
            io.loadWords(currentDepth)
            lst = io.getWords()
            while True:
                try:
                    tmp = lst.popitem()
                    #if not root.probe(tmp[0]):
                        #word is unknown
                    self.__addWord(tmp, root, io)
                except KeyError:
                    break
            self.dictionary = root
            self.depth = currentDepth
            self.save("TrainerDepth", currentDepth)
            print("DEBUG Current depth: ", currentDepth)
  


    def __addWord(self, tupel, root=Dictionary, io=IOHandler):
        """ Adds a word to the tree, letter by letter"""
        word = tupel[0]
        count = tupel[1]
        subword = ''
        node = root
        for letter in word:
            subword += letter
            tmp = node.getChild(subword)
            if not tmp:
                if subword == word:
                    node.addChild(Dictionary(count, io.mapCharacter(subword[-1]), subword))
                else:
                    break
            node = tmp
                

    def getLetter(self):
        return self.__totalLetter

    def getWord(self):
        return self.__totalWord

    def save(self, name=str, depth=int):
        n = name + str(depth)
        return super().save(n)

    def restore(self, name=str, depth=int):
        n = name + str(depth)
        return super().restore(n)
开发者ID:storgi,项目名称:ASP,代码行数:83,代码来源:Trainer.py


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