class Analtex::BagOfWords

Public Class Methods

new(dictionary) click to toggle source
# File lib/analtex/bag_of_words.rb, line 3
def initialize(dictionary)
  @dictionary = dictionary
end

Public Instance Methods

get_bag_of(words) click to toggle source
# File lib/analtex/bag_of_words.rb, line 7
def get_bag_of(words)
  dictionary_size = @dictionary.words.length
  bag = Array.new(dictionary_size, 0).to_a

  words.each do |word|
    index = @dictionary.words[word]
    next if index.nil?
    bag[index] = bag[index] + 1
  end

  return bag
end