Class: Ruigi::Word

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruigi/word.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#countObject

Returns the value of attribute count.



5
6
7
# File 'lib/ruigi/word.rb', line 5

def count
  @count
end

#documentObject

Returns the value of attribute document.



5
6
7
# File 'lib/ruigi/word.rb', line 5

def document
  @document
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/ruigi/word.rb', line 5

def name
  @name
end

Instance Method Details

#dfObject

Raises:



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

#idfObject



31
32
33
# File 'lib/ruigi/word.rb', line 31

def idf
  df2idf(df)
end

#tfObject

Raises:



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

#tfidfObject



14
15
16
# File 'lib/ruigi/word.rb', line 14

def tfidf
  tf * idf
end