Skip to content

Commit

Permalink
First attempt to hook "culture names" into NameGen
Browse files Browse the repository at this point in the history
  • Loading branch information
impaktor committed Jan 4, 2022
1 parent 8128155 commit 772e468
Show file tree
Hide file tree
Showing 21 changed files with 928 additions and 539 deletions.
57 changes: 57 additions & 0 deletions data/culture/common.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
-- Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local utils = require 'utils'

local CultureName = {
male = {}, -- List of 100 most common male first names
female = {}, -- List of 100 most common female first names
surname = {}, -- List of 100 most common last names
name = "Name", -- Name of language / culture
code = "xx", -- ISO ISO 639-1 language code
}

-- local ascii_replacement = {}
--- xxx todo / fix
ascii_replacement = {}
ascii_replacement["ä"] = "ae"
ascii_replacement["è"] = "e"
ascii_replacement["à"] = "a"
ascii_replacement["ò"] = "o"
ascii_replacement["ò"] = "o"
ascii_replacement["à"] = "a"
ascii_replacement["ù"] = "u"
ascii_replacement["è"] = "e"
ascii_replacement["ì"] = "i"
ascii_replacement["ì"] = "i"
ascii_replacement["ù"] = "u"
ascii_replacement["ü"] = "u"
ascii_replacement["å"] = "aa"
ascii_replacement["ä"] = "ae"
ascii_replacement["ö"] = "o"
ascii_replacement["ø"] = "o"
ascii_replacement["æ"] = "ae"


function CultureName:New (o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end

function CultureName:FirstName (isFemale, rand)
local array = isFemale and self.female or self.male
return utils.chooseEqual(array, rand)
end

-- Some cultures have gender specific surnames
function CultureName:Surname (isFemale, rand)
return utils.chooseEqual(self.surname, rand)
end

function CultureName:FullName (isFemale, rand)
return self:FirstName(isFemale, rand) .. " " .. self:Surname(isFemale, rand)
end

return CultureName
139 changes: 139 additions & 0 deletions data/culture/culture.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
-- Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

-- give name, first and last name functions

local utils = require 'utils'

local de = require '.de' -- german
local da = require '.da' -- danish
local es = require '.es' -- spanish
local en = require '.en' -- english
local fi = require '.fi' -- finish
local fr = require '.fr' -- french
local gd = require '.gd' -- gaelic
local el = require '.el' -- greek
local hu = require '.hu' -- hungarian
local is = require '.is' -- islandic
local it = require '.it' -- italian
local ja = require '.ja' -- japanese
local nl = require '.nl' -- netherlands
local nb = require '.nb' -- norwegian bokmål
local pl = require '.pl' -- polish
local ro = require '.ro' -- romanian
local ru = require '.ru' -- russian
local sv = require '.sv' -- swedish
-- local us = require '.us' -- USA
local tr = require '.tr' -- turkish
local zh = require '.zh' -- chinese/mandarin
-- local misc = require '.misc' -- mixed / developer's names

--
-- Class: Culture
--

local Culture = {}

Culture.weights = {
{lang = da, weight = 1.0},
{lang = de, weight = 3.0},
{lang = el, weight = 1.0},
{lang = en, weight = 6.0},
{lang = es, weight = 3.0},
{lang = fi, weight = 1.0},
{lang = fr, weight = 3.0},
{lang = gd, weight = 0.5},
{lang = hu, weight = 1.0},
{lang = is, weight = 0.5},
{lang = it, weight = 3.0},
{lang = ja, weight = 3.0},
{lang = nb, weight = 1.0},
{lang = nl, weight = 2.0},
{lang = pl, weight = 1.0},
{lang = ru, weight = 3.0},
{lang = sv, weight = 1.0},
{lang = tr, weight = 1.0},
-- {lang = us, weight = 5.0},
{lang = zh, weight = 3.0},
-- {lang = misc, weight = 1.0},
}

-- Normalize weights to sum to 1
utils.normWeights(Culture.weights)

-- Map language string to module table
Culture.lookup = {}
print("Random generated names from:")
for k, v in pairs(Culture.weights) do
Culture.lookup[v.lang.name] = v.lang
print("* ", k, v.lang.code, v.lang.name, v.lang, v.weight)
end

--
-- Function: FirstName
--
-- Create first name, from specified culture, or default to weighted
-- probability from pre-set list of available cultures. See parameter
-- and return documentation from Culture:FullName()
--
-- > name = Culture:FirstName(isfemale, rand, culture)
--
function Culture:FirstName (isFemale, rand, culture)
local c = self.lookup[culture] or utils.chooseNormalized(self.weights, rand).lang
return c:FirstName(isFemale)
end

--
-- Function: Surname
--
-- Create surname, from specified culture, or default to weighted
-- probability from pre-set list of available cultures. See parameter
-- and return documentation from Culture:FullName().
--
-- > name = Culture:Surname(isfemale, rand, culture)
--
function Culture:Surname (isFemale, rand, culture)
local c = self.lookup[culture] or utils.chooseNormalized(self.weights, rand).lang
return c:Surname(isFemale, rand)
end


--
-- Function: FullName
--
-- Create a full name, where first and last match the same
-- language/culture. If no culture is specified, one is randomly
-- selected according to pre-set weights. Valid input is one of the
-- following (capitalized) strings:
--
-- Danish German Greek English Spanish Finish French Gaelic Hungarian
-- Icelandic Italian Japanese Norwegian Dutch Polish Russian Swedish
-- Turkish Chinese
--
-- > name = Culture:FullName(isfemale, rand, culture)
--
-- Parameters:
--
-- isfemale - whether to generate a male or female name. true for female,
-- false for male
--
-- rand - the <Rand> object to use to generate the name
--
-- culture - optional string
--
-- Return:
--
-- name - a string containing matching first and last name
--
-- Return full name from the same culture/language
function Culture:FullName (isFemale, rand, culture)
-- if 'culture' given as a string, e.g. "Russian" use that
local c = self.lookup[culture] or utils.chooseNormalized(self.weights, rand).lang

local debug_code = "(".. c.code .. ") "
return debug_code .. c:FullName(isFemale, rand)
-- return c:FullName(isFemale)
end


return Culture
17 changes: 13 additions & 4 deletions data/culture/da.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@

-- https://www.dst.dk/da/Statistik/emner/befolkning-og-valg/navne/navne-i-hele-befolkningen

local male = {
local CultureName = require './common'

local Danish = CultureName:New()

Danish.name = "Danish"
Danish.code = "da"

Danish.male = {
"Peter",
"Michael",
"Jens",
Expand All @@ -26,7 +33,7 @@ local male = {
"Ole"
}

local female = {
Danish.female = {
"Anne",
"Kirsten",
"Mette",
Expand All @@ -49,7 +56,7 @@ local female = {
"Karen"
}

local surnames = {
Danish.surname = {
"Nielsen",
"Jensen",
"Hansen",
Expand All @@ -69,5 +76,7 @@ local surnames = {
"Poulsen",
"Johansen",
"Møller",
"Mortensen",
"Mortensen"
}

return Danish
17 changes: 13 additions & 4 deletions data/culture/de.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
-- Copyright © 2008-2016 Pioneer Developers. See AUTHORS.txt for details
-- Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local male={
local CultureName = require './common'

local German = CultureName:New()

German.name = "German"
German.code = "de"

German.male = {
'Adrian',
'Albert',
'Alexander',
Expand Down Expand Up @@ -211,7 +218,7 @@ local male={
'Zacharias'
}

local female={
German.female = {
'Agnes',
'Alessa',
'Alexa',
Expand Down Expand Up @@ -434,7 +441,7 @@ local female={
'Yvonne'
}

local surname={
German.surname = {
'Albrecht',
'Althaus',
'Altmann',
Expand Down Expand Up @@ -581,3 +588,5 @@ local surname={
'Ziegler',
'Zimmermann'
}

return German
26 changes: 22 additions & 4 deletions data/culture/el.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
-- Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

local male = {
local utils = require 'utils'
local CultureName = require './common'

local Greek = CultureName:New()

Greek.name = "Greek"
Greek.code = "el"
Greek.surname = nil -- not using this for Greek

Greek.male = {
"Achaeus",
"Adeimantus",
"Agapetus",
Expand Down Expand Up @@ -115,7 +124,7 @@ local male = {
"Zenobios"}


local female = {
Greek.female = {
"Agariste",
"Agatha",
"Agne",
Expand Down Expand Up @@ -228,7 +237,7 @@ local female = {
}


local female_surnames = {
Greek.female_surname = {
"Afroudaki",
"Agathangelou",
"Aggeloniti",
Expand Down Expand Up @@ -458,7 +467,7 @@ local female_surnames = {
"Zografaki",
}

local male_surname = {
Greek.male_surname = {
"Achilleos",
"Afroudakis",
"Aggelonitis",
Expand Down Expand Up @@ -818,3 +827,12 @@ local male_surname = {
"Zografakis",
"Zografos"
}

-- Greek surnames are gender specific
function Greek:Surname (isFemale, rand)
-- print("OVERLOADED", self.name) xxx
local array = isFemale and self.female_surname or self.male_surname
return utils.chooseEqual(array, rand)
end

return Greek
17 changes: 13 additions & 4 deletions data/culture/es.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
-- Copyright © 2008-2016 Pioneer Developers. See AUTHORS.txt for details
-- Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
-- Licensed under the terms of the GPL v3. See licenses/GPL-3.txt

-- source http://www.studentsoftheworld.info/penpals/stats.php3?Pays=ESP

local male={
local CultureName = require './common'

local Spanish = CultureName:New()

Spanish.name = "Spanish"
Spanish.code = "es"

Spanish.male={
"Adrian",
"Aitor",
"Albert",
Expand Down Expand Up @@ -106,7 +113,7 @@ local male={
"Óscar"
}

local female={
Spanish.female={
"Aida",
"Aina",
"Ainhoa",
Expand Down Expand Up @@ -208,7 +215,7 @@ local female={
"Yaiza"
}

local surname={
Spanish.surname={
"Aguilar",
"Alonso",
"Alvarez",
Expand Down Expand Up @@ -310,3 +317,5 @@ local surname={
"Vidal",
"Vila"
}

return Spanish
Loading

0 comments on commit 772e468

Please sign in to comment.