Class: BowTfidf::BagOfWords

Inherits:
Object
  • Object
show all
Defined in:
lib/bow_tfidf/bag_of_words.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBagOfWords

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

#categoriesObject (readonly)

Returns the value of attribute categories.



3
4
5
# File 'lib/bow_tfidf/bag_of_words.rb', line 3

def categories
  @categories
end

#wordsObject (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