Module:VL-adj

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Called by {{VL-adj-1&2}} and {{VL-adj-3rd}}. Do not use directly.


local m_links = require("Module:links")
local m_utilities = require("Module:utilities")
local m_vl_translit = require("Module:VL-translit")

local lang = require("Module:languages").getByCode("la")

local export = {}

local branch_links = {
	["It-W"] = "[[w:Italo-Western languages|Italo-Western]]",
	["E"] = "[[w:Eastern Romance languages|Eastern]]",
	["S"] = "[[w:Sardinian language|Sardinian]]",
}

local decl_names = {
	["1&2"] = "First/second declension",
	["3rd"] = "Third declension",
	["accum ille"] = "Irregular, but similar to first and second declensions"
}

local decls = {}

decls["1&2"] = {
	params = {
		[1] = {},
		},
}
setmetatable(decls["1&2"], {__call = function(self, args, data)
	data.forms["nom-sg-m"] = {args[1] .. "us"}
	data.forms["nom-pl-m"] = {args[1] .. "ī"}
	data.forms["gen-sg-m"] = {args[1] .. "ī"}
	data.forms["gen-pl-m"] = {args[1] .. "ōrum"}
	data.forms["dat-sg-m"] = {args[1] .. "ō"}
	data.forms["dat-pl-m"] = {args[1] .. "īs"}
	data.forms["acc-abl-sg-m"] = {args[1] .. "um"}
	data.forms["acc-abl-pl-m"] = {args[1] .. "ōs"}
	
	data.forms["nom-sg-f"] = {args[1] .. "a"}
	data.forms["nom-pl-f"] = {args[1] .. "ae"}
	data.forms["gen-sg-f"] = {args[1] .. "ae"}
	data.forms["gen-pl-f"] = {args[1] .. "ārum"}
	data.forms["dat-sg-f"] = {args[1] .. "ae"}
	data.forms["dat-pl-f"] = {args[1] .. "īs"}
	data.forms["acc-abl-sg-f"] = {args[1] .. "am"}
	data.forms["acc-abl-pl-f"] = {args[1] .. "ās"}
	
	data.forms["nom-sg-n"] = {args[1] .. "u"}
	data.forms["nom-pl-n"] = {args[1] .. "a"}
	data.forms["gen-sg-n"] = {args[1] .. "ī"}
	data.forms["gen-pl-n"] = {args[1] .. "ōrum"}
	data.forms["dat-sg-n"] = {args[1] .. "ō"}
	data.forms["dat-pl-n"] = {args[1] .. "īs"}
	data.forms["acc-abl-sg-n"] = {args[1] .. "um"}
	data.forms["acc-abl-pl-n"] = {args[1] .. "a"}
	
	table.insert(data.categories, "Latin first and second declension adjectives")
end
})

decls["3rd"] = {
	params = {
		[1] = {},
		},
}
setmetatable(decls["3rd"], {__call = function(self, args, data)
	data.forms["nom-sg-m"] = {args[1] .. "is"}
	data.forms["nom-pl-m"] = {args[1] .. "ēs"}
	data.forms["gen-sg-m"] = {args[1] .. "is"}
	data.forms["gen-pl-m"] = {args[1] .. "ium"}
	data.forms["dat-sg-m"] = {args[1] .. "ī"}
	data.forms["dat-pl-m"] = {args[1] .. "ibus"}
	data.forms["acc-abl-sg-m"] = {args[1] .. "em"}
	data.forms["acc-abl-pl-m"] = {args[1] .. "es"}
	
	data.forms["nom-sg-f"] = {args[1] .. "is"}
	data.forms["nom-pl-f"] = {args[1] .. "ēs"}
	data.forms["gen-sg-f"] = {args[1] .. "is"}
	data.forms["gen-pl-f"] = {args[1] .. "ium"}
	data.forms["dat-sg-f"] = {args[1] .. "ī"}
	data.forms["dat-pl-f"] = {args[1] .. "ibus"}
	data.forms["acc-abl-sg-f"] = {args[1] .. "em"}
	data.forms["acc-abl-pl-f"] = {args[1] .. "es"}
	
	data.forms["nom-sg-n"] = {args[1] .. "e"}
	data.forms["nom-pl-n"] = {args[1] .. "ia"}
	data.forms["gen-sg-n"] = {args[1] .. "is"}
	data.forms["gen-pl-n"] = {args[1] .. "ium"}
	data.forms["dat-sg-n"] = {args[1] .. "ī"}
	data.forms["dat-pl-n"] = {args[1] .. "ibus"}
	data.forms["acc-abl-sg-n"] = {args[1] .. "em"}
	data.forms["acc-abl-pl-n"] = {args[1] .. "ia"}
	
	table.insert(data.categories, "Latin third declension adjectives")
end
})

decls["accum ille"] = {}
setmetatable(decls["accum ille"], {__call = function(self, args, data)
	data.forms["nom-sg-m"] = {"accum ille", "accum illī"}
	data.forms["nom-pl-m"] = {"accum illī"}
	data.forms["gen-sg-m"] = {"accum illūius"}
	data.forms["gen-pl-m"] = {"accum illōrum"}
	data.forms["dat-sg-m"] = {"accum illī", "accum illūi"}
	data.forms["dat-pl-m"] = {"accum illīs", "accum illōrum"}
	data.forms["acc-abl-sg-m"] = {"accum illum"}
	data.forms["acc-abl-pl-m"] = {"accum illōs"}
	
	data.forms["nom-sg-f"] = {"accum illa"}
	data.forms["nom-pl-f"] = {"accum illae"}
	data.forms["gen-sg-f"] = {"accum illaeius"}
	data.forms["gen-pl-f"] = {"accum illōrum"}
	data.forms["dat-sg-f"] = {"accum illī", "accum illae", "accum illaei"}
	data.forms["dat-pl-f"] = {"accum illīs"}
	data.forms["acc-abl-sg-f"] = {"accum illam"}
	data.forms["acc-abl-pl-f"] = {"accum illās"}
	
	data.forms["nom-sg-n"] = {"accum illum"}
	data.forms["nom-pl-n"] = {"accum illa"}
	data.forms["gen-sg-n"] = {}
	data.forms["gen-pl-n"] = {"accum illōrum"}
	data.forms["dat-sg-n"] = {}
	data.forms["dat-pl-n"] = {"accum illīs"}
	data.forms["acc-abl-sg-n"] = {"accum illum"}
	data.forms["acc-abl-pl-n"] = {"accum illa"}

end
})

local cases = {
	["nominative"] = {short_form = "nom", link = "''[[nominative case|nominative]]''"},
	["accusative-ablative"] = {short_form = "acc-abl", link = "''[[accusative case|accusative]]-[[ablative case|ablative]]''"},
	["genitive"] = {short_form = "gen", link = "''[[genitive case|genitive]]''"},
	["dative"] = {short_form = "dat", link = "''[[dative case|dative]]''"},
}

local function make_headers(data, wikicode)
	table.insert(wikicode, '|- class="vsHide"\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[3] .. '; font-style:italic;" | Number\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[3] .. '; font-style:italic;" colspan="3" | Singular\n')
	table.insert(wikicode, '|rowspan="2" |\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[3] .. '; font-style:italic;" colspan="3" | Plural\n')
	table.insert(wikicode, '|- class="vsHide"\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. '; font-style:italic;"| Case / Gender\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. ';"| Masculine\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. ';"| Feminine\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. ';"| Neuter\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. ';"| Masculine\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. ';"| Feminine\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. ';"| Neuter\n')
end

local function show_forms(forms, data, branch)
	local function show_single_form(form, data, branch)
		local function convert_word(form, branch)
			if mw.ustring.find(form, "{{{") then
				return form
			else
				return m_vl_translit.convert_words(form, branch)
			end
		end
	
		if not form then
			return "—"
		end
		
		return m_links.full_link({lang = lang, alt = convert_word(form, branch), term = "*" .. form})
	end
	
	local form_t = {}

	for i, form in ipairs(forms) do
		table.insert(form_t, show_single_form(form, data, branch))
	end
	return table.concat(form_t, ", ")
end

local function make_case(data, wikicode, case, branch)
	local case_short = cases[case].short_form
	table.insert(wikicode, '|- class="vsHide"\n')
	table.insert(wikicode, '! style="background:#' .. data.latincolour[1] .. ';" | ' .. cases[case].link .. '\n')
	table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_forms(data.forms[case_short .. '-sg-m'], data, branch) .. '\n')
	table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_forms(data.forms[case_short .. '-sg-f'], data, branch) .. '\n')
	table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_forms(data.forms[case_short .. '-sg-n'], data, branch) .. '\n')
	if case_short == "nom" then table.insert(wikicode, '|rowspan="4"|\n') end
	table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_forms(data.forms[case_short .. '-pl-m'], data, branch) .. '\n')
	table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_forms(data.forms[case_short .. '-pl-f'], data, branch) .. '\n')
	table.insert(wikicode, '| style="background:#' .. data.latincolour[2] .. ';" | ' .. show_forms(data.forms[case_short .. '-pl-n'], data, branch) .. '\n')
end

local function make_table(data, branch)
	local wikicode = {'{| class="prettytable inflection-table vsSwitcher" data-toggle-category="inflection"\n'}
	table.insert(wikicode, '! colspan="8" class="vsToggleElement" style="text-align:left;min-width: 25em;background:#' ..
				 data.latincolour[1] .. '" | ')
	table.insert(wikicode, branch_links[branch] .. ' declension of #head\n')

	make_headers(data, wikicode)
	make_case(data, wikicode, "nominative", branch)
	make_case(data, wikicode, "genitive", branch)
	make_case(data, wikicode, "dative", branch)
	make_case(data, wikicode, "accusative-ablative", branch)

	table.insert(wikicode, "|}")
	
	return table.concat(wikicode)
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local parent_args = frame:getParent().args
	
	local decl_type = (frame.args["decl"] or parent_args["decl"]) or "1&2"
	
	if not decls[decl_type] then
		error("Unknown declension type '" .. decl_type .. "'")
	end
	
	local data = {forms = {}, categories = {}}
	data.head = parent_args["head"] or nil
	
	data.latincolour = {
		frame:expandTemplate({title = "Latincolour1"}),
		frame:expandTemplate({title = "Latincolour2"}),
		frame:expandTemplate({title = "Latincolour3"}),
	}

	local args = {}
	
	if decls[decl_type].params then
		args = require("Module:parameters").process(parent_args, decls[decl_type].params, true)
	end
	
	if mw.title.getCurrentTitle().nsText == "Template" then
		setmetatable(args, {__index = function(self, key)
			return "{{{" .. key .. "}}}"
		end
		})
	end
	
	-- Generate the forms
	decls[decl_type](args, data)
	data["decl"] = decl_type
	
	-- Make the table
	t = decl_names[data.decl] .. '.\n\n'
	if parent_args.family then
		t = t .. make_table(data, parent_args.family)
		if parent_args.family2 then
			t = t .. "\n" .. make_table(data, parent_args.family2)
		end
	else
		t = t .. make_table(data, "It-W") .. "\n" .. make_table(data, "E") .. "\n" .. make_table(data, "S")
	end
	t = mw.ustring.gsub(t, "#head", m_links.full_link({lang = lang, alt = "*" .. data.forms["nom-sg-m"][1]}, "term"))
	return t .. m_utilities.format_categories(data.categories, lang)
end

return export