Class: TfIdf
- Inherits:
-
Object
- Object
- TfIdf
- Defined in:
- lib/tf_idf.rb
Instance Method Summary collapse
- #idf ⇒ Object
-
#initialize(data) ⇒ TfIdf
constructor
n the n-grams of the data en.wikipedia.org/wiki/N-gram.
- #tf ⇒ Object
-
#tf_idf ⇒ Object
This is basically calculated by multiplying tf by idf.
Constructor Details
#initialize(data) ⇒ TfIdf
n the n-grams of the data en.wikipedia.org/wiki/N-gram
4 5 6 |
# File 'lib/tf_idf.rb', line 4 def initialize(data) @data = data end |
Instance Method Details
#idf ⇒ Object
12 13 14 |
# File 'lib/tf_idf.rb', line 12 def idf @idf ||= calculate_inverse_document_frequency end |
#tf ⇒ Object
8 9 10 |
# File 'lib/tf_idf.rb', line 8 def tf @tf ||= calculate_term_frequencies end |
#tf_idf ⇒ Object
This is basically calculated by multiplying tf by idf
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tf_idf.rb', line 17 def tf_idf tf_idf = tf.clone tf.each_with_index do |document, index| document.each_pair do |term, tf_score| tf_idf[index][term] = tf_score * idf[term] end end tf_idf end |