Modul:cop-headword

Daripada Wiktionary

Pendokumenan untuk modul ini boleh diciptakan di Modul:cop-headword/doc

local export = {}
local lang = require("Module:languages").getByCode("cop")
local m_scripts = require("Module:scripts")

-- key           = what is entered into the template
-- first value   = displayed siglum
-- second value  = tooltip
local dialects = {
	["A"]  = { "A", "Akhmim" },
	["A2"] = { "L", "Lycopolitan" },
	["B"]  = { "B", "Buhairi" },
	["F"]  = { "F", "Fayyum" },
	["G"]  = { "G", "Dialek G" },
	["H"]  = { "H", "Hermopolitan" },
	["I"]  = { "I", "Proto-Lycopolitan" },
	["J"]  = { "J", "Dialek J" },
	["K"]  = { "K", "Dialek K" },
	["L"]  = { "L", "Lycopolitan" },
	["M"]  = { "O", "Oxyrhynchus" },
	["O"]  = { "O", "Oxyrhynchus" },
	["OC"] = { "OC", "Qibti Lama" },
	["P"]  = { "P", "Dialek P" },
	["S"]  = { "S", "Saidi" },
}

local rdialects = {}
-- allow displayed text forms to be entered too
for key, value in pairs(dialects) do
	if key == value[1] then
		rdialects[value[2]] = value
	end
end
for key, value in pairs(rdialects) do
	dialects[key] = value
end

-- expand list of comma-separated dialects (tooltips, etc.)
local function parse_dialects(qual)
	local list = mw.text.split(qual, ',%s*')
	local expanded = { }

	for i, dialect in ipairs(list) do
		if dialects[dialect] then
			table.insert(expanded, '<abbr title="' .. dialects[dialect][2] .. '">' .. dialects[dialect][1] .. "</abbr>")
		else
			table.insert(expanded, dialect)
		end
	end

	return table.concat(expanded, ", ")
end

local function generate_head_forms(inflections, name, forms, qualifiers)
	if #forms < 1 then return end
	local infl = { label = name }
	for i, form in ipairs(forms) do
		local term = { term = form }
		if qualifiers[i] then
			term.qualifiers = parse_dialects(qualifiers[i])
		end
		table.insert(infl, term)
	end
	table.insert(inflections, infl)
end

function export.show_noun(frame)
	local title = mw.title.getCurrentTitle().text
	local categories = { }
	
	local params = {
		[1] = { default = "?" },
		[2] = { list = "pl", default = title },
		[3] = { default = nil },
		
		["f"] = { list = true },
		["nom"] = { list = true },
		["pro"] = { list = true },
		
		["q"] = { list = true, require_index = true, allow_holes = true },
		["fq"] = { list = true, require_index = true, allow_holes = true },
		["nomq"] = { list = true, require_index = true, allow_holes = true },
		["proq"] = { list = true, require_index = true, allow_holes = true },
		
		["head"] = { default = nil },
		["title"] = { default = nil }
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local plurals = args[2]
	local head = args["head"]
	local gender = args[1]
	local inflections = { ["enable_auto_translit"] = true }

	if args[3] and plurals[1] ~= "~" then
		error("Argumen 3 hanya dibenarkan jika argumen 2 ialah ~ (kata nama kedua-duanya berbilang dan tidak berbilang)")
	elseif plurals[1] == "-" then
		if #plurals > 1 then error("Tidak dapat memberi lebih banyak jamak untuk kata nama tidak berbilang") end
		table.insert(inflections, { label = "[[Lampiran:Glosari#tidak berbilang|tidak berbilang]]" } )
		plurals = { }
		table.insert(categories, "Kata nama tidak berbilang bahasa Qibti")
	elseif plurals[1] == "!" then
		if #plurals > 1 then error("Tidak dapat memberi lebih banyak jamak jika jamak tidak dibuktikan") end
		table.insert(inflections, { label = "jamak tidak dibuktikan" } )
		plurals = { }
		table.insert(categories, "Kata nama bahasa Qibti dengan jamak tidak dibuktikan")
	elseif plurals[1] == "~" then
		table.insert(inflections, { label = "[[Lampiran:Glosari#berbilang|berbilang]] dan [[Lampiran:Glosari#tidak berbilamg|tidak berbilang]]" } )
		plurals[1] = args[3] or head or title
		table.insert(categories, "Kata nama tidak berbilang bahasa Qibti")
		-- countable added later
	end
	
	if plurals[1] == "?" or (plurals[1] == "~" and args[3] == "?") then
		if #plurals > 1 then error("Tidak dapat memberi lebih banyak jamak jika jamak tidak pasti") end
		plurals = { }
		table.insert(categories, "Masukan kata nama bahasa Qibti yang hilang bentuk jamak")
	elseif #plurals > 0 then
		table.insert(categories, "Kata nama berbilang bahasa Qibti")
	end
	
	if head then
		for i, pl in ipairs(plurals) do
			if pl == title then
				plurals[i] = head
			end
		end
	end

	generate_head_forms(inflections, "feminin", args["f"], args["fq"])
	generate_head_forms(inflections, "jamak", plurals, args["q"])
	generate_head_forms(inflections, "bentuk namaan", args["nom"], args["nomq"])
	generate_head_forms(inflections, "bentuk kata ganti", args["pro"], args["proq"])

	return require("Module:headword").full_headword{
		lang = lang,
		heads = { head or title },
		genders = { gender },
		inflections = inflections,
		pos_category = "nouns",
		categories = categories
	}
end

return export