Class: MarkovTextGenerator::Api::Model::Knowledge

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/markov_text_generator/api/model/knowledge.rb,
lib/markov_text_generator/api/model/knowledge/entry.rb,
lib/markov_text_generator/api/model/knowledge/registry.rb

Defined Under Namespace

Classes: Entry, RandomProxy, Registry

Instance Method Summary collapse

Methods included from Utils

#make_linked_list

Constructor Details

#initialize(registry = Registry.new) ⇒ Knowledge



9
10
11
# File 'lib/markov_text_generator/api/model/knowledge.rb', line 9

def initialize(registry = Registry.new)
  @registry = registry
end

Instance Method Details

#clear!Object



24
25
26
# File 'lib/markov_text_generator/api/model/knowledge.rb', line 24

def clear!
  @registry.clear!
end

#predict_next_word(key) ⇒ Object



20
21
22
# File 'lib/markov_text_generator/api/model/knowledge.rb', line 20

def predict_next_word(key)
  @registry[key].predict_next_word
end

#train(list) ⇒ Object



13
14
15
16
17
18
# File 'lib/markov_text_generator/api/model/knowledge.rb', line 13

def train(list)
  list.each do |node|
    entry = add_new_entry node.data
    entry.add_next_word node.succ.data if node.succ
  end
end