Class: Lda::TextDocument

Inherits:
Document show all
Defined in:
lib/lda-ruby/document/text_document.rb

Instance Attribute Summary collapse

Attributes inherited from Document

#corpus, #counts, #length, #tokens, #total, #words

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Document

#handle, #recompute, #tokenize

Constructor Details

#initialize(corpus, text) ⇒ TextDocument

Returns a new instance of TextDocument.



5
6
7
8
9
10
11
12
# File 'lib/lda-ruby/document/text_document.rb', line 5

def initialize(corpus, text)
  super(corpus)
  @filename = nil

  tokenize(text)
  @corpus.stopwords.each { |w| @tokens.delete(w) }
  build_from_tokens
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/lda-ruby/document/text_document.rb', line 3

def filename
  @filename
end

Class Method Details

.build_from_file(corpus, filename) ⇒ Object



18
19
20
21
22
# File 'lib/lda-ruby/document/text_document.rb', line 18

def self.build_from_file(corpus, filename)
  @filename = filename.dup.freeze
  text = File.open(@filename, 'r') { |f| f.read }
  self.new(corpus, text)
end

Instance Method Details

#has_text?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/lda-ruby/document/text_document.rb', line 14

def has_text?
  true
end