Module:Nl-adjective

--[=[
	This module contains functions for creating inflection tables for Dutch
	adjectives.
	
	Notice:
	The bot [[User:MewBot]] uses this module to automatically create entries
	for adjective forms. If you change how this module works, please notify
	the bot owner so the bot can be updated!
]=]--

local export = {}

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	PAGENAME = mw.title.getCurrentTitle().text
	NAMESPACE = mw.title.getCurrentTitle().nsText
	local word_type = frame.args["word_type"]
	local args = frame:getParent().args
	
	local forms = {}
	
	local inflected = export.make_inflected(PAGENAME, args[1])
	local partitive = export.make_partitive(PAGENAME, args["part"])
	local predicative = args["pred"] or PAGENAME; if predicative == "-" then predicative = nil end
	
	local comparative = export.make_comparative(PAGENAME, inflected, args[2])
	
	-- Positive degree
	-- The predicative form of the present participle can have -e too,
	-- in sentences like "Hij is stervende".
	if word_type == "pres-ptc" then
		forms["pred_pos"] = {predicative, inflected}
	else
		forms["pred_pos"] = predicative
	end
	
	forms["mfsg_pos"] = inflected
	forms["nsg_ind_pos"] = PAGENAME
	forms["nsg_def_pos"] = inflected
	forms["plur_pos"] = inflected
	forms["part_pos"] = partitive
	
	-- Participles never have comparative and superlative forms.
	-- If they do, then they're probably really adjectives.
	if comparative and word_type ~= "pres-ptc" and word_type ~= "past-ptc" then
		local inflected_comp = comparative .. "e"; if PAGENAME:find("[^eio]en$") or PAGENAME:find("[aeou]ien$") then inflected_comp = comparative end
		local superlative = export.make_superlative(PAGENAME, partitive, args[3])
		
		-- Comparative degree
		forms["pred_comp"] = comparative
		forms["mfsg_comp"] = inflected_comp
		forms["nsg_ind_comp"] = comparative
		forms["nsg_def_comp"] = inflected_comp
		forms["plur_comp"] = inflected_comp
		forms["part_comp"] = comparative .. "s"
		
		-- Superlative degree
		forms["mfsg_att_sup"] = superlative .. "e"
		forms["nsg_def_att_sup"] = superlative .. "e"
		forms["plur_att_sup"] = superlative .. "e"
		forms["mfsg_pred_sup"] = superlative .. "e"
		forms["nsg_def_pred_sup"] = {superlative, superlative .. "e"}
		forms["plur_pred_sup"] = superlative .. "e"
	end
	
	return make_table(forms)
end

-- Four functions to create various forms.
-- These are exported, because Module:nl-head also uses them to create
-- comparative and superlative forms.

function export.make_inflected(base, inflected)
	if (inflected or "") ~= "" then
		return inflected
	-- Adjectives ending in unstressed -en or -e get no extra -e.
	elseif base:find("[^eio]en$") or base:find("[aeou]ien$") or base:find("[^eio]e$") then
		return base
	-- Adjectives ending in certain digraphs get a diaeresis
	elseif base:find("[eio]e$") then
		return base .. "ë"
	else
		return base .. "e"
	end
end

function export.make_partitive(base, partitive)
	if partitive == "-" then
		return nil
	elseif (partitive or "") ~= "" then
		return partitive
	-- Adjectives ending in a sibilant do not get an extra -s
	elseif base:find("s$") or base:find("sch$") or base:find("x$") or base:find("sj$") or base:find("sh$") then
		return base
	-- Adjectives ending in a long vowel get an apostrophe before the -s
	elseif base:find("[^aeiou][aiouy]$") then
		return base .. "'s"
	else
		return base .. "s"
	end
end

function export.make_comparative(base, inflected, comparative)
	if comparative == "-" then
		return nil
	elseif (comparative or "") ~= "" then
		return comparative
	-- Adjectives ending in -r get an extra -d- in the comparative,
	-- disregarding the inflected form
	elseif base:find("r$") then
		return base .. "der"
	-- If the inflected form does not end in -e, add it
	elseif not inflected:find("[eë]$") then
		return inflected .. "er"
	else
		return inflected .. "r"
	end
end

function export.make_superlative(base, partitive, superlative)
	if (superlative or "") ~= "" then
		return superlative
	-- Adjectives in -ide have a superlative -iedst
	elseif base:find("[iï]de$") then
		return base:gsub("([iï])de$", "%1ed") .. "st"
	elseif partitive then
		return partitive .. "t"
	else
		return base .. "st"
	end
end

-- Make the table
function make_table(forms)
	local m_links = require("Module:links")
	local m_scriptutils = require("Module:script utilities")
	
	-- Make links out of all forms
	for key, form in pairs(forms) do
		if type(form) == "table" then
			for key2, subform in ipairs(form) do
				form[key2] = m_scriptutils.tag_text(m_links.language_link(subform, nil, "nl", nil, PAGENAME), "nl", "Latn", nil)
			end
			
			forms[key] = table.concat(form, ",<br/>")
		else
			forms[key] = m_scriptutils.tag_text(m_links.language_link(form, nil, "nl", nil, PAGENAME), "nl", "Latn", nil)
		end
	end
	
	local comparable =
		forms["pred_comp"] or forms["mfsg_comp"] or forms["nsg_ind_comp"] or forms["nsg_def_comp"] or forms["plur_comp"] or forms["part_comp"] or
		forms["mfsg_att_sup"] or forms["nsg_def_att_sup"] or forms["plur_att_sup"] or forms["mfsg_pred_sup"] or forms["nsg_def_pred_sup"] or forms["plur_pred_sup"]
	
	return [=[
<div class="NavFrame" style="width: ]=] .. (comparable and 75 or 30) .. [=[em;">
<div class="NavHead" style="background: #CCCCFF; text-align: left;">Declension of '']=] .. PAGENAME .. [=[''</div>
<div class="NavContent">
{| style="width:100%; border:1px solid #CCCCFF; text-align:center; line-height:125%" class="inflection-table" cellspacing="1" cellpadding="3"
|- style="background: #CCCCFF;"]=] .. (comparable and [=[

| rowspan="2" colspan="2" style="background: #E6E6FF; width: 20%;" |
! rowspan="2" style="width: 20%;" | [[positive degree|positive]]
! rowspan="2" style="width: 20%;" | [[comparative degree|comparative]]
! colspan="2" | [[superlative degree|superlative]]
|- style="background: #CCCCFF;"
! style="width: 20%;" | [[attributive]]
! style="width: 20%;" | [[predicative]]/[[adverbial]]]=] or [=[

| colspan="2" style="background: #E6E6FF; width: 50%;" |
! style="width: 50%;" | [[positive degree|positive]]]=]) .. [=[

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | [[predicative]]/[[adverbial]]
| ]=] .. (forms["pred_pos"] or "&mdash;") .. (comparable and " || " .. (forms["pred_comp"] or "&mdash;") .. [=[ || style="background: #E6E6FF;" colspan="2" rowspan="2" |]=] or "") .. [=[

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" rowspan="2" | [[neuter]]<br/>[[singular]]
! style="background: #CCCCFF;" | [[indefinite]]
| ]=] .. (forms["nsg_ind_pos"] or "&mdash;") .. (comparable and " || " .. (forms["nsg_ind_comp"] or "&mdash;") or "") .. [=[

|- style="background: #F2F2FF;"
! style="background:#CCCCFF;" | [[definite]]
| ]=] .. (forms["nsg_def_pos"] or "&mdash;") .. (comparable and " || " .. (forms["nsg_def_comp"] or "&mdash;") .. " || " .. (forms["nsg_def_att_sup"] or "&mdash;") .. " || " .. (forms["nsg_def_pred_sup"] or "&mdash;") or "") .. [=[

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | [[common]] [[singular]]
| ]=] .. (forms["mfsg_pos"] or "&mdash;") .. (comparable and " || " .. (forms["mfsg_comp"] or "&mdash;") .. " || " .. (forms["mfsg_att_sup"] or "&mdash;") .. " || " .. (forms["mfsg_pred_sup"] or "&mdash;") or "") .. [=[

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | [[plural]]
| ]=] .. (forms["plur_pos"] or "&mdash;") .. (comparable and " || " .. (forms["plur_comp"] or "&mdash;") .. " || " .. (forms["plur_att_sup"] or "&mdash;") .. " || " .. (forms["plur_pred_sup"] or "&mdash;") or "") .. [=[

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | [[partitive]]
| ]=] .. (forms["part_pos"] or "&mdash;") .. (comparable and " || " .. (forms["part_comp"] or "&mdash;") .. [=[

| style="background: #E6E6FF;" colspan="2" |]=] or "") .. [=[

|}</div></div>]=]
end

return export