Class: SClust::LDA2::Topic

Inherits:
Object
  • Object
show all
Defined in:
lib/sclust/lda/lda2.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTopic

Returns a new instance of Topic.



41
42
43
44
45
46
47
# File 'lib/sclust/lda/lda2.rb', line 41

def initialize()
    @words     = SClust::Util::SparseVector.new(0) # Hash count of words. Keys are indexes into @wordlist 
    #@words     = Hash.new(0) # Hash count of words. Keys are indexes into @wordlist 
    @wordcount = 0  # Sum of values in @words.
    @docs      = SClust::Util::SparseVector.new(0)
    #@docs      = Hash.new(0) # Collection of documents. Hash is to eliminate duplicates.
end

Instance Attribute Details

#docsObject

Returns the value of attribute docs.



38
39
40
# File 'lib/sclust/lda/lda2.rb', line 38

def docs
  @docs
end

#wordcountObject

Returns the value of attribute wordcount.



38
39
40
# File 'lib/sclust/lda/lda2.rb', line 38

def wordcount
  @wordcount
end

#wordsObject

Returns the value of attribute words.



38
39
40
# File 'lib/sclust/lda/lda2.rb', line 38

def words
  @words
end

Instance Method Details

#add(word, doc) ⇒ Object



53
54
55
56
57
# File 'lib/sclust/lda/lda2.rb', line 53

def add(word, doc)
    @words[word] += 1
    @wordcount   += 1
    @docs[doc]   += 1
end

#has_word_and_doc?(word, doc) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/sclust/lda/lda2.rb', line 49

def has_word_and_doc?(word, doc)
    @words.member?(word) and @docs.member?(doc)
end

#remove(word, doc) ⇒ Object



59
60
61
62
63
# File 'lib/sclust/lda/lda2.rb', line 59

def remove(word, doc)
    @words[word] -= 1
    @wordcount   -= 1
    @docs.delete(doc) if (@docs[doc] -= 1 ) < 0 # NOTE: Sparse Vector deletes when @docs[doc] == 0.
end