Created
January 26, 2012 10:49
-
-
Save sriedel/1682210 to your computer and use it in GitHub Desktop.
Generate nicknames phonetically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NicknameGenerator | |
# Grabbed phoneme and template list from http://www.flipcode.com/archives/misc/NameData.xml | |
# Based on an idea presented on http://www.flipcode.com/archives/Generating_Names_Phonetically.shtml | |
# by Jim Adams ([email protected]), 2000 | |
# (sr 2012-01-26) | |
PHONEME_LIST = { # consonants | |
:affricate => %w{ch dg j}, | |
:alveolar => %w{d l n r s t z}, | |
:bilabial => %w{b m p}, | |
:bilabial_stop => %w{b p}, | |
:complex => %w{sch thr}, | |
:consonant => %w{b c d f g h j k l m n p r s t v z}, | |
:double_consonant => %w{bb dd ff ll mm nn rr ss ss tt}, | |
:double_glide => %w{wy}, | |
:ending_nasal => %w{g ng r}, | |
:fricative => %w{ch f ph s sh th v z}, | |
:glide => %w{w y}, | |
:glottal => %w{h}, | |
:liquid => %w{l r}, | |
:mid_consonant => %w{ct dr dw ft mk nd ndr nf nj nk ns nt ny pr ps rd rg rk rm rn rz sl st stl wl}, | |
:nasal => %w{m n}, | |
:palatal => %w{ch dg s j sh y}, | |
:orc_begin => %w{gn gr hr k'z x z zr}, | |
:orc_begin2 => %w{gn gr hr k m n x z zh}, | |
:orc_middle => %w{gh gl gzh rg rgh rgl rl rmg rng zg}, | |
:stop => %w{b d g k p t}, | |
:velar => %w{g k ng w}, | |
# vowels | |
:dipthong => %w{ay ea ee ei oa oe ou ow oy y}, | |
:vowel => %w{a e i o u}, | |
:double_vowel => %w{ae au ea ey ie io oe oi oo ou ue ui ya yo}, | |
# misc | |
:separator => ["'", "-", " "] | |
} | |
NAME_TEMPLATES = { | |
# 3+ letters: V MC V [E.g., Erdi] | |
"V MC V" => [ :vowel, :mid_consonant, :vowel ], | |
# 3+ letters: V MC DoubleVowel [E.g., Erdoo] | |
"V MC VV" => [ :vowel, :mid_consonant, :double_vowel ], | |
# 3+ letters: Fricative Double :vowel , :nasal [E.g., Sean] | |
"Fricative VV Nasal" => [ :fricative, :double_vowel, :nasal ], | |
# 3+ letters: :fricative Double :vowel :consonant [E.g., Seaz] | |
"Fricative VV C" => [ :fricative, :double_vowel, :consonant ], | |
# 5 letters: CVCVC [E.g., Seton] | |
"CVCVC" => [ :consonant, :vowel, :consonant, :vowel, :consonant ], | |
# 3 letters: VCV [E.g., Eti] | |
"V C V" => [ :vowel, :consonant, :vowel ], | |
# 3+ letters: V DC V [E.g., Etti] | |
"V CC V" => [ :vowel, :double_consonant, :vowel ], | |
# 5+ letters: , :nasal V :fricative V EndingGuttural [E.g., Masher] | |
"Nasal V Fricative V Guttural" => [ :nasal, :vowel, :fricative, :vowel, :ending_nasal ], | |
# 5+ letters: :fricative V DoubleGlide V Ending, :nasal [E.g., Sawyer] | |
"Fricative V DoubleGlide V EndingNasal" => [ :fricative, :vowel, :double_glide, :vowel, :ending_nasal ], | |
# 8+ letters: [E.g., Gruph'Norgle] | |
"Orcish" => [ :orc_begin, :vowel, :fricative, :separator, :orc_begin2, :vowel, :orc_middle, :vowel ] | |
} | |
def self.from_template( template_name ) | |
sequence = NAME_TEMPLATES[template_name] | |
raise "Unknown nickname template name '#{template_name}'!" unless sequence | |
name = '' | |
sequence.each do |phoneme_type| | |
name << PHONEME_LIST[phoneme_type].sample | |
end | |
return name.capitalize | |
end | |
def self.generate_purely_random | |
template = NAME_TEMPLATES.keys.sample | |
return from_template( template ) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment