Class: Ruigi::Word
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#document ⇒ Object
Returns the value of attribute document.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #df ⇒ Object
- #idf ⇒ Object
-
#initialize(name, count) ⇒ Word
constructor
A new instance of Word.
- #tf ⇒ Object
- #tfidf ⇒ Object
Constructor Details
#initialize(name, count) ⇒ Word
Returns a new instance of Word.
9 10 11 12 |
# File 'lib/ruigi/word.rb', line 9 def initialize(name, count) self.name = name self.count = count end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
5 6 7 |
# File 'lib/ruigi/word.rb', line 5 def count @count end |
#document ⇒ Object
Returns the value of attribute document.
5 6 7 |
# File 'lib/ruigi/word.rb', line 5 def document @document end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/ruigi/word.rb', line 5 def name @name end |
Instance Method Details
#df ⇒ Object
25 26 27 28 29 |
# File 'lib/ruigi/word.rb', line 25 def df raise NoModelError unless involved_model involved_model.corpus.count { |document| document.words[name] != nil } end |
#idf ⇒ Object
31 32 33 |
# File 'lib/ruigi/word.rb', line 31 def idf df2idf(df) end |
#tf ⇒ Object
18 19 20 21 22 23 |
# File 'lib/ruigi/word.rb', line 18 def tf raise NoDocumentError unless document document_length = document.words.inject(0) { |sum, (k, v)| sum + v.count } count.to_f / document_length end |
#tfidf ⇒ Object
14 15 16 |
# File 'lib/ruigi/word.rb', line 14 def tfidf tf * idf end |