Class: Momblish::Corpus

Inherits:
Object
  • Object
show all
Defined in:
lib/momblish/corpus.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#occurrencesObject

Returns the value of attribute occurrences.



5
6
7
# File 'lib/momblish/corpus.rb', line 5

def occurrences
  @occurrences
end

#weighted_bigramsObject

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