Module:fy-adjectives

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

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

local export = {}

function export.adjective(frame)
	local params = {
		[1] = {},
		[2] = {},
		[3] = {},
		["pred"] = {},
		["part"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local make_auto_subtabler = require("Module:auto-subtable")
	local data = {forms = make_auto_subtabler(), categories = {}, comparable = true}
	
	-- Get parameters
	local pred = args["pred"]
	local infl = args[1]
	local part = args["part"]
	
	if args[2] == "-" then
		data.comparable = false
	end
	
	local base = mw.title.getCurrentTitle().nsText == "Template" and "-" or mw.title.getCurrentTitle().text
	
	-- Positive degree
	if pred == "-" then
		pred = nil
	elseif not pred then
		pred = base
	end
	
	if not infl then
		infl = base .. "e"
	end
	
	if part == "-" then
		part = nil
	elseif not part then
		if base:find("s$") then
			part = base
		else
			part = base .. "s"
		end
	end
	
	data.forms["pred"] = {pred}
	data.forms["indef|c|s"] = {infl}
	data.forms["indef|n|s"] = {base}
	data.forms["indef|p"] = {infl}
	data.forms["def"] = {infl}
	data.forms["par"] = {part}
	
	if data.comparable then
		-- Comparative degree
		local comd_base = {args[2]}
		
		if not comd_base[1] then
			-- Adjectives ending in -r get an extra -d- in the comparative,
			-- disregarding the inflected form.
			if base:find("r$") then
				comd_base = {base .. "der"}
			-- Adjectives ending in -l or -n also get an extra -d-,
			-- but it's optional alongside the form without it.
			elseif base:find("[ln]$") then
				comd_base = {base .. "der", infl .. "r"}
			else
				comd_base = {infl .. "r"}
			end
		end
		
		for _, form in ipairs(comd_base) do
			table.insert(data.forms["pred|comd"], form)
			table.insert(data.forms["indef|n|s|comd"], form)
			table.insert(data.forms["indef|c|s|comd"], form .. "e")
			table.insert(data.forms["indef|p|comd"], form .. "e")
			table.insert(data.forms["def|comd"], form .. "e")
			table.insert(data.forms["par|comd"], form .. "s")
		end
		
		-- Superlative degree
		local supd_base = {args[3]}
		
		if not supd_base[1] then
			if base:find("st$") then
				supd_base = {base}
			else
				supd_base = {part .. "t"}
			end
		end
		
		for _, form in ipairs(supd_base) do
			table.insert(data.forms["pred|supd"], "it [[" .. form .. "]]")
			table.insert(data.forms["pred|supd"], "it [[" .. form .. "e]]")
			table.insert(data.forms["indef|c|s|supd"], form .. "e")
			table.insert(data.forms["indef|n|s|supd"], form .. "e")
			table.insert(data.forms["indef|p|supd"], form .. "e")
			table.insert(data.forms["def|supd"], form .. "e")
		end
	end
	
	-- Remove metatable.
	data.forms:un_auto_subtable()
	
	return make_table(data)
end

-- Make the table
function make_table(data)
	local function repl(param)
		local accel = true
		local no_store = false
		
		if param == "lemma" then
			return require("Module:links").full_link({lang = lang, alt = mw.title.getCurrentTitle().text}, "term")
		elseif param == "info" then
			return data.title and " (" .. data.title .. ")" or ""
		elseif string.sub(param, 1, 1) == "!" then
			no_store = true
			param = string.sub(param, 2)
		elseif string.sub(param, 1, 1) == "#" then
			accel = false
			param = string.sub(param, 2)
		end
		
		local forms = data.forms[param]
		
		if not forms then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(forms) do
			table.insert(ret, require("Module:links").full_link({lang = lang, term = subform, accel = accel and {form = param, lemma = data.lemma, no_store = no_store} or nil}))
		end
		
		return table.concat(ret, "<br/>")
	end
	
	local wikicode = [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="border: 1px solid #CCCCFF;" cellspacing="1" cellpadding="3"
|- style="background: #CCCCFF;"
! colspan="5" class="vsToggleElement" style="text-align: left" | Inflection of {{{lemma}}}{{{info}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | uninflected
| style="min-width: 12em;" | {{{!indef|n|s}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | inflected
| {{{!indef|c|s}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | comparative
| {{{!indef|n|s|comd}}}
|- class="vsHide" style="background: #CCCCFF;"
| colspan="2" style="background: #E6E6FF;" |
! style="min-width: 12em;" | [[positive degree|positive]]]=] .. (data.comparable and [=[

! style="min-width: 12em;" | [[comparative degree|comparative]]
! style="min-width: 12em;" | [[superlative degree|superlative]]]=] or "") .. [=[

|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | [[predicative]]/[[adverbial]]
| {{{pred}}}]=] .. (data.comparable and " || {{{pred|comd}}} || {{{pred|supd}}}" or "") .. [=[

|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" rowspan="3" | [[indefinite]]
! style="background: #CCCCFF;" | [[common|c.]]&nbsp;[[singular|sing.]]
| {{{indef|c|s}}}]=] .. (data.comparable and " || {{{indef|c|s|comd}}} || {{{indef|c|s|supd}}}" or "") .. [=[

|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[neuter|n.]]&nbsp;[[singular|sing.]]
| {{{indef|n|s}}}]=] .. (data.comparable and " || {{{indef|n|s|comd}}} || {{{indef|n|s|supd}}}" or "") .. [=[

|- class="vsHide" style="background: #F2F2FF;"
! style="background:#CCCCFF;" | [[plural]]
| {{{indef|p}}}]=] .. (data.comparable and " || {{{indef|p|comd}}} || {{{indef|p|supd}}}" or "") .. [=[

|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | [[definite]]
| {{{def}}}]=] .. (data.comparable and " || {{{def|comd}}} || {{{def|supd}}}" or "") .. [=[

|- class="vsHide" style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | [[partitive]]
| {{{par}}}]=] .. (data.comparable and " || {{{par|comd}}} || {{{par|supd}}}" or "") .. [=[

|}]=]
	
	return mw.ustring.gsub(wikicode, "{{{([#!]?[a-z0-9|]+)}}}", repl) .. require("Module:utilities").format_categories(data.categories, lang)
end

return export