Ruby Cookbook question

B

Bharat Ruparel

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.

Thanks in advance.

Bharat
 
J

Jan Svitok

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:

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

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

Bharat Ruparel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top