Modül:de-başlıkbaşı

Vikisözlük sitesinden
Modül belgelemesi [Düzenle] [Tazele]

Bu Lua modülü, şu şablonların çıktısını vermektedir:


local export = {}
local pos_functions = {}

local legal_gender = {
	["m"] = true,
	["e"] = true,
	["m-s"] = true,
	["e-t"] = true,
	["m-p"] = true,
	["e-ç"] = true,
	["f"] = true,
	["d"] = true,
	["f-s"] = true,
	["d-t"] = true,
	["f-p"] = true,
	["d-ç"] = true,
	["n"] = true,
	["n-s"] = true,
	["n-t"] = true,
	["n-p"] = true,
	["n-ç"] = true,
	["?"] = true,
	["?-s"] = true,
	["?-t"] = true,
	["?-p"] = true,
	["?-ç"] = true,
	["p"] = true,
	["ç"] = true,
}

local gender_names = {
	["m"] = "eril",
	["e"] = "eril",
	["m-s"] = "eril",
	["e-t"] = "eril",
	["m-p"] = "eril",
	["e-ç"] = "eril",
	["f"] = "dişil",
	["d"] = "dişil",
	["f-s"] = "dişil",
	["d-t"] = "dişil",
	["f-p"] = "dişil",
	["d-ç"] = "dişil",
	["n"] = "nötr",
	["n-s"] = "nötr",
	["n-t"] = "nötr",
	["n-p"] = "nötr",
	["n-ç"] = "nötr",
	["?"] = "cinsiyeti bilinmeyen",
	["?-s"] = "cinsiyeti bilinmeyen",
	["?-t"] = "cinsiyeti bilinmeyen",
	["?-p"] = "cinsiyeti bilinmeyen",
	["?-ç"] = "cinsiyeti bilinmeyen",
	["p"] = "çoğul",
	["ç"] = "çoğul",
}

local legal_verb_classes = {
	['1'] = true,
	['2'] = true,
	['3'] = true,
	['4'] = true,
	['5'] = true,
	['6'] = true,
	['7'] = true,
}

local lang = require("Modül:diller").getirKodaGore("de")

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local args = frame:getParent().args
	PAGENAME = mw.title.getCurrentTitle().text
	
	local head = args["baş"]; if head == "" then head = nil end
	
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	local class = frame.args[2]; if class == "" then class = nil end
	
	local veri = {dil = lang, soz_kategorisi = poscat, kategoriler = {}, baslar = {head}, cinsiyetler = {}, cekimler = {}}
	
	if pos_functions[poscat] then
		pos_functions[poscat](class, args, veri)
	end
	
	return
		require("Modül:başlık başı").tam_baslikbasi(veri)
end

pos_functions["ön adlar"] = function(class, args, veri)
	params = {
		[1] = {list = "comp"},
		[2] = {list = "sup"},
		["baş"] = {},
	}
	local args = require("Modül:parameters").process(args, params)
	veri.baslar = {args["baş"]}
	
	if args[1][1] == '-' then
		table.insert(veri.cekimler, {etiket = 'kıyaslanamayan'})
		table.insert(veri.kategoriler, 'Almanca kıyaslanamayan ön adlar')
		return
	end
	
	if #args[1] > 0 then
		for i, form in ipairs(args[1]) do
			args[1][i] = {sozcuk = (form == 'er' and PAGENAME .. 'er' or form),
				accel = 'comparative-form-of'}
		end
	else
		args[1] = {request = true}
		table.insert(veri.kategoriler, 'de-adj lacking comparative')
	end
	args[1].etiket = "[[Ek:Açıklamalar#karşılaştırma|karşılaştırma]]"
	table.insert(veri.cekimler, args[1])
	
	if #args[2] > 0 then
		for i, form in ipairs(args[2]) do
			args[2][i] = {
				sozcuk = 'am [[' ..  (form == 'sten' and PAGENAME .. 'sten' or form) .. ']]',
				accel = 'superlative-form-of'}
		end
	else
		args[2] = {request = true}
		table.insert(veri.kategoriler, 'de-adj lacking superlative')
	end
	args[2].etiket = "[[Ek:Açıklamalar#üstünlük|üstünlük]]"
	table.insert(veri.cekimler, args[2])
end

pos_functions["adlar"] = function(class, args, veri)
	params = {
		[1] = {list = 'c', default = '?'},
		[2] = {list = 'gen',
			default = (
				args[1] == 'm' or
				args[1] == 'e' or
				args[1] == 'm-s' or
				args[1] == 'e-t' or
				args[1] == 'n' or
				args[1] == 'n-s' or
				args[1] == 'n-t'
				) and PAGENAME .. 's' or PAGENAME},
		[3] = {list = 'ç'},
		[4] = {list = 'dim'},
		["baş"] = {},
		["e"] = {list = true},
		["d"] = {list = true},
	}
	
	if veri.soz_kategorisi == 'adlar' then
		params[3].default = PAGENAME .. 'en'
	end
	
	local args = require("Modül:parameters").process(args, params)
	veri.baslar = {args["baş"]}
	
	for _, g in ipairs(args[1]) do
		if legal_gender[g] then
			table.insert(veri.cinsiyetler, g)
			if gender_names[g] ~= "cinsiyeti bilinmeyen" then
				table.insert(veri.kategoriler, "Almanca " .. gender_names[g] .. " adlar")
			end
		else
			error("Gender “" .. g .. "” is not an valid German gender.")
		end
	end
	
	for i, form in ipairs(args[2]) do
		args[2][i] = {sozcuk = form, accel = 'genitive-form-of'}
	end
	args[2].etiket = "tamlayan hâli"
	table.insert(veri.cekimler, args[2])
	
	if args[3][1] == '-' then
		table.insert(veri.cekimler, {etiket = 'çoğulu yok'})
		table.insert(veri.kategoriler, 'Almanca sayılamayan adlar')
	elseif #args[3] > 0 then
		for i, form in ipairs(args[3]) do
			args[3][i] = {sozcuk = form, accel = 'plural-form-of'}
		end
		args[3].etiket = "çoğulu"
		table.insert(veri.cekimler, args[3])
	end
	
	if #args[4] > 0 then
		for i, form in ipairs(args[4]) do
			args[4][i] = {
				sozcuk = form,
				cinsiyetler = {'n'},
				accel = 'diminutive-form-of gender-n'
				}
		end
		args[4].etiket = "diminutive"
		table.insert(veri.cekimler, args[4])
	end
	
	if #args.d > 0 then
		args.d.etiket = "dişil"
		table.insert(veri.cekimler, args.d)
	end
	
	if #args.e > 0 then
		args.e.etiket = "eril"
		table.insert(veri.cekimler, args.e)
	end
end

pos_functions["özel adlar"] = pos_functions["adlar"]

function export.detect_type(pr,pa,pp,ps)
	local args = {
		type = "",
		class = "",
	}
	local prefix = ""
	if mw.ustring.match(pr," ") then
		pr, prefix = mw.ustring.match(pr, "([^ ]+) (.+)")
		prefix = mw.ustring.gsub(prefix, " ", "")
	end
	pr = mw.ustring.gsub(pr, "e?t$", "")
	pa = mw.ustring.gsub(pa, " .+", "")
	ps = mw.ustring.gsub(ps, " .+", "")
	pp = mw.ustring.gsub(pp, " ", "")
	pp = mw.ustring.gsub(pp, prefix, "")
	pr = mw.ustring.gsub(pr, "ß", "ss")
	pa = mw.ustring.gsub(pa, "ß", "ss")
	pp = mw.ustring.gsub(pp, "ß", "ss")
	ps = mw.ustring.gsub(ps, "ß", "ss")
	local e = mw.ustring.match(pr, "[dt]$") and "e" or ""
	if pr .. e .. "te" == pa then
		args.type = 'weak'
	else
		local before, stem_vowel, long = mw.ustring.match(pr, "^(.-)([aeiouäöü]+)([^aeiouäöü]*)$")
		long = long or ""
		local short = long
		if mw.ustring.len(long) == 1 then
			short = long .. long
		elseif mw.ustring.match(long,"^h.$") then
			short = mw.ustring.gsub(long,"h(.)","%1%1")
		elseif mw.ustring.match(long,"^(.)%1") then
			long = mw.ustring.sub(long,1,1)
			short = long .. long
		end
		mw.log(pr,pa,pp,ps,before,stem_vowel,short,long)
		local function check(class, past, participle)
			participle = participle or past
			if pa == (before .. past .. long) then
				if pp == (before .. participle .. long .. "en") or pp == ("ge" .. before .. participle .. long .. "en") then
				args.type = "strong"
					args.class = type(class) == "string" and class or class()
					return true
				end
			elseif pa == (before .. past .. short) then
				if pp == (before .. participle .. short .. "en") or pp == ("ge" .. before .. participle .. short .. "en") then
					args.type = "strong"
					args.class = type(class) == "string" and class or class()
					return true
				end
			end
			return false
		end
		
		local function check_stem(class, stem)
			if mw.ustring.match(pr, stem .. "$") then
			args.type = "strong"
				args.class = class
				return true
			end
			return false
		end
		
		local done = false
		if stem_vowel == "ä" then
			done = check("3", "o", "o") or check("6", "u", "a") or check("7", "ie", "a")
		elseif stem_vowel == "au" then
			done = check("2", "o")
		elseif stem_vowel == "äu" then
			done = check("2", "o") or check("7", "ie", "au")
		elseif stem_vowel == "ei" then
			done = check("1", "ie") or check("1", "i") or check("7", "ie", "ei")
		elseif stem_vowel == "i" then
			local function distinguish()
				if ps then
					if ps == (before .. "ä" .. long .. "e") then
						return "4"
					else
						return "3"
					end
				else
					error("Please specify the past subjunctive by passing parameter 4")
				end
			end
			done = check("3", "a", "u") or check("3", "i", "o") or check("5", "a", "e")
			done = done or check("7", "ie", "e") or check(distinguish, "a", "o")
		elseif stem_vowel == "ie" then
			done = check("2", "o") or check("5", "a", "e") or check("7", "ie", "e")
		elseif stem_vowel == "ö" then
			done = check("7", "ie", "o")
		elseif stem_vowel == "ü" then
			done = check("2", "o") or check("7", "ie", "u")
		end
		if not done then
			done = check_stem("2", "zieh")
				or check_stem("3", "erlisch")
				or check_stem("3", "fich")
				or check_stem("3", "schall")
				or check_stem("4", "komm")
				or check_stem("4", "nimm")
				or check_stem("5", "iss")
				or check_stem("6", "heb")
				or check_stem("6", "schwör")
				or check_stem("7", "geh")
				or check_stem("7", "hau")
			args.type = "irregular"
		end
	end
	return args.type, args.class
end

pos_functions["eylemler"] = function(class, args, veri)
	params = {
		[1] = {list = 'present ='},
		[2] = {list = 'past ='},
		[3] = {list = 'past participle ='},
		["baş"] = {},
		["type"] = {default = class},
		["auxiliary"] = {default = 'haben'},
	}
	
	if class ~= 'weak' or args.type ~= 'weak' then
		params[4] = {list = 'past subjunctive'}
	end
	if class == 'strong' or args.type == 'strong' then
		params.class = {default = nil}
	end
	local args = require("Modül:parameters").process(args, params)
	veri.baslar = {args["baş"]}
	
	if not args.type then
		args.type, args.class = detect_type(args[1][1],args[2][1],args[3][1],args[4][1])
	end
	
	if args.type == 'strong' then
		if not args.class then
			table.insert(veri.cekimler, {etiket = '[[Ek:Açıklamalar#güçlü eylem|güçlü]]'})
			table.insert(veri.kategoriler, 'Almanca sınıfı olmayan güçlü eylemler')
		elseif legal_verb_classes[args.class] then
			table.insert(veri.cekimler, {etiket = 'sınıf ' .. args.class .. ' [[Ek:Açıklamalar#güçlü eylem|güçlü]]'})
			table.insert(veri.kategoriler, 'Almanca sınıf ' .. args.class .. ' güçlü eylemler')
		else
			error("Girdiğiniz güçlü eylem sınıfı “" .. args.class .. "” geçerli bir Almanca sınıfı (1-7) değil.")
		end
		table.insert(veri.kategoriler, 'Almanca güçlü eylemler')
	elseif args.type == 'weak' then
		table.insert(veri.cekimler, {etiket = '[[Ek:Açıklamalar#zayıf eylem|zayıf]]'})
		table.insert(veri.kategoriler, 'Almanca zayıf eylemler')
	elseif args.type == 'irregular' then
		table.insert(veri.cekimler, {etiket = '[[Ek:Açıklamalar#düzensiz|düzensiz]]'})
		table.insert(veri.kategoriler, 'Almanca düzensiz eylemler')
	elseif not args.type then
		table.insert(veri.kategoriler, 'Almanca çekimleme tipi olmayan eylemler')
	else
		error("Eylem tipi “" .. args.type .. "” geçerli bir Almanca tipi (“güçlü” veya “zayıf”) değil.")
	end
	
	if #args[1] == 0 then
		args[1] = {request = true}
	end
	args[1].etiket = 'üçüncü kişi tekil şimdiki zaman'
	table.insert(veri.cekimler, args[1])
	
	if #args[2] == 0 then
		args[2] = {request = true}
	end
	args[2].etiket = 'geçmiş zaman'
	table.insert(veri.cekimler, args[2])
	
	if #args[3] == 0 then
		args[3] = {request = true}
	end
	args[3].etiket = 'past participle'
	table.insert(veri.cekimler, args[3])
	
	if #args["past subjunctive"] > 0 then
		args["past subjunctive"].etiket = "past subjunctive"
		table.insert(veri.cekimler, args["past subjunctive"])
	end
	
	if args.auxiliary == 'haben' then
		args.auxiliary = {'haben'}
		table.insert(veri.kategoriler, 'Almanca verbs using haben as auxiliary')
	elseif args.auxiliary == 'sein' then
		args.auxiliary = {'sein'}
		table.insert(veri.kategoriler, 'Almanca verbs using sein as auxiliary')
	elseif args.auxiliary == 'both' then
		args.auxiliary = {'haben', 'sein'}
		table.insert(veri.kategoriler, 'Almanca verbs using haben and sein as auxiliary')
	else
		error("Verb auxiliary “" .. args.auxiliary .. "” is not an valid German auxiliary (“haben”, “sein”, or “both”).")
	end
	args.auxiliary.etiket = "auxiliary"
	table.insert(veri.cekimler, args.auxiliary)
end

return export