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


Python Brain.dump方法代码示例

本文整理汇总了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)
开发者ID:eric011,项目名称:Zoidberg,代码行数:104,代码来源:problem.py


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