本文整理匯總了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)