本文整理汇总了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)