我正在尝试使用 bayes_motel gem 来分析一些数据。我认为我的 ruby 版本与 gem 的哈希创建之间存在不兼容:
ruby-1.9.3-p0/gems/bayes_motel-0.1.0/lib/bayes_motel/corpus.rb:89:in `[]=': can't add a new key into hash during iteration (RuntimeError)
这是gem中的相关代码:
def clean(hash, k, v)
case v
when Hash
v.each_pair do |key, value|
clean(v, key, value)
end
if v.empty?
hash.delete(k)
elsif v.size == 1 and v['other']
hash.delete(k)
end
else
if v < (@total_count * 0.03).floor
hash['other'] ||= 0
hash['other'] += v
hash.delete(k)
end
end
end
我一直在关注本教程:
http://www.mikeperham.com/2010/04/28/bayes_motel-bayesian-classification-for-ruby/
以及 gem 上的演示: