本文整理汇总了Python中brain.Brain.dump方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.dump方法的具体用法?Python Brain.dump怎么用?Python Brain.dump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类brain.Brain
的用法示例。
在下文中一共展示了Brain.dump方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Problem
# 需要导入模块: from brain import Brain [as 别名]
# 或者: from brain.Brain import dump [as 别名]
#.........这里部分代码省略.........
"feminine": None,
"neutral": None,
"mixed": None,
"self": None,
"ambiguous": None,
},
"last": None,
}
self.all_targets = {
"plurality": {"singular": {}, "plural": {}, "self": {}, "regular": {}},
"gender": {"masculine": {}, "feminine": {}, "neutral": {}, "mixed": {}, "self": {}, "ambiguous": {}},
"last": None,
}
self.contexts = []
self.all_contexts = {
"plurality": {"singular": {}, "plural": {}, "self": {}, "regular": {}},
"gender": {"self": {}, "masculine": {}, "feminine": {}, "neutral": {}, "mixed": {}, "ambiguous": {}},
"last": None,
}
# Engines
self.inference = None
self.question = None
self.solution = None
def digest(self):
if self.sentences is not None:
return
# Digest the problem into sentences
tokenizer = data.load("tokenizers/punkt/english.pickle")
self.sentences = tokenizer.tokenize(self.text.strip())
# Digest each sentence into words and part-of-speech tags
if self.sentence_tags is None:
sentence_tags = []
all_tags = []
all_words = []
for s in self.sentences:
all_words.append(s)
tags = pos_tag(word_tokenize(s))
sentence_tags.append(tags)
for t in tags:
l = len(t[0])
if not self.longest_word or self.longest_word < l:
self.longest_word = l
all_tags.append(t[1])
self.sentence_tags = sentence_tags
self.all_tags = uniq(all_tags)
self.all_words = uniq(all_words)
def infer(self):
if self.inference is not None:
return
self.digest()
self.inference = Inference(self)
def query(self):
if self.question is not None:
return
self.infer()
self.question = Query(self)
def solve(self):
if self.solution is not None:
return
self.query()
self.solution = Solution(self)
# Maybe move this into a different mode so you can see everything but
self.solution.compute_correct()
self.brain.dump()
def __str__(self):
o = []
o.append("# Zoidberg Solution")
if self.file_name:
o.append("File: {0}".format(self.file_name))
o.append("\n## The problem")
o.append(" " + "\n ".join(self.text.split("\n")))
o.append("## Digested problem")
output_tuples(self.sentence_tags, o, self.longest_word, self.brain)
if self.inference is not None:
o.append(str(self.inference))
if self.question is not None:
o.append(str(self.question))
if self.solution is not None:
o.append(str(self.solution))
return "\n".join(o)