Class: Gulp::Phrase

Inherits:
Object
  • Object
show all
Defined in:
lib/gulp/phrase.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#countObject

Returns the value of attribute count.



3
4
5
# File 'lib/gulp/phrase.rb', line 3

def count
  @count
end

#documentObject

Returns the value of attribute document.



3
4
5
# File 'lib/gulp/phrase.rb', line 3

def document
  @document
end

#stringObject

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_frequencyObject



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_termObject



22
23
24
# File 'lib/gulp/phrase.rb', line 22

def number_of_documents_with_term
  document.corpus.phrase_document_count(string)
end

#phrase_sizeObject



14
15
16
# File 'lib/gulp/phrase.rb', line 14

def phrase_size
  words.size
end

#scoreObject



30
31
32
# File 'lib/gulp/phrase.rb', line 30

def score
  term_frequency * inverse_document_frequency
end

#term_frequencyObject



18
19
20
# File 'lib/gulp/phrase.rb', line 18

def term_frequency
  (count * phrase_size) / document.word_count.to_f
end

#wordsObject



10
11
12
# File 'lib/gulp/phrase.rb', line 10

def words
  words = string.split(/ /)
end