From: Charlie Bowman Date: 2006-04-07T22:53:16+09:00 Subject: Re: [QUIZ] Markov Chains (#74) --=-eezw3uGhq9txTVgxZPdu Content-Type: text/plain Content-Transfer-Encoding: 7bit I'm pumped! I've been reading this mailing list for the last 3 months and I finally feel ready to try out a quiz. This one sounds fun! On Fri, 2006-04-07 at 22:02 +0900, Ruby Quiz wrote: > The three rules of Ruby Quiz: > > 1. Please do not post any solutions or spoiler discussion for this quiz until > 48 hours have passed from the time on this message. > > 2. Support Ruby Quiz by submitting ideas as often as you can: > > http://www.rubyquiz.com/ > > 3. Enjoy! > > Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone > on Ruby Talk follow the discussion. > > -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= > > This week's Ruby Quiz is about text generation. That's right, we're going to > teach your computer to weave tall tales. > > At its most basic level, a solution might be: > > >> (1..30).map { (("a".."z").to_a + [" "] * 10)[rand(36)] }.join > => "fb mcr hhluesjbhtf swm eehokmi" > > However, let's make our goal to get as close to English looking sentences as > possible. One way you might do this is using a technique called Markov Chains. > > To use Markov Chains, you read some text document(s), making note of which > characters commonly follow which characters or which words commonly follow other > words (it works for either scale). Then, when generating text, you just select > a character or word to output, based on the characters or words that came before > it. > > The number of previous characters or words considered is called the "order" and > you can adjust that to try and find a natural feel. For example, here is some > generated text using a second order word chain derived from the Sherlock Holmes > novel "The Hound of the Baskervilles" by Arthur Conan Doyle: > > The stars shone cold and bright, while a crushing weight of responsibility > from my shoulders. Suddenly my thoughts with sadness. Then on the lady's > face. "What can I assist you?" > > If you need text's to prime your program with, I suggest searching Project > Gutenberg: > > http://www.gutenberg.org/ > --=-eezw3uGhq9txTVgxZPdu--