Class: Markovian::Corpus

Inherits:
Object
  • Object
show all
Defined in:
lib/markovian/corpus.rb,
lib/markovian/corpus/chain.rb,
lib/markovian/corpus/compiler.rb,
lib/markovian/corpus/dictionary.rb,
lib/markovian/corpus/dictionary_entry.rb

Defined Under Namespace

Classes: Chain, Compiler, Dictionary, DictionaryEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCorpus

Returns a new instance of Corpus.



9
10
11
# File 'lib/markovian/corpus.rb', line 9

def initialize
  @forward, @backward = Chain.new, Chain.new
end

Instance Attribute Details

#backwardObject (readonly)

Returns the value of attribute backward.



8
9
10
# File 'lib/markovian/corpus.rb', line 8

def backward
  @backward
end

#forwardObject (readonly)

Returns the value of attribute forward.



8
9
10
# File 'lib/markovian/corpus.rb', line 8

def forward
  @forward
end

Instance Method Details

#==(other) ⇒ Object



26
27
28
29
# File 'lib/markovian/corpus.rb', line 26

def ==(other)
  self.forward == other.forward &&
    self.backward == other.backward
end

#next_word(word, previous_word: nil) ⇒ Object



13
14
15
# File 'lib/markovian/corpus.rb', line 13

def next_word(word, previous_word: nil)
  forward.next_word(word, previous_word: previous_word)
end

#previous_word(word, following_word: nil) ⇒ Object



17
18
19
20
# File 'lib/markovian/corpus.rb', line 17

def previous_word(word, following_word: nil)
  # backward goes in the opposite direction to forward
  backward.next_word(word, previous_word: following_word)
end

#random_wordObject



22
23
24
# File 'lib/markovian/corpus.rb', line 22

def random_word
  forward.random_word
end