This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.

Classifying Text with a Bayesian Analyzer
require 'rubygems'
require 'classifier'
classifier ='Spam', 'Not spam')
classifier.train_spam 'are you in the market for viagra? we sell viagra'
classifier.train_not_spam 'hi there, are we still on for lunch?'
classifier.classify "we sell the cheapest viagra on the market"
"Spam" "Spam"
classifier.classify "lunch sounds great"
"Not spam" "Not spam"
#<Classifier::Bayes:0xb7cec7c8 #<Classifier::Bayes:0xb791a420 @categories={:Spam=>{:sell=>1, :market=>1, :for=>1, :viagra=>2, :"?"=>1}, :"Not spam"=>{:still=>1, :","=>1, :lunch=>1, :for=>1, :there=>1, :"?"=>1}}, @total_words=12>
classifier ='Interesting', 'Funny', 'Dramatic')
classifier.train 'Interesting', "Leaving reminds us of what we can part
  with and what we can't, then offers us something new to look forward
  to, to dream about."
classifier.train 'Funny', "Knock knock. Who's there? Boo boo. Boo boo
  who? Don't cry, it is only a joke."
classifier.train 'Dramatic', 'I love you! I hate you! Get out right
classifier.classify 'what!'
"Dramatic" "Dramatic"
classifier.classify "who's on first?"
"Funny" "Funny"
classifier.classify 'perchance to dream'
"Interesting" "Interesting"
classifier.untrain_funny "boo"
classifier.untrain "Dramatic", "out"