Class: SClust::LDA2::Topic
- Inherits:
-
Object
- Object
- SClust::LDA2::Topic
- Defined in:
- lib/sclust/lda/lda2.rb
Instance Attribute Summary collapse
-
#docs ⇒ Object
Returns the value of attribute docs.
-
#wordcount ⇒ Object
Returns the value of attribute wordcount.
-
#words ⇒ Object
Returns the value of attribute words.
Instance Method Summary collapse
- #add(word, doc) ⇒ Object
- #has_word_and_doc?(word, doc) ⇒ Boolean
-
#initialize ⇒ Topic
constructor
A new instance of Topic.
- #remove(word, doc) ⇒ Object
Constructor Details
#initialize ⇒ Topic
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
#docs ⇒ Object
Returns the value of attribute docs.
38 39 40 |
# File 'lib/sclust/lda/lda2.rb', line 38 def docs @docs end |
#wordcount ⇒ Object
Returns the value of attribute wordcount.
38 39 40 |
# File 'lib/sclust/lda/lda2.rb', line 38 def wordcount @wordcount end |
#words ⇒ Object
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
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 |