Class: BowTfidf::BagOfWords
- Inherits:
-
Object
- Object
- BowTfidf::BagOfWords
- Defined in:
- lib/bow_tfidf/bag_of_words.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#words ⇒ Object
readonly
Returns the value of attribute words.
Instance Method Summary collapse
- #add_labeled_data!(data) ⇒ Object
-
#initialize ⇒ BagOfWords
constructor
A new instance of BagOfWords.
Constructor Details
#initialize ⇒ BagOfWords
Returns a new instance of BagOfWords.
5 6 7 8 |
# File 'lib/bow_tfidf/bag_of_words.rb', line 5 def initialize @words = {} @categories = {} end |
Instance Attribute Details
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
3 4 5 |
# File 'lib/bow_tfidf/bag_of_words.rb', line 3 def categories @categories end |
#words ⇒ Object (readonly)
Returns the value of attribute words.
3 4 5 |
# File 'lib/bow_tfidf/bag_of_words.rb', line 3 def words @words end |
Instance Method Details
#add_labeled_data!(data) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bow_tfidf/bag_of_words.rb', line 10 def add_labeled_data!(data) validate_labeled_data(data) data.each do |category_key, category_words| category = category_by_key(category_key) category_words.each do |word| add_word(word, category) end end compute_tfidf end |