Soft launch: Soldier biographies and research notes vary in completeness. Prefer class-roster, NARA, newspapers, and other cited sources for contested facts — treat Research notes as leads, not settled history. Anyone can correct a page; contact us with questions.

Module:SplitCats: Difference between revisions

From Ritchie Boys Wiki
Jump to navigation Jump to search
Normalize IPW T/? codes; skip Armd; map 424-G-style codes to MII
Skip bogus IPW labels (CSU, Doc Team, FH, FID, Illness, etc.)
Line 9: Line 9:
end
end
return nil
return nil
end
local function isJunkIpwLabel(part)
local lower = mw.ustring.lower(mw.text.trim(part or ''))
if lower == 'csu' or lower == 'fh' or lower == 'fid' or lower == 'illness' then
return true
end
local compact = mw.ustring.gsub(lower, '%s+', '')
if compact == 'docteam' then
return true
end
return false
end
end


Line 26: Line 38:
end
end
if miiLetterCode(part) then
if miiLetterCode(part) then
return nil
end
if isJunkIpwLabel(part) then
return nil
return nil
end
end
Line 37: Line 52:
if mw.ustring.match(part, '^%d+$') then
if mw.ustring.match(part, '^%d+$') then
return part
return part
end
if isJunkIpwLabel(part) then
return nil
end
end
return part
return part

Revision as of 03:35, 19 August 2026

Documentation for this module may be created at Module:SplitCats/doc

local p = {}

-- IPW roster codes: 148T -> 148, 178? -> 178.
-- Skip "14th Armd" / "2nd Armd". Lettered codes like 424-G are MII, not IPW.
local function miiLetterCode(part)
	local num, letter = mw.ustring.match(part, '^(%d+)%s*[%-–—]%s*([A-Za-z])$')
	if num and letter then
		return num .. '-' .. mw.ustring.upper(letter)
	end
	return nil
end

local function isJunkIpwLabel(part)
	local lower = mw.ustring.lower(mw.text.trim(part or ''))
	if lower == 'csu' or lower == 'fh' or lower == 'fid' or lower == 'illness' then
		return true
	end
	local compact = mw.ustring.gsub(lower, '%s+', '')
	if compact == 'docteam' then
		return true
	end
	return false
end

local function normalizeIpwCode(part)
	part = mw.text.trim(part or '')
	if part == '' then
		return nil
	end
	part = mw.ustring.gsub(part, '%s*%?+%s*$', '')
	part = mw.text.trim(part)
	if part == '' then
		return nil
	end
	local lower = mw.ustring.lower(part)
	if mw.ustring.find(lower, 'armd', 1, true) or mw.ustring.find(lower, 'armored', 1, true) then
		return nil
	end
	if miiLetterCode(part) then
		return nil
	end
	if isJunkIpwLabel(part) then
		return nil
	end
	local num = mw.ustring.match(part, '^(%d+)[Tt]$')
	if num then
		return num
	end
	if mw.ustring.match(lower, '^%d+(st|nd|rd|th)$') then
		return nil
	end
	if mw.ustring.match(part, '^%d+$') then
		return part
	end
	if isJunkIpwLabel(part) then
		return nil
	end
	return part
end

function p.categories(frame)
	local raw = frame.args[1] or ''
	local prefix = frame.args[2] or 'Class '
	raw = mw.ustring.gsub(raw, ';', ';')
	local isIpw = mw.ustring.find(prefix, 'Team IPW', 1, true) == 1
	local out = {}
	for part in mw.text.gsplit(raw, ';', true) do
		part = mw.text.trim(part)
		if part ~= '' and not mw.ustring.find(part, ';', 1, true) then
			if isIpw then
				local mii = miiLetterCode(part)
				if mii then
					table.insert(out, '[[Category:Team MII ' .. mii .. ']]')
				else
					part = normalizeIpwCode(part)
					if part then
						table.insert(out, '[[Category:' .. prefix .. part .. ']]')
					end
				end
			else
				table.insert(out, '[[Category:' .. prefix .. part .. ']]')
			end
		end
	end
	return table.concat(out)
end

function p.letterCategory(frame)
	local title = mw.title.getCurrentTitle()
	local first = mw.ustring.upper(mw.ustring.sub(title.text, 1, 1))
	if mw.ustring.match(first, '[A-Z]') then
		return '[[Category:Soldiers ' .. first .. ']]'
	end
	return '[[Category:Soldiers other]]'
end

return p