Class: USDA
- Inherits:
-
Object
- Object
- USDA
- Defined in:
- lib/data/sr24/classifier.rb
Instance Attribute Summary collapse
-
#classifier ⇒ Object
Returns the value of attribute classifier.
Instance Method Summary collapse
- #add_categories ⇒ Object
- #c(word) ⇒ Object
- #d(word) ⇒ Object
-
#initialize ⇒ USDA
constructor
A new instance of USDA.
- #train ⇒ Object
Constructor Details
#initialize ⇒ USDA
Returns a new instance of USDA.
12 13 14 15 16 |
# File 'lib/data/sr24/classifier.rb', line 12 def initialize @classifier = Classifier::Bayes.new add_categories train end |
Instance Attribute Details
#classifier ⇒ Object
Returns the value of attribute classifier.
10 11 12 |
# File 'lib/data/sr24/classifier.rb', line 10 def classifier @classifier end |
Instance Method Details
#add_categories ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/data/sr24/classifier.rb', line 19 def add_categories categories_path = Dir[ FBayesDir.sr24_data + "*"] @categories = categories_path.map{|path| path.gsub(FBayesDir.sr24_data, "")} @categories.each do |c| @classifier.add_category c end end |
#c(word) ⇒ Object
42 43 44 |
# File 'lib/data/sr24/classifier.rb', line 42 def c(word) @classifier.classify(word) end |
#d(word) ⇒ Object
46 47 48 |
# File 'lib/data/sr24/classifier.rb', line 46 def d(word) @classifier.classifications(word) end |
#train ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/data/sr24/classifier.rb', line 28 def train total_size = 0 @categories.each do |category| method = "train_" + category.downcase data = File.read( FBayesDir.sr24_data + category.to_s) puts category +": " + data.size.to_s @classifier.send(method, data) total_size += data.size.to_i end puts "TOTAL SIZE: #{total_size}" end |