# Ruby Cookbook question

**URL:** <https://www.ruby-forum.com/t/ruby-cookbook-question/81198>\
**Category:** Ruby\
**Created:** [January 6, 2007, 7:01pm UTC](https://www.ruby-forum.com/t/ruby-cookbook-question/81198 "2007-01-06T19:01:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [January 6, 2007, 7:01pm UTC](https://www.ruby-forum.com/t/ruby-cookbook-question/81198/1 "2007-01-06T19:01:31Z")

</div>

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/](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.

Thanks in advance.

Bharat

---

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [January 7, 2007, 7:04pm UTC](https://www.ruby-forum.com/t/ruby-cookbook-question/81198/2 "2007-01-07T19:04:56Z")

</div>

On 1/6/07, Bharat R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> of the README file from the classifer gem install directory as follows:
> 
> c:/ruby/lib/ruby/gems/1.8/gems/classifier-1.3.0/lib/classifier/extensions/word\_hash.rb:32:in  
> `eval’
> 
> > 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.

1. 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).

---

<div class="post-metadata">

**Author:** ![bruparel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@bruparel](https://www.ruby-forum.com/u/bruparel)\
**Post date:** [January 7, 2007, 11:56pm UTC](https://www.ruby-forum.com/t/ruby-cookbook-question/81198/3 "2007-01-07T23:56:32Z")

</div>

Thank you.  
As you suggested, I checked if stemmer was installed correctly. It was.  
Then I added the line  
require ‘stemmer’ to my code and it worked.  
Regards,  
Bharat
