Module:osx-decl-adj

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local m_links = require("Module:links")
local m_utils = require("Module:utilities")

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

local headers = {}

headers.strong = [=[
|- style="background-color:#EFEFEF; "
|-
! style="background-color:#FBEC5D;" colspan="7" | Strong declension
]=]

headers.weak = [=[
|- style="background-color:#EFEFEF; "
|-
! style="background-color:#FBEC5D;" colspan="7" | Weak declension
]=]

headers.top = function(text)
	return [=[<div class="NavFrame" style="float: left; width: 100%;">
<div class="NavHead" style="text-align: center">]=] .. text .. [=[</div>
<div class="NavContent">
{| style="width: 100%; line-height: 125%; background-color:#F9F9F9; text-align:center; border: 1px solid #CCCCFF;" cellpadding="3" cellspacing="1" class="inflection-table"
|- style="background-color:#EFEFEF; "
|-
]=]
end

local decl_data = {}

decl_data["st"] = {}
setmetatable(decl_data["st"], {__call = function(self, stem, data)
	
	data.forms["nom_sg_m"] = {stem}
	data.forms["nom_sg_f"] = {stem}
	data.forms["nom_sg_n"] = {stem}
	data.forms["nom_pl_m"] = {stem .. "e", stem .. "a"}
	data.forms["nom_pl_f"] = {stem .. "a"}
	data.forms["nom_pl_n"] = {stem, stem .. "a"}

	data.forms["acc_sg_m"] = {stem .. "an", stem .. "en"}
	data.forms["acc_sg_f"] = {stem .. "a"}
	data.forms["acc_sg_n"] = {stem}
	data.forms["acc_pl_m"] = {stem .. "a", stem .. "e"}
	data.forms["acc_pl_f"] = {stem .. "a"}
	data.forms["acc_pl_n"] = {stem, stem .. "a"}
	
	data.forms["gen_sg_m"] = {stem .. "es", stem .. "as"}
	data.forms["gen_sg_f"] = {stem .. "ara", stem .. "aro"}
	data.forms["gen_sg_n"] = {stem .. "es", stem .. "as"}
	data.forms["gen_pl_m"] = {stem .. "aro", stem .. "oro", stem .. "ero"}
	data.forms["gen_pl_f"] = {stem .. "aro", stem .. "oro", stem .. "ero"}
	data.forms["gen_pl_n"] = {stem .. "aro", stem .. "oro", stem .. "ero"}
	
	data.forms["dat_sg_m"] = {stem .. "umu", stem .. "um", stem .. "un", stem .. "un", stem .. "on", stem .. "en", stem .. "an"}
	data.forms["dat_sg_f"] = {stem .. "aro", stem .. "aru", stem .. "ara"}
	data.forms["dat_sg_n"] = {stem .. "umu", stem .. "um", stem .. "un", stem .. "un", stem .. "on", stem .. "en", stem .. "an"}
	data.forms["dat_pl_m"] = {stem .. "un", stem .. "on", stem .. "um"}
	data.forms["dat_pl_f"] = {stem .. "un", stem .. "on"}
	data.forms["dat_pl_n"] = {stem .. "un", stem .. "on", stem .. "um"}

	return data
end
})

decl_data["wk"] = {}
setmetatable(decl_data["wk"], {__call = function(self, stem, data)
	
	data.forms["nom_sg_m"] = {stem .. "o", stem .. "a"}
	data.forms["nom_sg_f"] = {stem .. "a", stem .. "e"}
	data.forms["nom_sg_n"] = {stem .. "a", stem .. "e"}
	data.forms["nom_pl_m"] = {stem .. "on", stem .. "un"}
	data.forms["nom_pl_f"] = {stem .. "on", stem .. "un", stem .. "an"}
	data.forms["nom_pl_n"] = {stem .. "on", stem .. "un"}

	data.forms["acc_sg_m"] = {stem .. "on", stem .. "an"}
	data.forms["acc_sg_f"] = {stem .. "un", stem .. "on", stem .. "an"}
	data.forms["acc_sg_n"] = {stem .. "a", stem .. "e"}
	data.forms["acc_pl_m"] = {stem .. "on", stem .. "un"}
	data.forms["acc_pl_f"] = {stem .. "on", stem .. "un", stem .. "an"}
	data.forms["acc_pl_n"] = {stem .. "on", stem .. "un"}
	
	data.forms["gen_sg_m"] = {stem .. "en", stem .. "an"}
	data.forms["gen_sg_f"] = {stem .. "un", stem .. "an", stem .. "en"}
	data.forms["gen_sg_n"] = {stem .. "en", stem .. "an"}
	data.forms["gen_pl_m"] = {stem .. "ono", stem .. "eno"}
	data.forms["gen_pl_f"] = {stem .. "ono"}
	data.forms["gen_pl_n"] = {stem .. "ono", stem .. "eno"}

	data.forms["dat_sg_m"] = {stem .. "on", stem .. "en", stem .. "an"}
	data.forms["dat_sg_f"] = {stem .. "un", stem .. "an"}
	data.forms["dat_sg_n"] = {stem .. "on", stem .. "en", stem .. "an"}
	data.forms["dat_pl_m"] = {stem .. "on", stem .. "un"}
	data.forms["dat_pl_f"] = {stem .. "on", stem .. "un"}
	data.forms["dat_pl_n"] = {stem .. "on", stem .. "un"}
	
	return data
end
})

function insert_all(tb, args)
	for _, v in ipairs(args) do
		table.insert(tb, v)
	end
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 data = {forms = {}, categories = {}}
	
	data.head = parent_args["head"] or nil
	
	-- Override for templates
	if not parent_args[1] then
		setmetatable(parent_args, {__index = function(self, key)
			return "{{{" .. key .. "}}}"
		end
		})
	end

	local wikicode = {}
	
	if parent_args.decl == "st" then
		-- do nothing yet
	else
		if parent_args[1] ~= "" then
			insert_all(wikicode, {headers.top("Positive forms of " .. parent_args[1]), headers.strong,
				make_base_table(decl_data.st(parent_args[1], data)), headers.weak, make_base_table(decl_data.wk(parent_args[1], data)),
				'|}</div></div><br clear="all" />'})
		end
		if parent_args[2] and parent_args[2] ~= "" then
			insert_all(wikicode, {headers.top("Comparative forms of " .. parent_args[1] .. " (weak only)"), headers.weak,
				make_base_table(decl_data.wk(parent_args[2], data)), '|}</div></div><br clear="all" />'})
		end
		if parent_args[3] and parent_args[3] ~= "" then
			insert_all(wikicode, {headers.top("Superlative forms of " .. parent_args[1]), headers.strong,
				make_base_table(decl_data.st(parent_args[3], data)), headers.weak, make_base_table(decl_data.wk(parent_args[3], data)),
				'|}</div></div><br clear="all" />'})
		end
	end

	-- Make the table
	return table.concat(wikicode)
end


local function show_form(form)
	if not form then
		return "—"
	end
	
	local ret = {}
	
	for key, subform in ipairs(form) do
		if mw.title.getCurrentTitle().nsText == "Reconstruction" and subform ~= "—" then
			subform = "*" .. subform
		end
		table.insert(ret, m_links.full_link({lang = lang, term = subform}))
	end
		
	return table.concat(ret, ", ")
end

function make_base_table(data)
	local function repl(param)
		if param == "decl_type" then
			return data.decl_type
		else
			return show_form(data.forms[param])
		end
	end

	local wikicode = [=[
|-
! gender
! style="width: 33%; background-color:#FDD5B1" colspan="2" | masculine
! style="width: 33%; background-color:#FDD5B1" colspan="2" | feminine
! style="width: 33%; background-color:#FDD5B1" colspan="2" | neuter
|-
! case
! style="width: 16%; background-color:#FFEFD5" | singular
! style="width: 16%; background-color:#FFEFD5" | plural
! style="width: 16%; background-color:#FFEFD5" | singular
! style="width: 16%; background-color:#FFEFD5" | plural
! style="width: 16%; background-color:#FFEFD5" | singular
! style="width: 16%; background-color:#FFEFD5" | plural
|-
! style="background-color:#FFEFD5; text-align:left; font-size:90%;"| nominative
| style="background-color:#ffffff;" | {{{nom_sg_m}}}
| style="background-color:#ffffff;" | {{{nom_pl_m}}}
| style="background-color:#ffffff;" | {{{nom_sg_f}}}
| style="background-color:#ffffff;" | {{{nom_pl_f}}}
| style="background-color:#ffffff;" | {{{nom_sg_n}}}
| style="background-color:#ffffff;" | {{{nom_pl_n}}}
|-
! style="background-color:#FFEFD5; text-align:left; font-size:90%;"| accusative
| style="background-color:#ffffff;" | {{{acc_sg_m}}}
| style="background-color:#ffffff;" | {{{acc_pl_m}}}
| style="background-color:#ffffff;" | {{{acc_sg_f}}}
| style="background-color:#ffffff;" | {{{acc_pl_f}}}
| style="background-color:#ffffff;" | {{{acc_sg_n}}}
| style="background-color:#ffffff;" | {{{acc_pl_n}}}
|-
! style="background-color:#FFEFD5; text-align:left; font-size:90%;"| genitive
| style="background-color:#ffffff;" | {{{gen_sg_m}}}
| style="background-color:#ffffff;" | {{{gen_pl_m}}}
| style="background-color:#ffffff;" | {{{gen_sg_f}}}
| style="background-color:#ffffff;" | {{{gen_pl_f}}}
| style="background-color:#ffffff;" | {{{gen_sg_n}}}
| style="background-color:#ffffff;" | {{{gen_pl_n}}}
|-
! style="background-color:#FFEFD5; text-align:left; font-size:90%;"| dative
| style="background-color:#ffffff;" | {{{dat_sg_m}}}
| style="background-color:#ffffff;" | {{{dat_pl_m}}}
| style="background-color:#ffffff;" | {{{dat_sg_f}}}
| style="background-color:#ffffff;" | {{{dat_pl_f}}}
| style="background-color:#ffffff;" | {{{dat_sg_n}}}
| style="background-color:#ffffff;" | {{{dat_pl_n}}}
]=]

	local ret = mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)
	return ret
end

return export