模組:Tr-nouns

維基詞典,自由的多語言詞典


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

local export = {}


local vowels = {
	["a"] = {high = "ı", low = "a"}, ["â"] = {high = "ı", low = "a"},
	["e"] = {high = "i", low = "e"},
	["ı"] = {high = "ı", low = "a"},
	["i"] = {high = "i", low = "e"}, ["î"] = {high = "i", low = "e"},
	["o"] = {high = "u", low = "a"},
	["ö"] = {high = "ü", low = "e"},
	["u"] = {high = "u", low = "a"}, ["û"] = {high = "u", low = "a"},
	["ü"] = {high = "ü", low = "e"},
}


-- Inflection functions

function export.vowel(frame)
	local params = {
		[1] = {required = true, default = "u"},
		
		["n"] = {},
		["poss"] = {type = "boolean"},
		["pred"] = {type = "boolean"},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {forms = {}, info = "變格", categories = {}}
	local stem = mw.title.getCurrentTitle().text
	local vowel = vowels[args[1]]
	local plvowel = vowels[vowel.low]
	
	local plstem
	if args["n"] == "p" then
		plstem = stem
	else
		plstem = stem .. "l" .. vowel.low .. "r"
	end
	
	if mw.ustring.match(stem, "([aâeıiîoöuûü])$") ~= args[1] then
		require("Module:debug").track("tr-nouns/vowel")
	end
	
	data.forms["nom|s"]     = {stem}
	data.forms["def|acc|s"] = {stem .. "y" .. vowel.high}
	data.forms["dat|s"]     = {stem .. "y" .. vowel.low}
	data.forms["loc|s"]     = {stem .. "d" .. vowel.low}
	data.forms["abl|s"]     = {stem .. "d" .. vowel.low .. "n"}
	data.forms["gen|s"]     = {stem .. "n" .. vowel.high .. "n"}
	
	data.forms["nom|p"]     = {plstem}
	data.forms["def|acc|p"] = {plstem .. plvowel.high}
	data.forms["dat|p"]     = {plstem .. plvowel.low}
	data.forms["loc|p"]     = {plstem .. "d" .. plvowel.low}
	data.forms["abl|p"]     = {plstem .. "d" .. plvowel.low .. "n"}
	data.forms["gen|p"]     = {plstem .. plvowel.high .. "n"}
	
	if args["poss"] then
		data.forms["1|s|poss|of the|s"] = {stem .. "m"}
		data.forms["2|s|poss|of the|s"] = {stem .. "n"}
		data.forms["3|s|poss|of the|s"] = {stem .. "s" .. vowel.high}
		data.forms["1|p|poss|of the|s"] = {stem .. "m" .. vowel.high .. "z"}
		data.forms["2|p|poss|of the|s"] = {stem .. "n" .. vowel.high .. "z"}
		data.forms["3|p|poss|of the|s"] = {plstem .. plvowel.high}
		
		data.forms["1|s|poss|of the|p"] = {plstem .. plvowel.high .. "m"}
		data.forms["2|s|poss|of the|p"] = {plstem .. plvowel.high .. "n"}
		data.forms["3|s|poss|of the|p"] = {plstem .. plvowel.high}
		data.forms["1|p|poss|of the|p"] = {plstem .. plvowel.high .. "m" .. plvowel.high .. "z"}
		data.forms["2|p|poss|of the|p"] = {plstem .. plvowel.high .. "n" .. plvowel.high .. "z"}
		data.forms["3|p|poss|of the|p"] = {plstem .. plvowel.high}
	end
	
	if args["pred"] then
		data.forms["1|s|pred|of the|s"] = {stem .. "y" .. vowel.high .. "m"}
		data.forms["2|s|pred|of the|s"] = {stem .. "s" .. vowel.high .. "n"}
		data.forms["3|s|pred|of the|s"] = {stem, stem .. "d" .. vowel.high .. "r"}
		data.forms["1|p|pred|of the|s"] = {stem .. "y" .. vowel.high .. "z"}
		data.forms["2|p|pred|of the|s"] = {stem .. "s" .. vowel.high .. "n" .. vowel.high .. "z"}
		data.forms["3|p|pred|of the|s"] = {plstem}
		
		data.forms["1|s|pred|of the|p"] = {plstem .. plvowel.high .. "m"}
		data.forms["2|s|pred|of the|p"] = {plstem .. "s" .. plvowel.high .. "n"}
		data.forms["3|s|pred|of the|p"] = {plstem, plstem .. "d" .. plvowel.high .. "r"}
		data.forms["1|p|pred|of the|p"] = {plstem .. plvowel.high .. "z"}
		data.forms["2|p|pred|of the|p"] = {plstem .. "s" .. plvowel.high .. "n" .. plvowel.high .. "z"}
		data.forms["3|p|pred|of the|p"] = {plstem .. "d" .. plvowel.high .. "r"}
	end
	
	postprocess(args, data)
	
	return make_table(data)
end


function export.cons(frame)
	local params = {
		[1] = {required = true, default = "u"},
		
		["n"] = {},
		["poss"] = {type = "boolean"},
		["pred"] = {type = "boolean"},
		["stem"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {forms = {}, info = "變格", categories = {}}
	
	local stem = mw.title.getCurrentTitle().text
	local stem2 = args["stem"] or stem
	local vowel = vowels[args[1]]
	local plvowel = vowels[vowel.low]
	local plstem
	if args["n"] == "p" then
		plstem = stem
	else
		plstem = stem .. "l" .. vowel.low .. "r"
	end
	
	if mw.ustring.match(stem, "([aâeıiîoöuûü])[^aâeıiîoöuûü]+$") ~= args[1] then
		require("Module:debug").track("tr-nouns/vowel")
	end
	
	local dt = "d"
	
	if mw.ustring.find(stem, "[çfhkptsş]$") then
		dt = "t"
	end
	
	
	data.forms["nom|s"]     = {stem}
	data.forms["def|acc|s"] = {stem2 .. vowel.high}
	data.forms["dat|s"]     = {stem2 .. vowel.low}
	data.forms["loc|s"]     = {stem .. dt .. vowel.low}
	data.forms["abl|s"]     = {stem .. dt .. vowel.low .. "n"}
	data.forms["gen|s"]     = {stem2 .. vowel.high .. "n"}
	
	data.forms["nom|p"]     = {plstem}
	data.forms["def|acc|p"] = {plstem .. plvowel.high}
	data.forms["dat|p"]     = {plstem .. plvowel.low}
	data.forms["loc|p"]     = {plstem .. "d" .. plvowel.low}
	data.forms["abl|p"]     = {plstem .. "d" .. plvowel.low .. "n"}
	data.forms["gen|p"]     = {plstem .. plvowel.high .. "n"}
	
	if args["poss"] then
		data.forms["1|s|poss|of the|s"] = {stem2 .. vowel.high .. "m"}
		data.forms["2|s|poss|of the|s"] = {stem2 .. vowel.high .. "n"}
		data.forms["3|s|poss|of the|s"] = {stem2 .. vowel.high}
		data.forms["1|p|poss|of the|s"] = {stem2 .. vowel.high .. "m" .. vowel.high .. "z"}
		data.forms["2|p|poss|of the|s"] = {stem2 .. vowel.high .. "n" .. vowel.high .. "z"}
		data.forms["3|p|poss|of the|s"] = {plstem .. plvowel.high}
		
		data.forms["1|s|poss|of the|p"] = {plstem .. plvowel.high .. "m"}
		data.forms["2|s|poss|of the|p"] = {plstem .. plvowel.high .. "n"}
		data.forms["3|s|poss|of the|p"] = {plstem .. plvowel.high}
		data.forms["1|p|poss|of the|p"] = {plstem .. plvowel.high .. "m" .. plvowel.high .. "z"}
		data.forms["2|p|poss|of the|p"] = {plstem .. plvowel.high .. "n" .. plvowel.high .. "z"}
		data.forms["3|p|poss|of the|p"] = {plstem .. plvowel.high}
	end
	
	if args["pred"] then
		data.forms["1|s|pred|of the|s"] = {stem2 .. vowel.high .. "m"}
		data.forms["2|s|pred|of the|s"] = {stem .. "s" .. vowel.high .. "n"}
		data.forms["3|s|pred|of the|s"] = {stem, stem .. dt .. vowel.high .. "r"}
		data.forms["1|p|pred|of the|s"] = {stem2 .. vowel.high .. "z"}
		data.forms["2|p|pred|of the|s"] = {stem .. "s" .. vowel.high .. "n" .. vowel.high .. "z"}
		data.forms["3|p|pred|of the|s"] = {plstem}
		
		data.forms["1|s|pred|of the|p"] = {plstem .. plvowel.high .. "m"}
		data.forms["2|s|pred|of the|p"] = {plstem .. "s" .. plvowel.high .. "n"}
		data.forms["3|s|pred|of the|p"] = {plstem, plstem .. "d" .. plvowel.high .. "r"}
		data.forms["1|p|pred|of the|p"] = {plstem .. plvowel.high .. "z"}
		data.forms["2|p|pred|of the|p"] = {plstem .. "s" .. plvowel.high .. "n" .. plvowel.high .. "z"}
		data.forms["3|p|pred|of the|p"] = {plstem .. "d" .. plvowel.high .. "r"}
	end
	
	postprocess(args, data)
	
	return make_table(data)
end


function postprocess(args, data)
	data.has_poss = args["poss"]
	data.has_pred = args["pred"]
	data.n = args["n"]
	
	if args["n"] == "p" then
		table.insert(data.categories, lang:getCanonicalName() .. "唯複名詞")
	elseif args["n"] == "s" then
		table.insert(data.categories, lang:getCanonicalName() .. "不可數名詞")
	elseif args["n"] then
		error("args= must be \"s\" or \"p\".")
	end
	
	for key, form in pairs(data.forms) do
		-- Do not show singular or plural forms for nominals that don't have them
		if (args["n"] == "p" and key:find("|s$")) or (args["n"] == "s" and key:find("|p$")) then
			form = nil
		end
		
		data.forms[key] = form
	end
	
	data.lemma = (data.forms["nom|" .. (data.n or "s")])[1]
	
	-- Check if the lemma form matches the page name
	if lang:makeEntryName(data.lemma) ~= mw.title.getCurrentTitle().text then
		table.insert(data.categories, lang:getCanonicalName() .. " entries with inflection not matching pagename")
	end
end


-- Make the table
function make_table(data)
	local function repl(param)
		local accel = true
		local no_store = false
		
		if param == "info" then
			return mw.getContentLanguage():ucfirst(data.info 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 = {}
	table.insert(wikicode, [=[
{| class="inflection-table vsSwitcher vsToggleCategory-inflection" style="text-align: left; background: #F9F9F9; border: 1px solid #AAAAAA;"
|- style="background: #DEDEDE; text-align: left;"
! class="vsToggleElement" colspan="3" | {{{info}}}
|- class="vsShow"
! style="background: #EFEFEF; width: 12em;" | 主格
| colspan="2" style="width: 10em;" | {{{nom|]=] .. (data.n or "s") .. [=[}}}
|- class="vsShow"
! style="background: #EFEFEF;" | 定賓格
| colspan="2" | {{{def|acc|]=] .. (data.n or "s") .. [=[}}}
|- class="vsHide" style="background: #DEDEDE;"
! style="width: 12em;" |
! style="width: 10em;" | 單數
! style="width: 10em;" | 複數
|- class="vsHide"
! style="background: #EFEFEF;" | 主格
| {{{nom|s}}}
| {{{nom|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 定賓格
| {{{def|acc|s}}}
| {{{def|acc|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 與格
| {{{dat|s}}}
| {{{dat|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 方位格
| {{{loc|s}}}
| {{{loc|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 奪格
| {{{abl|s}}}
| {{{abl|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 屬格
| {{{gen|s}}}
| {{{gen|p}}}]=])

	-- Possessive forms
	if data.has_poss then
		table.insert(wikicode, [=[

|- class="vsHide"
| colspan="3" style="padding: 0;" |
{| class="inflection-table vsSwitcher" style="text-align: left; width: 100%;"
|- style="background: #EFEFEF; text-align: left;"
! class="vsToggleElement" colspan="3" | 所有格形式
|- class="vsHide" style="background: #DEDEDE;"
! style="width: 12em;" |
! style="width: 10em;" | 單數
! style="width: 10em;" | 複數
|- class="vsHide"
! style="background: #EFEFEF;" | 第一人稱單數
| {{{1|s|poss|of the|s}}}
| {{{1|s|poss|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第二人稱單數
| {{{2|s|poss|of the|s}}}
| {{{2|s|poss|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第三人稱單數
| {{{3|s|poss|of the|s}}}
| {{{3|s|poss|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第一人稱複數
| {{{1|p|poss|of the|s}}}
| {{{1|p|poss|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第二人稱複數
| {{{2|p|poss|of the|s}}}
| {{{2|p|poss|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第三人稱複數
| {{{3|p|poss|of the|s}}}
| {{{3|p|poss|of the|p}}}
|}]=])
	end
	
	-- Predicative forms
	if data.has_pred then
		table.insert(wikicode, [=[

|- class="vsHide"
| colspan="3" style="padding: 0;" |
{| class="inflection-table vsSwitcher" style="text-align: left; width: 100%;"
|- style="background: #EFEFEF; text-align: left;"
! class="vsToggleElement" colspan="3" | 表語形式
|- class="vsHide" style="background: #DEDEDE;"
! style="width: 12em;" |
! style="width: 10em;" | 單數
! style="width: 10em;" | 複數
|- class="vsHide"
! style="background: #EFEFEF;" | 第一人稱單數
| {{{1|s|pred|of the|s}}}
| {{{1|s|pred|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第二人稱單數
| {{{2|s|pred|of the|s}}}
| {{{2|s|pred|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第三人稱單數
| {{{3|s|pred|of the|s}}}
| {{{3|s|pred|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第一人稱複數
| {{{1|p|pred|of the|s}}}
| {{{1|p|pred|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第二人稱複數
| {{{2|p|pred|of the|s}}}
| {{{2|p|pred|of the|p}}}
|- class="vsHide"
! style="background: #EFEFEF;" | 第三人稱複數
| {{{3|p|pred|of the|s}}}
| {{{3|p|pred|of the|p}}}
|}]=])
	end
	
	table.insert(wikicode, "\n|}")
	
	return mw.ustring.gsub(table.concat(wikicode), "{{{([#!]?[a-z0-9| ]+)}}}", repl) .. require("Module:utilities").format_categories(data.categories, lang)
end

return export