Opening summary: prefer full birth/death dates (Wikipedia style)
Split arm/service from Branch; expand Qu religion; hide Not stated
Line 499: Line 499:
ISLAM = 'Muslim',
ISLAM = 'Muslim',
Q = 'Quaker',
Q = 'Quaker',
QU = 'Quaker',
QUA = 'Quaker',
QUAKER = 'Quaker',
FRIENDS = 'Quaker',
N = 'None',
N = 'None',
X = 'Not stated',
X = 'Not stated',
Line 668: Line 672:
key = mw.ustring.gsub(key, '%s+', ' ')
key = mw.ustring.gsub(key, '%s+', ' ')
key = trim(key)
key = trim(key)
if RELIGION_NAME[key] then
local mapped = RELIGION_NAME[key]
return RELIGION_NAME[key]
if mapped then
-- Hide non-informative roster placeholders from the infobox.
if mapped == 'Not stated' or mapped == 'None' or mapped == 'Unknown' then
return ''
end
return mapped
end
end
local lower = mw.ustring.lower(s)
local lower = mw.ustring.lower(s)
if lower == 'not stated' or lower == 'none' or lower == 'unknown'
or lower == 'n/a' or lower == 'na' then
return ''
end
if lower == 'hebrew' or lower == 'jewish' or lower == 'jew'
if lower == 'hebrew' or lower == 'jewish' or lower == 'jew'
or mw.ustring.find(lower, 'jewish', 1, true)
or mw.ustring.find(lower, 'jewish', 1, true)
or mw.ustring.find(lower, 'hebrew', 1, true) then
or mw.ustring.find(lower, 'hebrew', 1, true) then
return 'Jewish'
return 'Jewish'
end
if lower == 'quaker' or lower == 'friends' then
return 'Quaker'
end
end
return prettyProse(s)
return prettyProse(s)
Line 1,087: Line 1,103:
['CAV'] = 'Cavalry',
['CAV'] = 'Cavalry',
['CAVALRY'] = 'Cavalry',
['CAVALRY'] = 'Cavalry',
['CALVALRY'] = 'Cavalry',
['CE'] = 'Corps of Engineers',
['CE'] = 'Corps of Engineers',
['ENG'] = 'Corps of Engineers',
['ENG'] = 'Corps of Engineers',
Line 1,153: Line 1,170:
end
end
return raw
return raw
end
local function keyEqualsAAF(part)
local key = mw.ustring.upper(trim(part))
key = mw.ustring.gsub(key, '%.', '')
key = mw.ustring.gsub(key, '%s+', ' ')
return key == 'AAF' or key == 'ARMY AIR FORCES'
end
-- True when a BRANCH_MAP / class_branch value is an Army arm/service, not Army/Marines/Navy.
local SERVICE_BRANCH_KEY = {
['AUS'] = true,
['USA'] = true,
['ARMY'] = true,
['UNITED STATES ARMY'] = true,
['US ARMY'] = true,
['USMC'] = true,
['USMCR'] = true,
['MARINES'] = true,
['MARINE CORPS'] = true,
['UNITED STATES MARINE CORPS'] = true,
['USN'] = true,
['NAVY'] = true,
['UNITED STATES NAVY'] = true,
['USCG'] = true,
['COAST GUARD'] = true,
['UNITED STATES COAST GUARD'] = true,
['AAF'] = true,
['ARMY AIR FORCES'] = true,
['UNITED STATES ARMY AIR FORCES'] = true,
['PA'] = true,
['PHILIPPINE ARMY'] = true,
['RCE'] = true,
['RCA'] = true,
}
local function isServiceBranchName(name)
name = trim(name)
if name == '' then
return false
end
local key = mw.ustring.upper(name)
key = mw.ustring.gsub(key, '%.', '')
key = mw.ustring.gsub(key, '%s+', ' ')
key = trim(key)
if SERVICE_BRANCH_KEY[key] then
return true
end
local low = mw.ustring.lower(name)
if mw.ustring.find(low, 'marine', 1, true)
or mw.ustring.find(low, 'navy', 1, true)
or mw.ustring.find(low, 'coast guard', 1, true) then
return true
end
if mw.ustring.find(low, 'air force', 1, true)
or mw.ustring.find(low, 'air forces', 1, true) then
return true
end
if mw.ustring.find(low, 'united states army', 1, true)
or low == 'army'
or low == 'u.s. army'
or low == 'us army' then
return true
end
return false
end
local function isArmOfServiceToken(raw)
raw = trim(raw)
if raw == '' then
return false
end
local key = mw.ustring.upper(raw)
key = mw.ustring.gsub(key, '%.', '')
key = mw.ustring.gsub(key, '%s+', ' ')
key = trim(key)
if SERVICE_BRANCH_KEY[key] then
return false
end
if BRANCH_MAP[key] then
return true
end
local low = mw.ustring.lower(raw)
if mw.ustring.find(low, 'calvalry', 1, true) then
return true
end
for _, needle in ipairs({
'artillery', 'signal', 'cavalry', 'infantry', 'engineer',
'ordnance', 'quartermaster', 'medical', 'police', 'intelligence',
'armor', 'tank destroyer', 'chemical', 'chaplain', 'transportation',
'adjutant',
}) do
if mw.ustring.find(low, needle, 1, true) then
return true
end
end
return false
end
local function splitBranchAndArm(branchRaw, classBranchRaw, armRaw)
branchRaw = trim(branchRaw)
classBranchRaw = trim(classBranchRaw)
armRaw = trim(armRaw)
local service = ''
local arms = {}
local function consider(raw, preferArm)
raw = trim(raw)
if raw == '' then
return
end
for part in mw.text.gsplit(raw, ';', true) do
part = trim(part)
if part ~= '' then
local expanded = expandBranchToken(part)
if isServiceBranchName(expanded) or isServiceBranchName(part) then
if service == '' then
service = expandBranchToken(part)
if not isServiceBranchName(service) then
-- expandBranchToken may not rewrite "Army"
local low = mw.ustring.lower(part)
if mw.ustring.find(low, 'marine', 1, true) then
service = 'United States Marine Corps'
elseif mw.ustring.find(low, 'navy', 1, true) then
service = 'United States Navy'
elseif mw.ustring.find(low, 'air force', 1, true)
or mw.ustring.find(low, 'air forces', 1, true)
or keyEqualsAAF(part) then
service = 'United States Army Air Forces'
else
service = 'United States Army'
end
end
end
elseif preferArm or isArmOfServiceToken(part) or isArmOfServiceToken(expanded) then
local armName = expanded
if mw.ustring.find(mw.ustring.lower(part), 'calvalry', 1, true) then
armName = 'Cavalry'
end
local dup = false
for _, existing in ipairs(arms) do
if existing == armName then
dup = true
break
end
end
if not dup then
table.insert(arms, armName)
end
elseif preferArm then
table.insert(arms, expanded)
elseif service == '' and not preferArm then
service = expanded
end
end
end
end
-- Explicit arm_or_service first
consider(armRaw, true)
-- Roster class_branch is almost always arm/service within the Army
consider(classBranchRaw, true)
-- |branch= may be either
consider(branchRaw, false)
local armJoined = table.concat(arms, '; ')
return service, armJoined
end
end


Line 1,670: Line 1,855:
addHeader(tbl, 'Military service')
addHeader(tbl, 'Military service')
addRow(tbl, 'Allegiance', '[[File:Flag of the United States.png|20px|link=|alt=]] United States')
addRow(tbl, 'Allegiance', '[[File:Flag of the United States.png|20px|link=|alt=]] United States')
local branchRaw = parentArg(frame, 'class_branch')
local serviceName, armName = splitBranchAndArm(
if branchRaw == '' then
parentArg(frame, 'branch'),
branchRaw = parentArg(frame, 'branch')
parentArg(frame, 'class_branch'),
parentArg(frame, 'arm_or_service')
)
if serviceName == '' then
serviceName = 'United States Army'
end
end
local branch = expandBranch(branchRaw)
addRow(tbl, 'Branch', branchWithEmblem(serviceName))
if branch == '' then
if armName ~= '' then
branch = branchWithEmblem('United States Army')
-- Roster "branch" codes (FA, Signal Corps, Cavalry, …) are arm/service, not Army/Marines.
addRow(tbl, 'Arm / service', prettyProse(armName))
end
end
addRow(tbl, 'Branch', branch)
addRow(tbl, 'Years of service', prettyProse(parentArg(frame, 'years_of_service')))
addRow(tbl, 'Years of service', prettyProse(parentArg(frame, 'years_of_service')))
addRow(tbl, 'ASN', parentArg(frame, 'asn'), 'serial')
addRow(tbl, 'ASN', parentArg(frame, 'asn'), 'serial')