Jump to content

Module:ofs-decl-adj

From Wiktionary, the free dictionary

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("ofs")

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 .. "e"}
	data.forms["nom_sg_n"] = {stem}
	data.forms["nom_pl_m"] = {stem .. "a", "e"}
	data.forms["nom_pl_f"] = {stem .. "a", "e"}
	data.forms["nom_pl_n"] = {stem .. "a", "e"}

	data.forms["acc_sg_m"] = {stem .. "", "ne", "ene", "en"}
	data.forms["acc_sg_f"] = {stem .. "e"}
	data.forms["acc_sg_n"] = {stem}
	data.forms["acc_pl_m"] = {stem .. "a", "e"}
	data.forms["acc_pl_f"] = {stem .. "a", "e"}
	data.forms["acc_pl_n"] = {stem .. "a", "e"}
	
	data.forms["gen_sg_m"] = {stem .. "es"}
	data.forms["gen_sg_f"] = {stem .. "ere"}
	data.forms["gen_sg_n"] = {stem .. "es"}
	data.forms["gen_pl_m"] = {stem .. "era"}
	data.forms["gen_pl_f"] = {stem .. "era"}
	data.forms["gen_pl_n"] = {stem .. "era"}
	
	data.forms["dat_sg_m"] = {stem .. "a", "e"}
	data.forms["dat_sg_f"] = {stem .. "ere"}
	data.forms["dat_sg_n"] = {stem .. "a", "e"}
	data.forms["dat_pl_m"] = {stem .. "a", "e"}
	data.forms["dat_pl_f"] = {stem .. "a", "e"}
	data.forms["dat_pl_n"] = {stem .. "a", "e"}
	
	return data
end
})

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

	data.forms["acc_sg_m"] = {stem .. "a"}
	data.forms["acc_sg_f"] = {stem .. "a"}
	data.forms["acc_sg_n"] = {stem .. "e"}
	data.forms["acc_pl_m"] = {stem .. "a"}
	data.forms["acc_pl_f"] = {stem .. "a"}
	data.forms["acc_pl_n"] = {stem .. "a"}
	
	data.forms["gen_sg_m"] = {stem .. "a"}
	data.forms["gen_sg_f"] = {stem .. "a"}
	data.forms["gen_sg_n"] = {stem .. "a"}
	data.forms["gen_pl_m"] = {stem .. "ena"}
	data.forms["gen_pl_f"] = {stem .. "ena"}
	data.forms["gen_pl_n"] = {stem .. "ena"}

	data.forms["dat_sg_m"] = {stem .. "a"}
	data.forms["dat_sg_f"] = {stem .. "a"}
	data.forms["dat_sg_n"] = {stem .. "a"}
	data.forms["dat_pl_m"] = {stem .. "um", "on"}
	data.forms["dat_pl_f"] = {stem .. "um", "on"}
	data.forms["dat_pl_n"] = {stem .. "um", "on"}
	
	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("Strong and Weak 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
	-- 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" | neuter
! style="width: 33%; background-color:#FDD5B1" colspan="2" | feminine
|-
! 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
end