當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。