cardmagic / classifier

A general classifier module to allow Bayesian and LSI classifications.
Other
661 stars 122 forks source link

Still having problems with ActiveRecord #2

Closed masnick closed 3 months ago

masnick commented 14 years ago

Unfortunately the problem I was having before still isn't solved...here's the error I'm getting now: /Library/Ruby/Gems/1.8/gems/classifier-1.3.3/lib/classifier/extensions/vector.rb:16:insum': undefined method to_f' for []:Array (NoMethodError)

fidel commented 14 years ago

I have the same problem. I'm trying to fix this, so if I succed, I'll give you to know.

XurdeFdez commented 13 years ago

Unpack the gem in your vendor directory (gem unpack classifier) and rewrite the sum method in lib/classifier/extensions/vector.rb like this:

def sum(identity = 0, &block)
 return identity unless size > 0

 if block_given?
   map(&block).sum
 else
   a = inject( nil ) { |sum,x| sum ? sum+x : x }
   #Hack to remove the to_f error
   a.is_a?(Array) ? a : a.to_f
 end
end
argusinsights commented 13 years ago

That worked! Thanks! Any chance of cardmagic rolling this into the main branch?

Rustin commented 13 years ago

Running into the same problem. Using rails 3 I can't unpack the gem as I was used to doing in rails 2. When I fork Classifier here on github I end up with a slew of other errors on bundle install.

I'd love to hear if cardmagic might roll a fix for this issue into the main branch. Any chance?

wuyuntao commented 13 years ago

Add a monkey patch to config/initializers/classifier_hack.rb if you are using rails3

class Array
  def sum(identity = 0, &block)
    return identity unless size > 0

    if block_given?
      map(&block).sum
    else
      a = inject( nil ) { |sum,x| sum ? sum+x : x }
      # Hack to remove the to_f error
      a.is_a?(Array) ? a : a.to_f
    end
  end
end
cardmagic commented 3 months ago

Fixed in version 1.4.0 and above