Class: Momblish::Corpus
- Inherits:
-
Object
- Object
- Momblish::Corpus
- Defined in:
- lib/momblish/corpus.rb
Instance Attribute Summary collapse
-
#occurrences ⇒ Object
Returns the value of attribute occurrences.
-
#weighted_bigrams ⇒ Object
Returns the value of attribute weighted_bigrams.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(weighted_bigrams = {}, occurrences = {}) ⇒ Corpus
constructor
A new instance of Corpus.
- #save(path) ⇒ Object
Constructor Details
#initialize(weighted_bigrams = {}, occurrences = {}) ⇒ Corpus
Returns a new instance of Corpus.
7 8 9 10 |
# File 'lib/momblish/corpus.rb', line 7 def initialize(weighted_bigrams = {}, occurrences = {}) @weighted_bigrams = weighted_bigrams @occurrences = occurrences end |
Instance Attribute Details
#occurrences ⇒ Object
Returns the value of attribute occurrences.
5 6 7 |
# File 'lib/momblish/corpus.rb', line 5 def occurrences @occurrences end |
#weighted_bigrams ⇒ Object
Returns the value of attribute weighted_bigrams.
5 6 7 |
# File 'lib/momblish/corpus.rb', line 5 def weighted_bigrams @weighted_bigrams end |
Class Method Details
.load(path) ⇒ Object
12 13 14 15 16 |
# File 'lib/momblish/corpus.rb', line 12 def self.load(path) data = File.read(path) parsed = JSON.parse(data) new(parsed['weighted_bigrams'], parsed['occurrences']) end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 |
# File 'lib/momblish/corpus.rb', line 18 def ==(other) @weighted_bigrams == other.weighted_bigrams && @occurrences == other.occurrences end |
#save(path) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/momblish/corpus.rb', line 22 def save(path) saved_corpus = { weighted_bigrams: @weighted_bigrams, occurrences: @occurrences } File.write(path, JSON.dump(saved_corpus)) end |