Pergi ke kandungan

Modul:nl-adjective

Daripada Wikikamus


--[=[
	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 m_links = require("Module:links")
local m_scriptutils = require("Module:script utilities")

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

local export = {}

-- Functions that do the actual inflecting by creating the forms of a basic term.
local inflections = {}

-- 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"] or "adjektif"
	local args = frame:getParent().args
	
	if not inflections[word_type] then
		error("Jenis '" .. infl_type .. "' nada suara tidak diketahui")
	end
	
	local data = {forms = {}, comparable = true}

	-- Generate the forms
	inflections[word_type](args, data)
	
	return make_table(data)
end

inflections["adjective"] = function(args, data, word_type)
	-- Get parameters
	local pred_pos = args["pred"]; if pred_pos == "" then pred_pos = nil end
	local infl_pos = args[1]; if infl_pos == "" then infl_pos = nil end
	local part_pos = args["part"]; if part_pos == "" then part_pos = nil end
	local comp = args[2]; if comp == "" then comp = nil end
	local sup = args[3]; if sup == "" then sup = nil end
	
	if comp == "-" then
		data.comparable = false
	end
	
	local base = (NAMESPACE == "Templat" and "-" or PAGENAME)

	-- Positive degree
	if pred_pos == "-" then pred_pos = nil else pred_pos = pred_pos or base end
	infl_pos = infl_pos or export.make_inflected(base)
	if part_pos == "-" then part_pos = nil else part_pos = part_pos or export.make_partitive(base) end
	
	data.forms["pred_pos"] = {pred_pos}
	data.forms["mfsg_pos"] = {infl_pos}
	data.forms["nsg_pos"] = {base}
	data.forms["pl_pos"] = {infl_pos}
	data.forms["def_pos"] = {infl_pos}
	data.forms["part_pos"] = {part_pos}
	
	-- Participles never have comparative and superlative forms.
	-- If they do, then they're probably really adjectives.
	if data.comparable then
		-- Comparative degree
		comp = comp or export.make_comparative(base, infl_pos)
		local infl_comp = export.make_inflected(comp); if base:find("[^eio]en$") or base:find("[aeou]ien$") then infl_comp = comp end
		local part_comp = export.make_partitive(comp)
		
		data.forms["pred_comp"] = {comp}
		data.forms["mfsg_comp"] = {infl_comp}
		data.forms["nsg_comp"] = {comp}
		data.forms["pl_comp"] = {infl_comp}
		data.forms["def_comp"] = {infl_comp}
		data.forms["part_comp"] = {part_comp}
		
		-- Superlative degree
		sup = sup or export.make_superlative(base, part_pos)
		local infl_sup = export.make_inflected(sup)
		
		data.forms["pred_sup"] = {"het [[" .. sup .. "]]", "het [[" .. infl_sup .. "]]"}
		data.forms["mfsg_sup"] = {infl_sup}
		data.forms["nsg_sup"] = {infl_sup}
		data.forms["pl_sup"] = {infl_sup}
		data.forms["def_sup"] = {infl_sup}
		data.forms["part_sup"] = nil
	end
end

inflections["pres-ptc"] = function(args, data)
	data.comparable = false
	inflections["adjective"](args, data)
	
	-- The predicative form of the present participle can have -e too,
	-- in sentences like "Hij is stervende".
	table.insert(data.forms["pred_pos"], data.forms["mfsg_pos"][1])
end

inflections["past-ptc"] = function(args, data)
	data.comparable = false
	inflections["adjective, adjektif"](args, data)
end

inflections["irregular, tidak teratur"] = function(args, data)
	local base = args[1]; if base == "" then base = nil end
	base = base or (NAMESPACE == "Templat" and "veel" or PAGENAME)
	
	if base == "veel" then
		data.forms["pred_pos"] = {"veel"}
		data.forms["mfsg_pos"] = {"veel"}
		data.forms["nsg_pos"] = {"veel"}
		data.forms["pl_pos"] = {"veel"}
		data.forms["def_pos"] = {"vele"}
		data.forms["part_pos"] = nil
		
		data.forms["pred_comp"] = {"meer"}
		data.forms["mfsg_comp"] = {"meer"}
		data.forms["nsg_comp"] = {"meer"}
		data.forms["pl_comp"] = {"meer"}
		data.forms["def_comp"] = nil
		data.forms["part_comp"] = nil
		
		data.forms["pred_sup"] = {"het [[meest]]", "het [[meeste]]"}
		data.forms["mfsg_sup"] = nil
		data.forms["nsg_sup"] = nil
		data.forms["pl_sup"] = nil
		data.forms["def_sup"] = {"meeste"}
		data.forms["part_sup"] = nil
	elseif base == "weinig" then
		data.forms["pred_pos"] = {"weinig"}
		data.forms["mfsg_pos"] = {"weinig"}
		data.forms["nsg_pos"] = {"weinig"}
		data.forms["pl_pos"] = {"weinig"}
		data.forms["def_pos"] = {"weinige"}
		data.forms["part_pos"] = nil
		
		data.forms["pred_comp"] = {"minder"}
		data.forms["mfsg_comp"] = {"minder"}
		data.forms["nsg_comp"] = {"minder"}
		data.forms["pl_comp"] = {"minder"}
		data.forms["def_comp"] = nil
		data.forms["part_comp"] = nil
		
		data.forms["pred_sup"] = {"het [[minst]]", "het [[minste]]"}
		data.forms["mfsg_sup"] = {"minste"}
		data.forms["nsg_sup"] = {"minste"}
		data.forms["pl_sup"] = {"minste"}
		data.forms["def_sup"] = {"minste"}
		data.forms["part_sup"] = nil
	else
		error("Tiada konjugasi tidak teratur dikenali dengan perkataan ini. Sila tambah kepada [[Module:nl-adjective]].")
	end
end

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

function export.make_inflected(base)
	-- Adjectives ending in unstressed -en or -e get no extra -e.
	if 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)
	-- Adjectives ending in a sibilant do not get an extra -s
	if 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)
	if not inflected then
		inflected = export.make_inflected(base)
	end
	
	-- Adjectives ending in -r get an extra -d- in the comparative,
	-- disregarding the inflected form
	if 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)
	if not partitive then
		partitive = export.make_partitive(base)
	end
	
	-- Adjectives in -ide have a superlative -iedst
	if base:find("[iï]de$") then
		return base:gsub("([iï])de$", "%1ed") .. "st"
	elseif partitive then
		return partitive .. "t"
	else
		return base .. "st"
	end
end

function show_form(form)
	if not form then
		return "—"
	elseif type(form) ~= "table" then
		error("nilai yang bukan jadual telah diberikan di dalam senarai borang difleksi.")
	elseif #form == 0 then
		return "—"
	end
	
	local ret = {}
	
	for key, subform in ipairs(form) do
		table.insert(ret, m_links.full_link(subform, nil, lang, nil, nil, nil, {}, false))
	end
	
	return table.concat(ret, "<br/>")
end

-- Make the table
function make_table(data)
	return [=[
<div class="NavFrame" style="width: ]=] .. (data.comparable and 60 or 30) .. [=[em;">
<div class="NavHead" style="background: #CCCCFF; text-align: left;">Declension of ]=] .. m_links.full_link(nil, PAGENAME, lang, nil, "term", nil, {}, false) .. [=[</div>
<div class="NavContent">
{| class="inflection-table" style="width:100%; text-align:center; line-height:125%;" cellspacing="1" cellpadding="3"
|- style="background: #CCCCFF;"]=] .. (data.comparable and [=[

| colspan="2" style="background: #E6E6FF; width: 25%;" |
! style="width: 25%;" | [[darjah positif|positif]]
! style="width: 25%;" | [[darjah perbandingan|perbandingan]]
! style="width: 25%;" | [[darjah superlatif|superlatif]]]=] or [=[

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

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | [[predikat]]/[[adverbaan]]
| ]=] .. show_form(data.forms["pred_pos"]) .. (data.comparable and " || " .. show_form(data.forms["pred_comp"]) .. " || " .. show_form(data.forms["pred_sup"]) or "") .. [=[

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" rowspan="3" | kata [[tak pasti]]
! style="background: #CCCCFF;" | [[maskulin|m.]]/[[feminin|f.]]&nbsp;[[singular|sing.]]
| ]=] .. show_form(data.forms["mfsg_pos"]) .. (data.comparable and " || " .. show_form(data.forms["mfsg_comp"]) .. " || " .. show_form(data.forms["mfsg_sup"]) or "") .. [=[

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" | [[neuter|n.]]&nbsp;[[singular|sing.]]
| ]=] .. show_form(data.forms["nsg_pos"]) .. (data.comparable and " || " .. show_form(data.forms["nsg_comp"]) .. " || " .. show_form(data.forms["nsg_sup"]) or "") .. [=[

|- style="background: #F2F2FF;"
! style="background:#CCCCFF;" | kata [[jamak]]
| ]=] .. show_form(data.forms["pl_pos"]) .. (data.comparable and " || " .. show_form(data.forms["pl_comp"]) .. " || " .. show_form(data.forms["pl_sup"]) or "") .. [=[

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | kata [[kata tentu|tentu]]
| ]=] .. show_form(data.forms["def_pos"]) .. (data.comparable and " || " .. show_form(data.forms["def_comp"]) .. " || " .. show_form(data.forms["def_sup"]) or "") .. [=[

|- style="background: #F2F2FF;"
! style="background: #CCCCFF;" colspan="2" | kata [[partitif]]
| ]=] .. show_form(data.forms["part_pos"]) .. (data.comparable and " || " .. show_form(data.forms["part_comp"]) .. " || " .. show_form(data.forms["part_sup"]) or "") .. [=[

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

return export