Module:gmh-decl-adj

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


local export = {}

local m_links = require("Module:links")
local m_utils = require("Module:utilities")
local rmatch = mw.ustring.match

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

local decl_data = {}

decl_data["adj"] = {
	params = {
		[1] = {},
		[2] = {},
		["alt1"] = {},
		["alt2"] = {},
		["comp"] = {},
		["sup"] = {},
		["sup2"] = {},
		["umlaut"] = {},
		["lr"] = {}
	},
}
setmetatable(decl_data["adj"], {__call = function(self, args, data)
	data.decl_type = "masculine, a-stem"
	
	local a1 = args.alt1 or args[1]
	local a2 = args.alt2 or args[2] or a1
	local a3 = args.umlaut or a2
	comp = args.comp
	local sup = args.sup
	local sup2 = args.sup2 or sup
	
	data.forms["bare"] = {a1}
	
if args.lr == "+" then

	data.forms["snsm"] = {a2 .. "er"}
	data.forms["snsf"] = {a3 .. "iu"}
	data.forms["snsn"] = {a2 .. "ȥ", a2 .. "eȥ"}
	data.forms["sgsm"] = {a2 .. "s", a2 .. "es"}
	data.forms["sgsf"] = {a2 .. "re", a2 .. "er"}
	data.forms["sdsm"] = {a2 .. "m", a2 .. "me", a2 .. "em"}
	data.forms["sasm"] = {a2 .. "n", a2 .. "en"}
	data.forms["sasf"] = {a2, a2 .. "e"}

	data.forms["wns"] = {a2, a2 .. "e"}
	data.forms["wnp"] = {a2 .. "n", a2 .. "en"}


else

	data.forms["snsm"] = {a2 .. "er"}
	data.forms["snsf"] = {a3 .. "iu"}
	data.forms["snsn"] = {a2 .. "eȥ"}
	data.forms["sgsm"] = {a2 .. "es"}
	data.forms["sgsf"] = {a2 .. "er"}
	data.forms["sdsm"] = {a2 .. "em"}
	data.forms["sasm"] = {a2 .. "en"}
	data.forms["sasf"] = {a2 .. "e"}

	data.forms["wns"] = {a2 .. "e"}
	data.forms["wnp"] = {a2 .. "en"}

end

if comp then

	data.forms["cwns"] = {comp .. "e"}
	data.forms["cwnp"] = {comp .. "en"}

	data.forms["ssnsm"] = {sup2 .. "er"}
	data.forms["ssnsf"] = {sup2 .. "iu"}
	data.forms["ssnsn"] = {sup2 .. "eȥ"}
	data.forms["ssgsm"] = {sup2 .. "es"}
	data.forms["ssgsf"] = {sup2 .. "er"}
	data.forms["ssdsm"] = {sup2 .. "em"}
	data.forms["ssasm"] = {sup2 .. "en"}
	data.forms["ssasf"] = {sup2 .. "e"}

	data.forms["swns"] = {sup2 .. "e"}
	data.forms["swnp"] = {sup2 .. "en"}

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 decl_type = (frame.args["decl"] or parent_args["decl"]) or "a-m"

	if not decl_data[decl_type] then
		error("Unknown declension '" .. decl_type .. "'")
	end
	
	local data = {forms = {}, categories = {}}
	
	data.head = parent_args["head"] or nil

	local args = require("Module:parameters").process(parent_args, decl_data[decl_type].params, true)
	
	-- Override for templates
	if not args[1] then
		setmetatable(args, {__index = function(self, key)
			return "{{{" .. key .. "}}}"
		end
		})
	end
	
	-- Generate the forms
	if parent_args.irr then
		table.insert(data.categories, "Old High German irregular nouns")
		if decl_data.irregular[parent_args.irr] then
			decl_data.irregular[parent_args.irr](data)
		else
			decl_data[decl_type](args, data)
		end
	else
		decl_data[decl_type](args, data)
	end

	-- Make the table
	return make_table(data)
end

function make_table(data)
	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
	
	local function repl(param)
		if param == "decl_type" then
			return data.decl_type
		else
			return show_form(data.forms[param])
		end
	end

	local wikicode1 = [=[<div class="NavFrame" style="width:30em">
<div class="NavHead" style="">Positive forms of {{{bare}}}</div>
<div class="NavContent">

{| style="background:#F9F9F9;text-align:center;width:30em" class="inflection-table" border="1px solid #505050"
|-
! colspan="2" rowspan="2" style="background:#C0C0C0" |  number & gender
! colspan="3" style="background:#C0C0C0" | singular
! colspan="2" style="background:#C0C0C0" | plural
|-
! style="background:#C0C0C0" | masculine
! style="background:#C0C0C0" | feminine
! style="background:#C0C0C0" | neuter
! style="background:#C0C0C0" | nonneuter
! style="background:#C0C0C0" | neuter
|-
! rowspan="4" style="background:#c0cfe4" | strong declension
! style="background:#c0cfe4" | nominative
| {{{snsm}}}
| {{{snsf}}}
| {{{snsn}}}
| {{{sasf}}}
| {{{snsf}}}
|-
! style="background:#c0cfe4" | genitive
| {{{sgsm}}}
| {{{sgsf}}}(e)
| {{{sgsm}}}
| colspan="2" | {{{sgsf}}}(e)
|-
! style="background:#c0cfe4" | dative
| {{{sdsm}}}(e)
| {{{sgsf}}}(e)
| {{{sdsm}}}(e)
| colspan="2" | {{{sasm}}}
|-
! style="background:#c0cfe4" | accusative
| {{{sasm}}}
| {{{sasf}}}
| {{{snsn}}}
| {{{sasf}}}
| {{{snsf}}}
|-
! rowspan="4" style="background:#c0e4c0" | weak declension
! style="background:#c0e4c0" | nominative
| dër {{{wns}}}
| diu {{{wns}}}
| daȥ {{{wns}}}
| die {{{wnp}}}
| diu {{{wnp}}}
|-
! style="background:#c0e4c0" | genitive
| dës {{{wnp}}}
| dër {{{wnp}}}
| dës {{{wnp}}}
| colspan="2" | dër {{{wnp}}}
|-
! style="background:#c0e4c0" | dative
| dëm {{{wnp}}}
| dër {{{wnp}}}
| dëm {{{wnp}}}
| colspan="2" | dën {{{wnp}}}
|-
! style="background:#c0e4c0" | accusative
| dën {{{wnp}}}
| die {{{wnp}}}
| daȥ {{{wns}}}
| die {{{wnp}}}
| diu {{{wnp}}}
]=]

 local wikicode2 = [=[<div class="NavFrame" style="width:30em">
<div class="NavHead" style="">Positive forms of {{{bare}}}</div>
<div class="NavContent">

{| style="background:#F9F9F9;text-align:center;width:30em" class="inflection-table" border="1px solid #505050"
|-
! colspan="2" rowspan="2" style="background:#C0C0C0" |  number & gender
! colspan="3" style="background:#C0C0C0" | singular
! colspan="2" style="background:#C0C0C0" | plural
|-
! style="background:#C0C0C0" | masculine
! style="background:#C0C0C0" | feminine
! style="background:#C0C0C0" | neuter
! style="background:#C0C0C0" | nonneuter
! style="background:#C0C0C0" | neuter
|-
! rowspan="4" style="background:#c0cfe4" | strong declension
! style="background:#c0cfe4" | nominative
| {{{snsm}}}
| {{{snsf}}}
| {{{snsn}}}
| {{{sasf}}}
| {{{snsf}}}
|-
! style="background:#c0cfe4" | genitive
| {{{sgsm}}}
| {{{sgsf}}}(e)
| {{{sgsm}}}
| colspan="2" | {{{sgsf}}}(e)
|-
! style="background:#c0cfe4" | dative
| {{{sdsm}}}(e)
| {{{sgsf}}}(e)
| {{{sdsm}}}(e)
| colspan="2" | {{{sasm}}}
|-
! style="background:#c0cfe4" | accusative
| {{{sasm}}}
| {{{sasf}}}
| {{{snsn}}}
| {{{sasf}}}
| {{{snsf}}}
|-
! rowspan="4" style="background:#c0e4c0" | weak declension
! style="background:#c0e4c0" | nominative
| dër {{{wns}}}
| diu {{{wns}}}
| daȥ {{{wns}}}
| die {{{wnp}}}
| diu {{{wnp}}}
|-
! style="background:#c0e4c0" | genitive
| dës {{{wnp}}}
| dër {{{wnp}}}
| dës {{{wnp}}}
| colspan="2" | dër {{{wnp}}}
|-
! style="background:#c0e4c0" | dative
| dëm {{{wnp}}}
| dër {{{wnp}}}
| dëm {{{wnp}}}
| colspan="2" | dën {{{wnp}}}
|-
! style="background:#c0e4c0" | accusative
| dën {{{wnp}}}
| die {{{wnp}}}
| daȥ {{{wns}}}
| die {{{wnp}}}
| diu {{{wnp}}}
|}</div></div>

<div class="NavFrame" style="width:30em">
<div class="NavHead" style="">Comparative forms of {{{bare}}}</div>
<div class="NavContent">

{| style="background:#F9F9F9;text-align:center;width:30em" class="inflection-table" border="1px solid #505050"
|-
! colspan="2" rowspan="2" style="background:#C0C0C0" |  number & gender
! colspan="3" style="background:#C0C0C0" | singular
! colspan="2" style="background:#C0C0C0" | plural
|-
! style="background:#C0C0C0" | masculine
! style="background:#C0C0C0" | feminine
! style="background:#C0C0C0" | neuter
! style="background:#C0C0C0" | nonneuter
! style="background:#C0C0C0" | neuter
|-
! rowspan="4" style="background:#c0e4c0" | weak declension
! style="background:#c0e4c0" | nominative
| dër {{{cwns}}}
| diu {{{cwns}}}
| daȥ {{{cwns}}}
| die {{{cwnp}}}
| diu {{{cwnp}}}
|-
! style="background:#c0e4c0" | genitive
| dës {{{cwnp}}}
| dër {{{cwnp}}}
| dës {{{cwnp}}}
| colspan="2" | dër {{{cwnp}}}
|-
! style="background:#c0e4c0" | dative
| dëm {{{cwnp}}}
| dër {{{cwnp}}}
| dëm {{{cwnp}}}
| colspan="2" | dën {{{cwnp}}}
|-
! style="background:#c0e4c0" | accusative
| dën {{{cwnp}}}
| die {{{cwnp}}}
| daȥ {{{cwns}}}
| die {{{cwnp}}}
| diu {{{cwnp}}}
|}</div></div>

<div class="NavFrame" style="width:30em">
<div class="NavHead" style="">Superlative forms of {{{bare}}}</div>
<div class="NavContent">

{| style="background:#F9F9F9;text-align:center;width:30em" class="inflection-table" border="1px solid #505050"
|-
! colspan="2" rowspan="2" style="background:#C0C0C0" |  number & gender
! colspan="3" style="background:#C0C0C0" | singular
! colspan="2" style="background:#C0C0C0" | plural
|-
! style="background:#C0C0C0" | masculine
! style="background:#C0C0C0" | feminine
! style="background:#C0C0C0" | neuter
! style="background:#C0C0C0" | nonneuter
! style="background:#C0C0C0" | neuter
|-
! rowspan="4" style="background:#c0cfe4" | strong declension
! style="background:#c0cfe4" | nominative
| {{{ssnsm}}}
| {{{ssnsf}}}
| {{{ssnsn}}}
| {{{ssasf}}}
| {{{ssnsf}}}
|-
! style="background:#c0cfe4" | genitive
| {{{ssgsm}}}
| {{{ssgsf}}}(e)
| {{{ssgsm}}}
| colspan="2" | {{{ssgsf}}}(e)
|-
! style="background:#c0cfe4" | dative
| {{{ssdsm}}}(e)
| {{{ssgsf}}}(e)
| {{{ssdsm}}}(e)
| colspan="2" | {{{ssasm}}}
|-
! style="background:#c0cfe4" | accusative
| {{{ssasm}}}
| {{{ssasf}}}
| {{{ssnsn}}}
| {{{ssasf}}}
| {{{ssnsf}}}
|-
! rowspan="4" style="background:#c0e4c0" | weak declension
! style="background:#c0e4c0" | nominative
| dër {{{swns}}}
| diu {{{swns}}}
| daȥ {{{swns}}}
| die {{{swnp}}}
| diu {{{swnp}}}
|-
! style="background:#c0e4c0" | genitive
| dës {{{swnp}}}
| dër {{{swnp}}}
| dës {{{swnp}}}
| colspan="2" | dër {{{swnp}}}
|-
! style="background:#c0e4c0" | dative
| dëm {{{swnp}}}
| dër {{{swnp}}}
| dëm {{{swnp}}}
| colspan="2" | dën {{{swnp}}}
|-
! style="background:#c0e4c0" | accusative
| dën {{{swnp}}}
| die {{{swnp}}}
| daȥ {{{swns}}}
| die {{{swnp}}}
| diu {{{swnp}}}
]=]

if comp then
	wikicode = wikicode2 .. "|}</div></div>"
else
	wikicode = wikicode1 .. "|}</div></div>"
end

	return (mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. m_utils.format_categories(data.categories, lang)
end

return export