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


Python Markov.find_context方法代码示例

本文整理汇总了Python中markov.Markov.find_context方法的典型用法代码示例。如果您正苦于以下问题:Python Markov.find_context方法的具体用法?Python Markov.find_context怎么用?Python Markov.find_context使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在markov.Markov的用法示例。


在下文中一共展示了Markov.find_context方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AveryBot

# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import find_context [as 别名]

#.........这里部分代码省略.........
        c.join(self.cafe)

        def birthday():
            age = int(open(self.agefile, 'r').read()) + 1
            c.action(self.cafe, "is %s years old today!" % age)
            print(age, file=open(self.agefile, 'w'))
            self.at_bday(birthday)

        self.at_bday(birthday)

    # cache each channel's mode
    def on_join(self, c, e):
        if e.source.nick == self.nick:
            c.mode(e.target, "")

    # basically borrowed from irc.bot.py's _on_mode(), since this library is a
    # god damn piece of shit
    def on_channelmodeis(self, c, e):
        print("debugging mode change:", e.arguments[1])
        modes = irc.modes.parse_channel_modes(e.arguments[1])
        t = e.arguments[0]
        ch = self.channels[t]
        for mode in modes:
            if mode[0] == '+':
                f = self.channels[t].set_mode(mode[1], mode[2])
            else:
                f = self.channels[t].clear_mode(mode[1], mode[2])

    def talk(self, args, diag=False):
        for i in range(3):
            if len(args) == 0:
                sentence = markov.prettify(self.mind.gen(), diag)
            elif len(args) == 1:
                k = self.mind.find_context(args[0])
                if k is not None:
                    sentence = markov.prettify(self.mind.gen_out(k), diag)
                else:
                    return "i don't know anything about " + args[0]
            elif len(args) == 2:
                k = self.mind.find_context(args)
                if k is not None:
                    sentence = markov.prettify(self.mind.gen_out(k), diag)
                else:
                    return "i don't know anything about " + " ".join(args)

            else:
                return "i can only talk about one (or maybe two) things at a time"

            for channel in self.channel:
                if channel not in self.channels:
                    print("AVEBOT ERROR: oh fuck this shouldn't actually happen")
                    return "i broke"

            # catch line length
            if len(sentence) > 450: # this should probably be good
                print("message too long.  retrying")
                continue

            # prevent convoing
            if sentence.startswith("!"):
                continue

            # prevent hilights
            tryagain = False
            for nope in self.blacklist:
                # generate non-blacklisted nick
开发者ID:anachrome,项目名称:averybot,代码行数:70,代码来源:averybot.py


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