Class: Company::Mapping::TextDocument
- Inherits:
-
Object
- Object
- Company::Mapping::TextDocument
- Defined in:
- lib/company/mapping/document_utils/text_document.rb
Overview
A simple text document
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#id ⇒ Object
Returns the value of attribute id.
-
#tokenizer ⇒ Object
Returns the value of attribute tokenizer.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #bag_of_words ⇒ Object
- #equal?(o) ⇒ Boolean
-
#initialize(id = SecureRandom.uuid, contents = "", tokenizer = BasicTokenizer.new) ⇒ TextDocument
constructor
A new instance of TextDocument.
- #to_s ⇒ Object
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
#contents ⇒ Object
Returns the value of attribute contents.
5 6 7 |
# File 'lib/company/mapping/document_utils/text_document.rb', line 5 def contents @contents end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/company/mapping/document_utils/text_document.rb', line 5 def id @id end |
#tokenizer ⇒ Object
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_words ⇒ Object
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
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_s ⇒ Object
25 26 27 |
# File 'lib/company/mapping/document_utils/text_document.rb', line 25 def to_s "TextDocument:{#{id},#{contents}}" end |