Class: PokemonNameGenerator::Algorithm::Markov
- Inherits:
-
Object
- Object
- PokemonNameGenerator::Algorithm::Markov
- Defined in:
- lib/pokemon_name_generator/algorithm/markov.rb
Instance Method Summary collapse
- #generate_name ⇒ Object
-
#initialize(training_data, chain_length:) ⇒ Markov
constructor
A new instance of Markov.
- #name ⇒ Object
Constructor Details
#initialize(training_data, chain_length:) ⇒ Markov
Returns a new instance of Markov.
4 5 6 7 |
# File 'lib/pokemon_name_generator/algorithm/markov.rb', line 4 def initialize(training_data, chain_length:) @training_data = training_data @chain_length = chain_length end |
Instance Method Details
#generate_name ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/pokemon_name_generator/algorithm/markov.rb', line 13 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 > chain_length current_phoneme = statistics[context].sample end pokemon_name end |
#name ⇒ Object
9 10 11 |
# File 'lib/pokemon_name_generator/algorithm/markov.rb', line 9 def name "Markov[#{@chain_length}]" end |