Class: Gulp::Phrase
- Inherits:
-
Object
- Object
- Gulp::Phrase
- Defined in:
- lib/gulp/phrase.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#document ⇒ Object
Returns the value of attribute document.
-
#string ⇒ Object
Returns the value of attribute string.
Instance Method Summary collapse
-
#initialize(document, string, count) ⇒ Phrase
constructor
A new instance of Phrase.
- #inverse_document_frequency ⇒ Object
- #number_of_documents_with_term ⇒ Object
- #phrase_size ⇒ Object
- #score ⇒ Object
- #term_frequency ⇒ Object
- #words ⇒ Object
Constructor Details
#initialize(document, string, count) ⇒ Phrase
Returns a new instance of Phrase.
4 5 6 7 8 |
# File 'lib/gulp/phrase.rb', line 4 def initialize(document, string, count) @document = document @string = string @count = count end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
3 4 5 |
# File 'lib/gulp/phrase.rb', line 3 def count @count end |
#document ⇒ Object
Returns the value of attribute document.
3 4 5 |
# File 'lib/gulp/phrase.rb', line 3 def document @document end |
#string ⇒ Object
Returns the value of attribute string.
3 4 5 |
# File 'lib/gulp/phrase.rb', line 3 def string @string end |
Instance Method Details
#inverse_document_frequency ⇒ Object
26 27 28 |
# File 'lib/gulp/phrase.rb', line 26 def inverse_document_frequency Math.log(document.corpus.total_number_of_documents / (1+number_of_documents_with_term)) end |
#number_of_documents_with_term ⇒ Object
22 23 24 |
# File 'lib/gulp/phrase.rb', line 22 def number_of_documents_with_term document.corpus.phrase_document_count(string) end |
#phrase_size ⇒ Object
14 15 16 |
# File 'lib/gulp/phrase.rb', line 14 def phrase_size words.size end |
#score ⇒ Object
30 31 32 |
# File 'lib/gulp/phrase.rb', line 30 def score term_frequency * inverse_document_frequency end |
#term_frequency ⇒ Object
18 19 20 |
# File 'lib/gulp/phrase.rb', line 18 def term_frequency (count * phrase_size) / document.word_count.to_f end |
#words ⇒ Object
10 11 12 |
# File 'lib/gulp/phrase.rb', line 10 def words words = string.split(/ /) end |