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
Skip bogus IPW and IPW Italian labels
Fix 5th class exact-string map to Italian 5
 
(4 intermediate revisions by the same user not shown)
Line 3: Line 3:
-- IPW roster codes: 148T -> 148, 178? -> 178.
-- IPW roster codes: 148T -> 148, 178? -> 178.
-- Skip "14th Armd" / "2nd Armd". Lettered codes like 424-G are MII, not IPW.
-- Skip "14th Armd" / "2nd Armd". Lettered codes like 424-G are MII, not IPW.
-- 540-R / 545-R / 546-R categorize as unlettered MII 540/545/546.
local function miiLetterCode(part)
local function miiLetterCode(part)
local num, letter = mw.ustring.match(part, '^(%d+)%s*[%-–—]%s*([A-Za-z])$')
local num, letter = mw.ustring.match(part, '^(%d+)%s*[%-–—]%s*([A-Za-z])$')
if num and letter then
if num and letter then
return num .. '-' .. mw.ustring.upper(letter)
letter = mw.ustring.upper(letter)
if letter == 'R' and (num == '540' or num == '545' or num == '546') then
return num
end
return num .. '-' .. letter
end
end
return nil
return nil
Line 18: Line 23:
['16320'] = true, ['16695'] = true,
['16320'] = true, ['16695'] = true,
['1st army'] = true, ['2 day'] = true, ['2/23/44'] = true,
['1st army'] = true, ['2 day'] = true, ['2/23/44'] = true,
['468th cic'] = true, ['5/7/45'] = true, ['8/24/44'] = true, ['8/7/43'] = true,
['apid'] = true, ['i-32'] = true, ['mis-eto'] = true, ['mitc'] = true,
['pac'] = true, ['sc7'] = true, ['shaef'] = true, ['v-831'] = true,
}
}
return junk[spaced] == true
return junk[spaced] == true
end
local function normalizeIpwItalianCode(part)
part = mw.text.trim(part or '')
if part == '' or isJunkIpwItalianLabel(part) then
return nil
end
local spaced = mw.ustring.lower(mw.ustring.gsub(part, '%s+', ' '))
if spaced == '5th class' or spaced == 'italian 5th class' then
return '5'
end
return part
end
end


local function isJunkIpwLabel(part)
local function isJunkIpwLabel(part)
local lower = mw.ustring.lower(mw.text.trim(part or ''))
local lower = mw.ustring.lower(mw.text.trim(part or ''))
if lower == 'csu' or lower == 'fh' or lower == 'fid' or lower == 'illness' then
lower = mw.ustring.gsub(lower, '%s+', ' ')
lower = mw.ustring.gsub(lower, '%s*%?+%s*$', '')
lower = mw.text.trim(lower)
if lower == 'csu' or lower == 'fh' or lower == 'fid' or lower == 'illness'
or lower == 'mfiu-5' or lower == 'mfiu 5' or lower == 'mitu 5' or lower == 'mitu-5'
or lower == 'mrbc4' or lower == 'mrbc 4' or lower == 't force' or lower == 'to cic' then
return true
return true
end
end
local compact = mw.ustring.gsub(lower, '%s+', '')
local compact = mw.ustring.gsub(lower, '[%s%-]+', '')
if compact == 'docteam' then
if compact == 'docteam' or compact == 'mfiu5' or compact == 'mitu5'
or compact == 'mrbc4' or compact == 'tforce' or compact == 'tocic' then
return true
return true
end
end
Line 84: Line 110:
table.insert(out, '[[Category:Team MII ' .. mii .. ']]')
table.insert(out, '[[Category:Team MII ' .. mii .. ']]')
elseif prefix == 'Team IPW Italian ' then
elseif prefix == 'Team IPW Italian ' then
if not isJunkIpwItalianLabel(part) then
part = normalizeIpwItalianCode(part)
if part then
table.insert(out, '[[Category:' .. prefix .. part .. ']]')
table.insert(out, '[[Category:' .. prefix .. part .. ']]')
end
end

Latest revision as of 04:15, 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.
-- 540-R / 545-R / 546-R categorize as unlettered MII 540/545/546.
local function miiLetterCode(part)
	local num, letter = mw.ustring.match(part, '^(%d+)%s*[%-–—]%s*([A-Za-z])$')
	if num and letter then
		letter = mw.ustring.upper(letter)
		if letter == 'R' and (num == '540' or num == '545' or num == '546') then
			return num
		end
		return num .. '-' .. letter
	end
	return nil
end

local function isJunkIpwItalianLabel(part)
	local lower = mw.ustring.lower(mw.text.trim(part or ''))
	local spaced = mw.ustring.gsub(lower, '%s+', ' ')
	local junk = {
		['16063'] = true, ['16095'] = true, ['16302'] = true,
		['16320'] = true, ['16695'] = true,
		['1st army'] = true, ['2 day'] = true, ['2/23/44'] = true,
		['468th cic'] = true, ['5/7/45'] = true, ['8/24/44'] = true, ['8/7/43'] = true,
		['apid'] = true, ['i-32'] = true, ['mis-eto'] = true, ['mitc'] = true,
		['pac'] = true, ['sc7'] = true, ['shaef'] = true, ['v-831'] = true,
	}
	return junk[spaced] == true
end

local function normalizeIpwItalianCode(part)
	part = mw.text.trim(part or '')
	if part == '' or isJunkIpwItalianLabel(part) then
		return nil
	end
	local spaced = mw.ustring.lower(mw.ustring.gsub(part, '%s+', ' '))
	if spaced == '5th class' or spaced == 'italian 5th class' then
		return '5'
	end
	return part
end

local function isJunkIpwLabel(part)
	local lower = mw.ustring.lower(mw.text.trim(part or ''))
	lower = mw.ustring.gsub(lower, '%s+', ' ')
	lower = mw.ustring.gsub(lower, '%s*%?+%s*$', '')
	lower = mw.text.trim(lower)
	if lower == 'csu' or lower == 'fh' or lower == 'fid' or lower == 'illness'
		or lower == 'mfiu-5' or lower == 'mfiu 5' or lower == 'mitu 5' or lower == 'mitu-5'
		or lower == 'mrbc4' or lower == 'mrbc 4' or lower == 't force' or lower == 'to cic' then
		return true
	end
	local compact = mw.ustring.gsub(lower, '[%s%-]+', '')
	if compact == 'docteam' or compact == 'mfiu5' or compact == 'mitu5'
		or compact == 'mrbc4' or compact == 'tforce' or compact == 'tocic' 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 .. ']]')
				elseif prefix == 'Team IPW Italian ' then
					part = normalizeIpwItalianCode(part)
					if part then
						table.insert(out, '[[Category:' .. prefix .. part .. ']]')
					end
				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