Module:Sandbox/Ste1la/Names
-- Ste1la Google Code-in, Names of People
local p = {}
p.getName = function(frame)
local name = frame.args.name or ""
local format = frame.args.format
local givenName = ""
local lastName = ""
local obtain = 0
if name == "" then
return "No name given"
end
--gets rid of any appendages
if name:find("Jr") or name:find("Jr.") or name:find("Sr") or
name:find("Sr.") or name:find("II") or name:find("III") then
local i, j = name:reverse():find("%S+")
name = name:reverse():sub(j+1):reverse()
end
--check if chinese
if obtain == 0 then
local exist
local chineseList = {"Wang", "Li", "Zhang", "Huang", "Liu", "Chen", "Yang", "Zhao",
"Wu", "Zhou", "Xu", "Wen", "Zhu", "Fan", "Zu", "Xu", "Mao", "Sun", "He", "Gao", "Zheng"}
for i = 1, #chineseList do
if name:find(chineseList[i]) then
exist = 1
end
end
if exist == 1 then
lastName = name:match("%a+")
local i, j = name:find(lastName)
givenName = name:sub(j+2)
if givenName:find("%(") then
i = givenName:find("%(")
givenName = givenName:sub(1, i - 2)
end
obtain = 1
end
end
--check if dutch
if obtain == 0 then
local dutchList = {" van ", " de ", " ter ", " van de ", " van den ", " van der "}
for i = 1, #dutchList do
if name:find(dutchList[i]) then
i, j = name:find(dutchList[i])
lastName = name:sub(i)
givenName = name:sub(1, i - 1)
obtain = 1
end
end
--[[if i ~= nil then
lastName = name:sub(i)
givenName = name:sub(1, i - 2)
obtain = 1
elseif name:find("de") then
i, j = name:find("de")
lastName = name:sub(i)
givenName = name:sub(1, i - 2)
obtain = 1
elseif name:find("ter") then
i, j = name:find("ter")
lastName = name:sub(i)
givenName = name:sub(1, i - 2)
obtain = 1
end]]
end
--check if spanish
if format == "es" or name:find(" y ") then
i, j = name:find(" de ")
if i ~= nil then
lastName = name:sub(j + 1)
k, l = lastName:reverse():match("(%S+) (%S+)")
if k ~= nil and l ~= nil then
if lastName:find("de") == nil then
lastName = l:reverse() .. " " .. k:reverse()
end
end
givenName = name:sub(1, i - 1)
obtain = 1
elseif name:find(" y ") then
i, j, k = name:reverse():match("(%S+) (%S+) (%S+)")
lastName = k:reverse() .. " " .. j:reverse() .. " " .. i:reverse()
i, j = name:find(lastName)
givenName = name:sub(1, i - 2)
obtain = 1
else
givenName = name:match("%a+")
i, j = name:find(givenName)
lastName = name:sub(j + 2)
obtain = 1
end
end
--check if thai
if format == "th" then
givenName = name:match("%S+")
i, j = name:find(givenName)
lastName = name:sub(j + 2)
obtain = 1
end
--normal name
if obtain == 0 then
i, j = name:reverse():find("%S+")
lastName = name:reverse():sub(i, j)
lastName = lastName:reverse()
givenName = name:reverse():sub(j + 2)
givenName = givenName:reverse()
--[[lastName = name:reverse():match("%S+")
lastName = lastName:reverse()
i, j = name:find(lastName)
givenName = name:sub(1, i-2)]]
end
out = "''Given'' = " .. givenName .. " -- ''Family'' = " .. lastName
return out
end
return p
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.