Class: Markov
- Inherits:
-
Object
- Object
- Markov
- Defined in:
- lib/pokemon_name_generator/markov.rb
Instance Method Summary collapse
- #generate_name ⇒ Object
-
#initialize(training_data, context_length:) ⇒ Markov
constructor
A new instance of Markov.
- #name ⇒ Object
Constructor Details
#initialize(training_data, context_length:) ⇒ Markov
Returns a new instance of Markov.
2 3 4 5 |
# File 'lib/pokemon_name_generator/markov.rb', line 2 def initialize(training_data, context_length:) @training_data = training_data @context_length = context_length end |
Instance Method Details
#generate_name ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pokemon_name_generator/markov.rb', line 11 def generate_name pokemon_name = "" context = [] current_phoneme = statistics[context].sample loop do break if current_phoneme.nil? pokemon_name << current_phoneme context << current_phoneme context = context.drop(1) if context.size > context_length current_phoneme = statistics[context].sample end pokemon_name end |
#name ⇒ Object
7 8 9 |
# File 'lib/pokemon_name_generator/markov.rb', line 7 def name "Markov[#{@context_length}]" end |