當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。