lib/fisher_classifier.rb in fisher_classifier-0.0.3 vs lib/fisher_classifier.rb in fisher_classifier-0.0.4

- old
+ new

@@ -17,44 +17,37 @@ @features = {} @categories = {} inc_feature do |feature, category| @features[category] ||= {} - - if @features[category].has_key? feature - @features[category][feature] += 1 - else - @features[category][feature] = 1 - end + @features[category][feature] ||= 0 + @features[category][feature] += 1 end inc_category do |category| - if @categories.has_key? category - @categories[category] += 1 - else - @categories[category] = 1 - end + @categories[category] ||= 0 + @categories[category] += 1 end get_features do |text| - text.split(' ') + text.split(' ').map { |s| s.downcase } end categories do [:good, :bad] end category_count do |category| - if @features.has_key?(category) - @categories[category] || 0 + if @categories.has_key?(category) + @categories[category] else 0 end end features_count do |feature, category| if @features.has_key?(category) && @features[category].has_key?(feature) - @features[category][feature] || 0 + @features[category][feature] else 0 end end