Kontent qismiga oʻtish

Modul:li-headword-eup

Vikilug‘atdan olingan

Bu modul uchun Modul:li-headword-eup/doc nomli hujjat sahifasini yaratishingiz mumkin

local export = {}
local pos_functions = {}

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

local gender_names = {
	["m"] = "masculine",
	["m-s"] = "masculine",
	["m-p"] = "masculine",
	["f"] = "feminine",
	["f-s"] = "feminine",
	["f-p"] = "feminine",
	["n"] = "neuter",
	["n-s"] = "neuter",
	["n-p"] = "neuter",
	["?"] = "unknown gender",
	["?-s"] = "unknown gender",
	["?-p"] = "unknown gender",
	["p"] = "unknown gender",
}

local plural_genders = {
	["m-p"] = true,
	["f-p"] = true,
	["n-p"] = true,
	["?-p"] = true,
	["p"] = true,
}

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

-- 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["head"]; 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 data = {lang = lang, pos_category = poscat, categories = {}, heads = {args["head"]}, genders = {}, inflections = {}}
	
	if pos_functions[poscat] then
		pos_functions[poscat](class, args, data)
	end
	
	return
		require("Module:headword").full_headword(data)
end

-- ADJECTIVES
pos_functions.adjectives = function(class, args, data)
	params = {
		[1] = {list = "m",
			default = mw.ustring.match(PAGENAME, "ee$") ~= nil
					and PAGENAME .. "ën" 
				or PAGENAME .. "e"},
		[2] = {list = "f",
			default = mw.ustring.match(PAGENAME, "[fjlmngrws]$") ~= nil
					and PAGENAME .. ""
				or PAGENAME .. "e"},
		["n"] = {list = true},
		["comp"] = {list = true},
			default = PAGENAME .. "er",
		["sup"] = {list = true,
			default = mw.ustring.match(PAGENAME, "s$") ~= nil
					and mw.ustring.gsub(PAGENAME,
					"([^AaIiEeOoUuÄäËëÉé])([aiou])([sxz])$",
					"%1%2%2%3") .. "te"
				or mw.ustring.gsub(PAGENAME,
					"([^AaIiEeOoUuÄäËëÉé])([aiou])([bcdfghjklmnpqrstvwxz]?)$",
					"%1%2%2%3") .. "ste"
			},
		["comp-irreg-only"] = {type = "boolean"},
		["head"] = {default = PAGENAME},
		["pred-only"] = {type = "boolean"},
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = {args.head}
	
	if args["pred-only"] then
		table.insert(data.inflections, {label = 'predicate-only'})
		table.insert(data.categories, 'Limburgish predicate only adjectives')
	else
		for i, form in ipairs(args[1]) do
			args[1][i] = {term = form}
		end
		args[1].label = "masculine"
		table.insert(data.inflections, args[1])
		
		if #args.n > 0 then
			for i, form in ipairs(args["n"]) do
				args["n"][i] = {term = form}
			end
			args["n"].label = "neuter"
			table.insert(data.inflections, args["n"])
		end
		
		for i, form in ipairs(args[2]) do
			args[2][i] = {term = form}
		end
		args[2].label = "feminine"
		table.insert(data.inflections, args[2])
	end
	
	if args["comp"][1] == '-' then
		table.insert(data.inflections, {label = 'not comparable'})
		table.insert(data.categories, 'Limburgish uncomparable adjectives')
	else
		if #args["comp"] > 0 then
			for i, form in ipairs(args["comp"]) do
				args["comp"][i] = {term = form}
			end
		else
			args["comp"] = {PAGENAME .. "er"}
		end
		args["comp"].label = "[[Appendix:Glossary#comparative|comparative]]"
		table.insert(data.inflections, args["comp"])
		
		for i, form in ipairs(args["sup"]) do
			args["sup"][i] = {term = form}
		end
		args["sup"].label = "[[Appendix:Glossary#superlative|superlative]]"
		table.insert(data.inflections, args["sup"])
	end
end

-- NOUNS
pos_functions.nouns = function(class, args, data)
	params = {
		[1] = {list = 'g', default = '?'},
		[2] = {list = 'pl'},
		["dim"] = {list = true},
		["head"] = {default = PAGENAME},
		["m"] = {list = true},
		["f"] = {list = true},
		["n"] = {list = true},
	}
	if data.pos_category == 'nouns' then
		params[2].default = mw.ustring.match(PAGENAME, "ee$") ~= nil
					and PAGENAME .. "ën" 
				or PAGENAME .. "e"
	end
	local args = require("Module:parameters").process(args, params)
	data.heads = {args.head}
	
	local plur_tant = false
	
	for _, g in ipairs(args[1]) do
		if legal_gender[g] then
			table.insert(data.genders, g)
			table.insert(data.categories, "Limburgish " .. gender_names[g] .. " nouns")
		else
			error("Gender “" .. g .. "” is not an valid Limburgish gender.")
		end
		
		if plural_genders[g] then
			plur_tant = true
		end
	end
	
	if plur_tant then
		table.insert(data.inflections, {label = '[[Appendix:Glossary#plural only|plural only]]'})
		table.insert(data.categories, 'Limburgish pluralia tantum')
	elseif args[2][1] == '-' then
		table.insert(data.inflections, {label = '[[Appendix:Glossary#uncountable|uncountable]]'})
		table.insert(data.categories, 'Limburgish uncountable nouns')
	elseif #args[2] > 0 then
		for i, form in ipairs(args[2]) do
			args[2][i] = {term = form}
		end
		args[2].label = "plural"
		table.insert(data.inflections, args[2])
		
		if #args[2] > 1 then
			table.insert(data.categories, 'Limburgish nouns with multiple plurals')
		end
	end
	
	if #args["dim"] > 0 then
		for i, form in ipairs(args["dim"]) do
			args["dim"][i] = {term = form}
		end
		args["dim"].label = "diminutive"
		table.insert(data.inflections, args["dim"])
	end
	
	if #args.f > 0 then
		args.f.label = "feminine"
		table.insert(data.inflections, args.f)
	end
	
	if #args.m > 0 then
		args.m.label = "masculine"
		table.insert(data.inflections, args.m)
	end
	
	if #args.n > 0 then
		args.n.label = "neuter"
		table.insert(data.inflections, args.n)
	end
end

-- PROPER NOUNS (UNFINISHED)
pos_functions["proper nouns"] = pos_functions.nouns

local function make_verb_forms(prefix)
	if prefix == nil then prefix = "" end
	
	if mw.ustring.match(prefix, "n$") then
		prefix = mw.ustring.gsub(
			prefix,
			"(.*)([^n])(n+)$",
			"%1%2"
			) .. "n*"
	end
	
	local stem = mw.ustring.gsub(PAGENAME, "^(" .. prefix .. ")(.*)([eë]n)$", "%2")
	local dent_suff = mw.ustring.match(stem, "([td]+)$")

	local conjugated = ""
	if dent_suff then
		conjugated = mw.ustring.gsub(stem, "([td]+)$", mw.ustring.rep("t", #dent_suff))
	else
		local lengthened = mw.ustring.gsub(stem,
			"([^AaIiEeOoUuÄäËëÉé])([aiou])([bcdfghjklmnpqrstvwz])$",
			"%1%2%2%3")
		conjugated = mw.ustring.match(lengthened, "(w)$") and mw.ustring.sub(lengthened, 1, -2) .. "ft" or lengthened .. "t"
	end
	
	return conjugated, (mw.ustring.match(conjugated, "^[ei]") and "gë" or "ge") .. conjugated
end

-- VERBS
pos_functions.verbs = function(class, args, data)
	third, pp = make_verb_forms(args.sep)
	
	params = {
		[1] = {list = '3s pres', default = third},
		[2] = {list = 'pp', default = pp},
		[3] = {default = 'haane'},
		["classes"] = {default = ""},
		["pret"] = {list = true},
		["subj"] = {list = true},
		["head"] = {default = PAGENAME},
		["sep"] = {default = ""},
	}
	
	local args = require("Module:parameters").process(args, params)
	data.heads = {args.head}
	
	local denasalized_prefix = mw.ustring.gsub(
		args.sep,
		"(.*)([^n])(n+)$",
		"%1%2"
		)
		
	if #args.classes == nil then
		table.insert(data.categories, 'Limburgish weak verbs')
	elseif #args.classes == "irregular" then
		table.insert(data.categories, 'Limburgish irregular verbs')
	elseif #args.classes > 0 then
		table.insert(data.inflections, {label = "class" .. classes .. "[[Appendix:Glossary#strong verb|strong]]"})
		table.insert(data.categories, 'Limburgish irregular verbs')
		table.insert(data.categories, 'Limburgish strong verbs')
		table.insert(data.categories, "Limburgish class " .. classes .. " strong verbs")
	end
	
	for i, form in ipairs(args[1]) do
		args[1][i] = {
			term = form .. (#args.sep > 0 and " " .. args.sep or ""),
			}
	end
	args[1].label = 'third-person singular present'
	table.insert(data.inflections, args[1])
	
	if #args.pret > 0 then
		for i, form in ipairs(args.pret) do
			args.pret[i] = {
				term = form .. (#args.sep > 0 and " " .. args.sep or ""),
				}
		end
		args.pret.label = 'preterite'
		table.insert(data.inflections, args.pret)
	end
	
	for i, form in ipairs(args[2]) do
		args[2][i] = {
			term = (mw.ustring.match(form, "^[^dhntzaäeéëioöuü]") and denasalized_prefix or args.sep) .. form,
			}
	end
	args[2].label = 'past participle'
	table.insert(data.inflections, args[2])
	
	if #args.subj > 0 then
		for i, form in ipairs(args.subj) do
			args.subj[i] = {
				term = form .. (#args.sep > 0 and " " .. args.sep or ""),
				}
		end
		args.subj.label = 'past subjunctive'
		table.insert(data.inflections, args.subj)
	end
	
	if args[3] == 'haane' then
		args[3] = {'haane'}
		table.insert(data.categories, 'Limburgish verbs using haane as auxiliary')
	elseif args[3] == 'séëne' then
		args[3] = {'séëne'}
		table.insert(data.categories, 'Limburgish verbs using séëne as auxiliary')
	elseif args[3] == 'both' then
		args[3] = {'haane', 'séëne'}
		table.insert(data.categories, 'Limburgish verbs using haane and séëne as auxiliary')
	else
		error("Verb auxiliary “" .. args[3] .. "” is not an valid Limburgish auxiliary (“haane”, “séëne”, or “both”).")
	end
	args[3].label = "auxiliary verb"
	table.insert(data.inflections, args[3])
end

return export