From: Jan Svitok Date: 2007-01-08T03:03:55+09:00 Subject: Re: Ruby Cookbook question On 1/6/07, Bharat Ruparel wrote: > Hello All, > This is a question from Ruby Cookbook by Lucas Carlson & Leonard > Richardson, Oreilly Publication. Recipe number 1.20 in Chapter 1 on > page 37. > As instructed in the book, I am trying to use the classifer gem to do > Bayesian Analysis. It advises me to install the classifer gem by using > the 'gem install classifer' command. gem asks me if I want to install > the stemmer gem as a dependency, I say yes and it installs it. > > Next, I am trying to check if everything works by running a snippet out > of the README file from the classifer gem install directory as follows: > > test.rb which contains the following lines of code: > > require 'classifier' > b = Classifier::Bayes.new 'Interesting', 'Uninteresting' > b.train_interesting "here are some good words. I hope you love them" > b.train_uninteresting "here are some bad words, I hate you" > b.classify "I hate bad words and you" # returns 'Uninteresting' > > When I run it, I get the following error: > > >ruby test.rb > Notice: for 10x faster LSI support, please install > http://rb-gsl.rubyforge.org/ > c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/bayes.rb:95:in > `method_missing': undefined method `stem' for "here":String > (NoMethodError) > from > c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/extensions/word_hash.rb:32:in > `each' > from > c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/extensions/word_hash.rb:32:in > `word_hash_for_words' > from > c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/extensions/word_hash.rb:20:in > `word_hash' > from > c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/bayes.rb:26:in > `train' > from (eval):1:in `method_missing' > from > c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/bayes.rb:95:in > `eval' > from > c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/bayes.rb:95:in > `method_missing' > from > c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/bayes.rb:95:in > `each' > from > c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/bayes.rb:95:in > `method_missing' > from test.rb:3 > >Exit code: 1 > > I contacted the author, Lucas Carlson, concerning this and he advised me > to install the stemmer gem by doing 'gem install stemmer' command. I > have done that already by answering Yes to the question by gem installer > if the dependency gem should be installed? I can also see the stemmer > gem that has been installed in the gems directory. Mind you, this > happens both in Linux and Windows operating systems, therefore, there is > something that I must be overlooking. I haven't heard back from the > author. Therefore, I am posting this question here on the forum to see > if anyone can help. 1. You can check you have the stemmer installed ok by running the following script, outside of the gems dir: require 'rubygems' require 'stemmer' puts 'here'.stem #=> 'here' if it raises an exception (method missing or similar), the stemmer is not installed correctly. 2. make sure that rubygems are required in the test script (either directly or by -rubygems paramter to ruby or by using RUBYOPT environment variable AND that stemmer is required somewhere (you can fix it temporarily by running ruby -rubygems -rstemmer test.rb - if that works, there's missing require line somewhere).