ealdent-lda-ruby 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lda.rb +21 -2
  2. metadata +2 -2
data/lda.rb CHANGED
@@ -8,11 +8,20 @@ module Lda
8
8
  class Corpus
9
9
  attr_reader :documents, :num_docs, :num_terms
10
10
 
11
- def initialize
11
+ #
12
+ # Create a blank corpus object. Either add documents to it
13
+ # using the +add_document+ method or load the data from a file
14
+ # using +load_from_file+.
15
+ #
16
+ def initialize(filename=nil)
12
17
  @documents = Array.new
13
18
  @all_terms = Set.new
14
19
  @num_terms = 0
15
20
  @num_docs = 0
21
+
22
+ if filename
23
+ self.load_from_file(filename)
24
+ end
16
25
  end
17
26
 
18
27
  # Add a new document to the corpus. This can either be
@@ -43,9 +52,12 @@ module Lda
43
52
  end
44
53
  end
45
54
 
55
+ #
46
56
  # A single document.
57
+ #
47
58
  class Document
48
- attr_accessor :words, :counts, :length, :total
59
+ attr_accessor :words, :counts
60
+ attr_reader :length, :total
49
61
 
50
62
  # Create the Document using the svmlight-style text line:
51
63
  #
@@ -79,12 +91,19 @@ module Lda
79
91
  end
80
92
  end
81
93
 
94
+
95
+ #
96
+ # Recompute the total and length values if the document has been
97
+ # altered externally. This probably won't happen, but might be useful
98
+ # if you want to subclass +Document+.
99
+ #
82
100
  def recompute
83
101
  @total = @counts.inject(0) {|sum, i| sum + i}
84
102
  @length = @words.size
85
103
  end
86
104
  end
87
105
 
106
+
88
107
  class Lda
89
108
  attr_reader :vocab, :corpus
90
109
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ealdent-lda-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason M. Adams
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-11-14 00:00:00 -08:00
13
+ date: 2008-11-16 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16