pokemon_name_generator 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dace6223beff530ba095999c1b125be0424b9e8c687db59d030af29da70ef9bc
4
- data.tar.gz: 2572ca6470688f12f27bff8fbdbc3f338fdb90b029c94cd826c88ca83b52851b
3
+ metadata.gz: 9edb273da4cdabb9557232e24699f3f82e926676974c2ef1c81cce52b6e871cf
4
+ data.tar.gz: f4e6bef343c36aca003243b4b0cbfbc50ad1afeabdd9cf1e5e7ceba8f3a95209
5
5
  SHA512:
6
- metadata.gz: e840d9af23209bc86dd8dd0b7ab01286a7cee778bbd6f8fe02e4484f2e21834d969061c8f07344ffa6c6153cf2579b504a82e32009203be3a9d0fe542e27dc26
7
- data.tar.gz: 0d85cc4e43d26c4745d9c28d1eb6c74f5930b58052a2f60e0a4d5c36aacc888814e537e367d743c125d5bd3e19b75512d3e6452378372fd97c827ebf757d9198
6
+ metadata.gz: f404f12c3cb2d950e1e9c971bddf78e6aa428d1c2429859787661facdfe2da88b40688ea7c14740e79e07c051f23a3d234a5167252ee1384841e29be099b6268
7
+ data.tar.gz: 20fc66d841cda24aac7b971b676a2ceaaa9479ae63201d7a9fb2ea819b88408a98946d6d99bb66b521ec33316610906fe6690a1ac74e73705aaa681cac3c11de
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Pokémon Name Generator
2
2
 
3
+ ![Lint](https://github.com/tony-rowan/pokemon-name-generator/actions/workflows/lint.yml/badge.svg)
4
+ ![Test](https://github.com/tony-rowan/pokemon-name-generator/actions/workflows/test.yml/badge.svg)
5
+ [![Gem Version](https://badge.fury.io/rb/pokemon_name_generator.svg)](https://badge.fury.io/rb/pokemon_name_generator)
6
+
3
7
  A command line ruby utility to generate fake (and sometimes accidentally real)
4
8
  Pokémon names.
5
9
 
@@ -38,7 +42,7 @@ You can also produce a number of names at once.
38
42
  Useful for exporting to other apps.
39
43
 
40
44
  ```bash
41
- $ pokeng generate --algorithm=markov --context=3 --number=100000 > generated_names.txt
45
+ $ pokeng generate --algorithm=markov --context=3 --number=100000 --quiet > generated_names.txt
42
46
  ```
43
47
 
44
48
  The default options are chosen to produce the most realistic names.
@@ -0,0 +1,33 @@
1
+ module PokemonNameGenerator
2
+ module Algorithm
3
+ class Factory
4
+ def initialize(training_data: Corpus::Names.as_letters, **options)
5
+ @training_data = training_data
6
+ @options = options
7
+ end
8
+
9
+ def build_algorithm
10
+ case options.fetch(:algorithm)
11
+ when "naive" then Naive.new(training_data)
12
+ when "markov" then Markov.new(training_data, chain_length: context)
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :training_data, :options
19
+
20
+ def context
21
+ value = begin
22
+ options.fetch(:context).to_i
23
+ rescue
24
+ raise InvalidContextError
25
+ end
26
+
27
+ raise InvalidContextError unless value > 0
28
+
29
+ value
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,68 @@
1
+ module PokemonNameGenerator
2
+ module Algorithm
3
+ class Markov
4
+ def initialize(training_data, chain_length:)
5
+ @training_data = training_data
6
+ @chain_length = chain_length
7
+ end
8
+
9
+ def name
10
+ "Markov[#{@chain_length}]"
11
+ end
12
+
13
+ def generate_name
14
+ pokemon_name = ""
15
+ context = []
16
+ current_phoneme = statistics[context].sample
17
+
18
+ loop do
19
+ break if current_phoneme.nil?
20
+
21
+ pokemon_name << current_phoneme
22
+ context << current_phoneme
23
+ context = context.drop(1) if context.size > chain_length
24
+ current_phoneme = statistics[context].sample
25
+ end
26
+
27
+ pokemon_name
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :training_data, :chain_length
33
+
34
+ def statistics
35
+ @statistics ||= load_statistics
36
+ end
37
+
38
+ def load_statistics
39
+ markov_statistics = {}
40
+
41
+ training_data.each do |this_pokemon_phonemes|
42
+ context = []
43
+
44
+ this_pokemon_phonemes.each do |this_pokemon_phoneme|
45
+ if markov_statistics[context]
46
+ markov_statistics[context] << this_pokemon_phoneme
47
+ else
48
+ markov_statistics[context] = [this_pokemon_phoneme]
49
+ end
50
+
51
+ context = [context, this_pokemon_phoneme].flatten
52
+ context = context.drop(1) if context.size > chain_length
53
+ end
54
+
55
+ if markov_statistics[context]
56
+ markov_statistics[context] << nil
57
+ else
58
+ markov_statistics[context] = [nil]
59
+ end
60
+ end
61
+
62
+ markov_statistics[[]] = markov_statistics[[]].uniq
63
+
64
+ markov_statistics
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,32 @@
1
+ module PokemonNameGenerator
2
+ module Algorithm
3
+ class Naive
4
+ def initialize(training_data)
5
+ @training_data = training_data
6
+ end
7
+
8
+ def name
9
+ "Naïve"
10
+ end
11
+
12
+ def generate_name
13
+ statistics[:phoneme_count_distribution].sample.times.map { statistics[:phoneme_distribution].sample }.join
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :training_data, :context_length
19
+
20
+ def statistics
21
+ @statistics ||= load_statistics
22
+ end
23
+
24
+ def load_statistics
25
+ {
26
+ phoneme_count_distribution: training_data.map(&:count),
27
+ phoneme_distribution: training_data.flatten
28
+ }
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ module PokemonNameGenerator
2
+ module Algorithm
3
+ class InvalidContextError < StandardError; end
4
+
5
+ require "pokemon_name_generator/algorithm/factory"
6
+ require "pokemon_name_generator/algorithm/markov"
7
+ require "pokemon_name_generator/algorithm/naive"
8
+ end
9
+ end
@@ -0,0 +1,37 @@
1
+ require "dry/cli"
2
+
3
+ module PokemonNameGenerator
4
+ module CLI
5
+ module Commands
6
+ class Generate < Dry::CLI::Command
7
+ desc "Generate one or more Pokémon Names"
8
+
9
+ option :algorithm, default: "markov", values: %w[naive markov], desc: "Algorithm to use"
10
+
11
+ option :context, type: :integer, default: 3, desc: "Number of links in the Markov Chain"
12
+
13
+ option :number, type: :integer, default: 1, desc: "Number of names to generate"
14
+
15
+ option :quiet, type: :boolean, default: false, desc: "Only print the names, nothing else"
16
+
17
+ def call(**options)
18
+ algorithm = Algorithm::Factory.new(**options).build_algorithm
19
+
20
+ unless options.fetch(:quiet)
21
+ puts "============================="
22
+ puts "🧪 Generator: #{algorithm.name}"
23
+ puts "============================="
24
+ puts ""
25
+
26
+ if options.fetch(:number).to_i > 1
27
+ puts "Generating #{options.fetch(:number)} names..."
28
+ puts ""
29
+ end
30
+ end
31
+
32
+ options.fetch(:number).to_i.times { puts algorithm.generate_name }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,59 @@
1
+ require "dry/cli"
2
+
3
+ module PokemonNameGenerator
4
+ module CLI
5
+ module Commands
6
+ class Test < Dry::CLI::Command
7
+ desc "Test an algorithm"
8
+
9
+ option :algorithm, required: true, values: %w[naive markov], desc: "Algorithm to test"
10
+
11
+ option :context, required: true, type: :integer, desc: "Number of links in the Markov Chain"
12
+
13
+ option :sample, type: :integer, default: 10_000, desc: "Number of names to generate"
14
+
15
+ option :show_names, type: :boolean, default: false, desc: "Show the new and actual generated names in the sample"
16
+
17
+ def call(**options)
18
+ actual_pokemon = Corpus::Data.new.load_pokemon_names
19
+ all_data = Corpus::Names.as_letters.shuffle
20
+
21
+ mid_point = (all_data.size + 1) / 2
22
+ training_data = all_data[..mid_point]
23
+ test_data = all_data[mid_point..]
24
+
25
+ algorithm = Algorithm::Factory.new(training_data: training_data, **options).build_algorithm
26
+
27
+ puts "============================="
28
+ puts "🧪 Generator: #{algorithm.name}"
29
+ puts "============================="
30
+
31
+ puts "Generating #{options.fetch(:sample)} names..."
32
+
33
+ generated_names = options.fetch(:sample).to_i.times.map { algorithm.generate_name }
34
+
35
+ unique_pokemon_generated = generated_names.uniq
36
+ training_pokemon_generated = unique_pokemon_generated.intersection(training_data.map(&:join))
37
+ test_pokemon_generated = unique_pokemon_generated.intersection(test_data.map(&:join))
38
+ new_pokemon_generated = unique_pokemon_generated - actual_pokemon
39
+
40
+ upper_limit = actual_pokemon.max_by(&:size).size
41
+ lower_limit = actual_pokemon.min_by(&:size).size
42
+
43
+ puts "Done."
44
+ puts ""
45
+ puts "Unique Names: #{unique_pokemon_generated.size}"
46
+ puts "Training Pokémon: #{training_pokemon_generated.size}"
47
+ puts training_pokemon_generated.to_s if options.fetch(:show_names, false)
48
+ puts "Test Pokémon: #{test_pokemon_generated.size}"
49
+ puts test_pokemon_generated.to_s if options.fetch(:show_names, false)
50
+ puts "New Pokémon: #{new_pokemon_generated.size}"
51
+ puts " Too Long: #{new_pokemon_generated.count { |x| x.size > upper_limit }}"
52
+ puts " Too Short: #{new_pokemon_generated.count { |x| x.size < lower_limit }}"
53
+ puts new_pokemon_generated.to_s if options.fetch(:show_names, false)
54
+ puts ""
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,15 @@
1
+ require "dry/cli"
2
+
3
+ module PokemonNameGenerator
4
+ module CLI
5
+ module Commands
6
+ class Version < Dry::CLI::Command
7
+ desc "Print version"
8
+
9
+ def call(*)
10
+ puts PokemonNameGenerator::VERSION
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -4,81 +4,11 @@ require "dry/cli"
4
4
  module PokemonNameGenerator
5
5
  module CLI
6
6
  module Commands
7
- extend Dry::CLI::Registry
8
-
9
- class Version < Dry::CLI::Command
10
- desc "Print version"
11
-
12
- def call(*)
13
- puts PokemonNameGenerator::VERSION
14
- end
15
- end
16
-
17
- class Generate < Dry::CLI::Command
18
- desc "Generate one or more Pokémon Names"
19
-
20
- option :algorithm, default: "markov", values: %w[naive markov], desc: "Algorithm to use"
21
-
22
- option :context, type: :integer, default: 3, desc: "Number of links in the Markov Chain"
23
-
24
- option :number, type: :integer, default: 1, desc: "Number of names to generate"
25
-
26
- def call(**options)
27
- corpus = Corpus.new
28
-
29
- algorithm = case options.fetch(:algorithm)
30
- when "naive" then Naive.new(corpus.pokemon_phonemes)
31
- when "markov" then Markov.new(corpus.pokemon_phonemes, context_length: options.fetch(:context).to_i)
32
- end
33
-
34
- options.fetch(:number).to_i.times { puts algorithm.generate_name }
35
- end
36
- end
37
-
38
- class Test < Dry::CLI::Command
39
- desc "Test an algorithm"
7
+ require "pokemon_name_generator/cli/commands/version"
8
+ require "pokemon_name_generator/cli/commands/generate"
9
+ require "pokemon_name_generator/cli/commands/test"
40
10
 
41
- option :algorithm, required: true, values: %w[naive markov], desc: "Algorithm to test"
42
-
43
- option :context, required: true, type: :integer, desc: "Number of links in the Markov Chain"
44
-
45
- option :number, type: :integer, default: 10_000, desc: "Number of names to generate"
46
-
47
- def call(**options)
48
- corpus = Corpus.new
49
- actual_pokemon = corpus.pokemon
50
- all_data = corpus.pokemon_phonemes.shuffle
51
-
52
- longest_name = actual_pokemon.max_by(&:length)
53
- shortest_name = actual_pokemon.min_by(&:length)
54
-
55
- mid_point = (all_data.size + 1) / 2
56
- training_data = all_data[..mid_point]
57
- test_data = all_data[mid_point..]
58
-
59
- algorithm = case options.fetch(:algorithm)
60
- when "naive" then Naive.new(training_data)
61
- when "markov" then Markov.new(training_data, context_length: options.fetch(:context).to_i)
62
- end
63
-
64
- puts "============================="
65
- puts "🧪 Generator: #{algorithm.name}"
66
- puts "============================="
67
-
68
- generated_names = options.fetch(:number).to_i.times.map { algorithm.generate_name }
69
-
70
- puts "Training Data: #{training_data.size}"
71
- puts "Test Data: #{test_data.size}"
72
- puts "Generated Names: #{generated_names.size}"
73
- puts "Unique Generated Names: #{generated_names.uniq.size}"
74
- puts "Training Data Names Generated: #{training_data.map { |datum| datum.join("") }.intersection(generated_names.uniq).size}"
75
- puts "Test Data Names Generated: #{test_data.map { |datum| datum.join("") }.intersection(generated_names.uniq).size}"
76
- puts "Test Data Names Generated: #{test_data.map { |datum| datum.join("") }.intersection(generated_names.uniq)}"
77
- puts "Overly Short Names: #{generated_names.count { |name| name.size < shortest_name.size }}"
78
- puts "Overly Long Names: #{generated_names.count { |name| name.size > longest_name.size }}"
79
- puts ""
80
- end
81
- end
11
+ extend Dry::CLI::Registry
82
12
 
83
13
  register "version", Version, aliases: ["-v", "--version"]
84
14
  register "generate", Generate, aliases: ["g", "generate"]
@@ -0,0 +1,19 @@
1
+ module PokemonNameGenerator
2
+ module Corpus
3
+ class Data
4
+ DATA_FILE_PATH = File.expand_path("../../../../data/pokemon.txt", __FILE__)
5
+
6
+ attr_reader :file
7
+
8
+ def initialize(file: DATA_FILE_PATH)
9
+ @file = file
10
+ end
11
+
12
+ def load_pokemon_names
13
+ File.readlines(file, chomp: true)
14
+ .map { |line| line[5..] } # drop the number
15
+ .map(&:downcase)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ module PokemonNameGenerator
2
+ module Corpus
3
+ module Names
4
+ def self.as_letters(data: Data.new)
5
+ data.load_pokemon_names.map(&:chars)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,46 +1,6 @@
1
- require_relative "./phoneme"
2
- require_relative "./pokemon"
3
-
4
- class Corpus
5
- def pokemon_letters
6
- @pokemon_letters ||= load_pokemon_letters.values
7
- end
8
-
9
- def pokemon_phonemes
10
- @pokemon_phonemes ||= load_pokemon_phonemes.values
11
- end
12
-
13
- def phonemes
14
- @phonemes ||= Phoneme.load_data
15
- end
16
-
17
- def pokemon
18
- @pokemon ||= Pokemon.load_data
19
- end
20
-
21
- private
22
-
23
- # This generates a hash so we can debug it easily
24
- def load_pokemon_letters
25
- pokemon.map { |name| [name, name.chars] }.to_h
26
- end
27
-
28
- # This generates a hash so we can debug it easily
29
- def load_pokemon_phonemes
30
- pokemon.map do |this_pokemon_name|
31
- remaining_pokemon_name = this_pokemon_name
32
- this_pokemon_phonemes = []
33
-
34
- loop do
35
- break if remaining_pokemon_name.empty?
36
-
37
- phoneme = phonemes.find { |phoneme| remaining_pokemon_name.start_with?(phoneme) }
38
-
39
- this_pokemon_phonemes << phoneme
40
- remaining_pokemon_name = remaining_pokemon_name.sub(phoneme, "")
41
- end
42
-
43
- [this_pokemon_name, this_pokemon_phonemes]
44
- end.to_h
1
+ module PokemonNameGenerator
2
+ module Corpus
3
+ require "pokemon_name_generator/corpus/data"
4
+ require "pokemon_name_generator/corpus/names"
45
5
  end
46
6
  end
@@ -1,3 +1,3 @@
1
1
  module PokemonNameGenerator
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,9 +1,6 @@
1
1
  module PokemonNameGenerator
2
+ require "pokemon_name_generator/algorithm"
2
3
  require "pokemon_name_generator/cli"
3
4
  require "pokemon_name_generator/corpus"
4
- require "pokemon_name_generator/markov"
5
- require "pokemon_name_generator/naive"
6
- require "pokemon_name_generator/phoneme"
7
- require "pokemon_name_generator/pokemon"
8
5
  require "pokemon_name_generator/version"
9
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pokemon_name_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Rowan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-14 00:00:00.000000000 Z
11
+ date: 2022-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.7.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: aruba
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -75,16 +89,20 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - README.md
77
91
  - bin/pokeng
78
- - data/phonemes.txt
79
92
  - data/pokemon.txt
80
93
  - lib/pokemon_name_generator.rb
94
+ - lib/pokemon_name_generator/algorithm.rb
95
+ - lib/pokemon_name_generator/algorithm/factory.rb
96
+ - lib/pokemon_name_generator/algorithm/markov.rb
97
+ - lib/pokemon_name_generator/algorithm/naive.rb
81
98
  - lib/pokemon_name_generator/cli.rb
82
99
  - lib/pokemon_name_generator/cli/commands.rb
100
+ - lib/pokemon_name_generator/cli/commands/generate.rb
101
+ - lib/pokemon_name_generator/cli/commands/test.rb
102
+ - lib/pokemon_name_generator/cli/commands/version.rb
83
103
  - lib/pokemon_name_generator/corpus.rb
84
- - lib/pokemon_name_generator/markov.rb
85
- - lib/pokemon_name_generator/naive.rb
86
- - lib/pokemon_name_generator/phoneme.rb
87
- - lib/pokemon_name_generator/pokemon.rb
104
+ - lib/pokemon_name_generator/corpus/data.rb
105
+ - lib/pokemon_name_generator/corpus/names.rb
88
106
  - lib/pokemon_name_generator/version.rb
89
107
  homepage: https://github.com/tony-rowan/pokemon-name-generator
90
108
  licenses:
data/data/phonemes.txt DELETED
@@ -1,130 +0,0 @@
1
- aigh
2
- augh
3
- ayer
4
- eigh
5
- ngue
6
- ough
7
- air
8
- are
9
- dge
10
- ear
11
- eau
12
- eer
13
- eir
14
- ere
15
- ier
16
- igh
17
- oar
18
- oew
19
- oor
20
- ore
21
- our
22
- sci
23
- tch
24
- uoy
25
- ure
26
- ae
27
- ai
28
- ar
29
- au
30
- aw
31
- ay
32
- bb
33
- cc
34
- ce
35
- ch
36
- ci
37
- ck
38
- dd
39
- di
40
- ea
41
- ed
42
- ee
43
- ei
44
- eo
45
- er
46
- et
47
- ew
48
- ey
49
- ff
50
- ft
51
- ge
52
- gg
53
- gh
54
- gn
55
- ho
56
- ie
57
- ir
58
- is
59
- lf
60
- lk
61
- ll
62
- lm
63
- mb
64
- mm
65
- mn
66
- ng
67
- nn
68
- oa
69
- oe
70
- oi
71
- oo
72
- or
73
- ou
74
- ow
75
- oy
76
- ph
77
- pn
78
- pp
79
- ps
80
- qu
81
- rh
82
- rr
83
- sc
84
- se
85
- sh
86
- si
87
- ss
88
- st
89
- te
90
- th
91
- ti
92
- tt
93
- tu
94
- ue
95
- ui
96
- ur
97
- uy
98
- ve
99
- wh
100
- wr
101
- ye
102
- yr
103
- ze
104
- zz
105
- a
106
- b
107
- c
108
- d
109
- e
110
- f
111
- g
112
- h
113
- i
114
- j
115
- k
116
- l
117
- m
118
- n
119
- o
120
- p
121
- q
122
- r
123
- s
124
- t
125
- u
126
- v
127
- w
128
- x
129
- y
130
- z
@@ -1,64 +0,0 @@
1
- class Markov
2
- def initialize(training_data, context_length:)
3
- @training_data = training_data
4
- @context_length = context_length
5
- end
6
-
7
- def name
8
- "Markov[#{@context_length}]"
9
- end
10
-
11
- def generate_name
12
- pokemon_name = ""
13
- context = []
14
- current_phoneme = statistics[context].sample
15
-
16
- loop do
17
- break if current_phoneme.nil?
18
-
19
- pokemon_name << current_phoneme
20
- context << current_phoneme
21
- context = context.drop(1) if context.size > context_length
22
- current_phoneme = statistics[context].sample
23
- end
24
-
25
- pokemon_name
26
- end
27
-
28
- private
29
-
30
- attr_reader :training_data, :context_length
31
-
32
- def statistics
33
- @statistics ||= load_statistics
34
- end
35
-
36
- def load_statistics
37
- markov_statistics = {}
38
-
39
- training_data.each do |this_pokemon_phonemes|
40
- context = []
41
-
42
- this_pokemon_phonemes.each do |this_pokemon_phoneme|
43
- if markov_statistics[context]
44
- markov_statistics[context] << this_pokemon_phoneme
45
- else
46
- markov_statistics[context] = [this_pokemon_phoneme]
47
- end
48
-
49
- context = [context, this_pokemon_phoneme].flatten
50
- context = context.drop(1) if context.size > context_length
51
- end
52
-
53
- if markov_statistics[context]
54
- markov_statistics[context] << nil
55
- else
56
- markov_statistics[context] = [nil]
57
- end
58
- end
59
-
60
- markov_statistics[[]] = markov_statistics[[]].uniq
61
-
62
- markov_statistics
63
- end
64
- end
@@ -1,28 +0,0 @@
1
- class Naive
2
- def initialize(training_data)
3
- @training_data = training_data
4
- end
5
-
6
- def name
7
- "Naïve"
8
- end
9
-
10
- def generate_name
11
- statistics[:phoneme_count_distribution].sample.times.map { statistics[:phoneme_distribution].sample }.join
12
- end
13
-
14
- private
15
-
16
- attr_reader :training_data, :context_length
17
-
18
- def statistics
19
- @statistics ||= load_statistics
20
- end
21
-
22
- def load_statistics
23
- {
24
- phoneme_count_distribution: training_data.map(&:count),
25
- phoneme_distribution: training_data.flatten
26
- }
27
- end
28
- end
@@ -1,7 +0,0 @@
1
- module Phoneme
2
- DATA = File.expand_path('../../../data/phonemes.txt', __FILE__)
3
-
4
- def self.load_data
5
- File.readlines(DATA, chomp: true)
6
- end
7
- end
@@ -1,10 +0,0 @@
1
- module Pokemon
2
- DATA = File.expand_path('../../../data/pokemon.txt', __FILE__)
3
-
4
- def self.load_data
5
- File.readlines(DATA, chomp: true)
6
- .map { |line| line[5..] } # drop the number
7
- .map(&:downcase)
8
- .reject { |name| name =~ /[♀♂.'2\-é:\ ]/ } # don't deal with special characters yet
9
- end
10
- end