Class: MarkovTextGenerator::Api::Model

Inherits:
Object
  • Object
show all
Includes:
Interface
Defined in:
lib/markov_text_generator/api/model.rb,
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: Knowledge

Constant Summary collapse

CLEAN =
/\W+/

Instance Method Summary collapse

Methods included from Interface

#generate

Methods included from Utils

#make_linked_list

Constructor Details

#initialize(knowledge = Knowledge.new) ⇒ Model

Returns a new instance of Model


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

def initialize(knowledge = Knowledge.new)
  @knowledge = knowledge
end

Instance Method Details

#become_silly!Object


28
29
30
# File 'lib/markov_text_generator/api/model.rb', line 28

def become_silly!
  @knowledge.clear!
end

#predict_next_word_for(key) ⇒ Object


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

def predict_next_word_for(key)
  @knowledge.predict_next_word key
end

#retrain(sentence) ⇒ Object


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

def retrain(sentence)
  become_silly!
  train sentence
end

#train(sentence) ⇒ Object


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

def train(sentence)
  words = prepare_string(sentence).split
  list = process_data words
  @knowledge.train list
end