Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You probably want to look into <a href="http://en.wikipedia.org/wiki/Markov_chain" rel="noreferrer">Markov Chains</a> as the basics for the bot AI. I wrote something a long time ago (the code to which I'm not proud of at all, and needs some mods to run on Python > 1.5) that may be a useful starting place for you: <a href="http://sourceforge.net/projects/benzo/" rel="noreferrer"><a href="http://sourceforge.net/projects/benzo/" rel="noreferrer">http://sourceforge.net/projects/benzo/</a></a></p> <p>EDIT: Here's a minimal example in Python of a Markov Chain that accepts input from stdin and outputs text based on the probabilities of words succeeding one another in the input. It's optimized for IRC-style chat logs, but running any decent-sized text through it should demonstrate the concepts:</p> <pre><code>import random, sys NONWORD = "\n" STARTKEY = NONWORD, NONWORD MAXGEN=1000 class MarkovChainer(object): def __init__(self): self.state = dict() def input(self, input): word1, word2 = STARTKEY for word3 in input.split(): self.state.setdefault((word1, word2), list()).append(word3) word1, word2 = word2, word3 self.state.setdefault((word1, word2), list()).append(NONWORD) def output(self): output = list() word1, word2 = STARTKEY for i in range(MAXGEN): word3 = random.choice(self.state[(word1,word2)]) if word3 == NONWORD: break output.append(word3) word1, word2 = word2, word3 return " ".join(output) if __name__ == "__main__": c = MarkovChainer() c.input(sys.stdin.read()) print c.output() </code></pre> <p>It's pretty easy from here to plug in persistence and an IRC library and have the basis of the type of bot you're talking about.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload