preprocessors/preprocess.rb
# compute and sum TF-IDF
compute and sum TF-IDF
compute and sum TF - IDF
def compute_tf_idf(samples)
  iter = 1
  samples.each do |s|
    tfidf = Hash.new(0)
    puts "#{iter} TF-IDF: ##{s[:id]} #{s[:author]}"
    s[:tf].each do |word, tf|
      tfidf[word] = tf * $idf[word]
      $tfidf_totals[word] += tfidf[word]
    end
    s[:tfidf] = tfidf
    iter += 1
  end
end
def compute_tf_idf ( samples ) iter = 1 samples . each do | s | tfidf = Hash . new ( 0 ) puts "#{iter} TF-IDF: ##{s[:id]} #{s[:author]}" s [ :tf ] . each do | word , tf | tfidf [ word ] = tf * $idf [ word ] $tfidf_totals [ word ] += tfidf [ word ] end s [ :tfidf ] = tfidf iter += 1 end end
compute and sum TF-IDF
compute and sum TF - IDF
samples