Class: Company::Mapping::TextDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/company/mapping/document_utils/text_document.rb

Overview

A simple text document

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = SecureRandom.uuid, contents = "", tokenizer = BasicTokenizer.new) ⇒ TextDocument

Returns a new instance of TextDocument.



7
8
9
# File 'lib/company/mapping/document_utils/text_document.rb', line 7

def initialize(id = SecureRandom.uuid, contents = "", tokenizer = BasicTokenizer.new)
  @id, @contents, @tokenizer = id, contents, tokenizer
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



5
6
7
# File 'lib/company/mapping/document_utils/text_document.rb', line 5

def contents
  @contents
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/company/mapping/document_utils/text_document.rb', line 5

def id
  @id
end

#tokenizerObject

Returns the value of attribute tokenizer.



5
6
7
# File 'lib/company/mapping/document_utils/text_document.rb', line 5

def tokenizer
  @tokenizer
end

Instance Method Details

#==(o) ⇒ Object



21
22
23
# File 'lib/company/mapping/document_utils/text_document.rb', line 21

def ==(o)
  o.class == self.class && o.state == self.state
end

#bag_of_wordsObject



11
12
13
14
15
# File 'lib/company/mapping/document_utils/text_document.rb', line 11

def bag_of_words
  @tf = TermFrequency.new(@tokenizer)
  @bag_of_words = @tf.calculate(@contents)
  @bag_of_words
end

#equal?(o) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/company/mapping/document_utils/text_document.rb', line 17

def equal?(o)
  o.class == self.class && o.state == self.state
end

#to_sObject



25
26
27
# File 'lib/company/mapping/document_utils/text_document.rb', line 25

def to_s
  "TextDocument:{#{id},#{contents}}"
end