Class: PokemonNameGenerator::Algorithm::Markov

Inherits:
Object
  • Object
show all
Defined in:
lib/pokemon_name_generator/algorithm/markov.rb

Instance Method Summary collapse

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_nameObject



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

#nameObject



9
10
11
# File 'lib/pokemon_name_generator/algorithm/markov.rb', line 9

def name
  "Markov[#{@chain_length}]"
end