Pergi ke kandungan

Modul:sl-headword

Daripada Wikikamus
local m_common = require("Module:sl-common")

local export = {}

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

local pos_functions = {}

local function ucfirst(s)
	-- Kembali rentetan yang diberikan dengan aksara pertama dalam huruf besar.
	-- Tidak harus digunakan dengan rentetan bukan-ascii.
	return s:sub(1, 1):upper() .. s:sub(2, -1)
end

-- 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 poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	
	local genders = {}
	local inflections = {}
	local categories = {ucfirst(poscat) .. " bahasa Slovenia"}
	
	-- Gather headwords
	local head = args[1]
	local heads = {head or ""}
	local i = 2
	head = args["head" .. i]
	
	while head do
		if head ~= "" then
			table.insert(heads, head)
		end
		
		i = i + 1
		head = args["head" .. i]
	end
	
	-- Process headwords for accents
	local check_accents = true
	
	-- If the first headword given is "-", then skip the check.
	if heads[1] == "-" then
		heads[1] = ""
		check_accents = false
	else
		for i, head in ipairs(heads) do
			if head == "" or not m_common.has_accents(head) then
				table.insert(categories, "Istilah bahasa Slovenia yang memerlukan loghat")
			end
		end
	end
	
	-- Call POS-specific function
	if pos_functions[poscat] then
		pos_functions[poscat](args, heads, genders, inflections, categories, check_accents)
	end
	
	return require("Module:headword").full_headword(lang, nil, heads, nil, genders, inflections, categories, nil)
end

-- Display additional inflection information for an adjective
pos_functions["kata sifat" or "adjektif"] = function(args, heads, genders, inflections, categories, check_accents)
	-- Get all the parameters
	local comparatives = {}
	
	local i = 2
	
	while true do
		local comp = args[i]; if comp == "" then comp = nil end
		
		if not comp then
			break
		end
		
		table.insert(comparatives, comp)
		i = i + 1
	end
	
	-- Decide what to do next...
	local mode = comparatives[1]
	
	if not mode then
		table.insert(inflections, "<small><sup>???</sup> sila berikan perbandingan!</small>")
		table.insert(categories, "Kata sifat bahasa Slovenia yang memerlukan infleksi")
	elseif mode == "-" then
		table.insert(inflections, {label = "not [[Lampiran:Glosari#setanding|setanding]]"})
	else
		do_comparatives(heads, inflections, categories, comparatives, check_accents)
	end
end

-- Display additional inflection information for an adverb
pos_functions["adverba" or "kata keterangan"] = function(args, heads, genders, inflections, categories, check_accents)
	-- Get all the parameters
	local comparatives = {}
	
	local i = 2
	
	while true do
		local comp = args[i]; if comp == "" then comp = nil end
		
		if not comp then
			break
		end
		
		table.insert(comparatives, comp)
		i = i + 1
	end
	
	-- Decide what to do next...
	local mode = comparatives[1]
	
	if mode and mode ~= "-" then
		do_comparatives(heads, inflections, categories, comparatives, check_accents)
	end
end

function do_comparatives(heads, inflections, categories, comparatives, check_accents)
	local encoded_head = ""
	
	if heads[1] ~= "" then
		-- This is decoded again by [[WT:ACCEL]].
		encoded_head = " origin-" .. heads[1]:gsub("%%", "."):gsub(" ", "_")
	end
	
	local comp_parts = {label = "[[Lampiran:Glosari#komparitif|komparitif]]", accel = "comparative-form-of" .. encoded_head}
	local sup_parts = {label = "[[Lampiran:Glosari#superlatif|superlatif]]", accel = "superlative-form-of" .. encoded_head}
	
	for i, comp in ipairs(comparatives) do
		if comp == "bolj" then
			table.insert(comp_parts, "[[bòlj]] " .. (heads[1] ~= "" and heads[1] or PAGENAME))
			table.insert(sup_parts, "[[nàjbolj]] " .. (heads[1] ~= "" and heads[1] or PAGENAME))
		else
			table.insert(comp_parts, comp)
			table.insert(sup_parts, "nàj" .. comp)
			
			if check_accents and not m_common.has_accents(comp) then
				table.insert(categories, "Istilah bahasa Slovenia yang memerlukan loghat")
			end
		end
	end
	
	table.insert(inflections, comp_parts)
	table.insert(inflections, sup_parts)
end

-- Display additional inflection information for a noun
pos_functions["kata nama"] = function(args, heads, genders, inflections, categories, check_accents)
	pos_functions["kata nama khas"](args, heads, genders, inflections, categories, check_accents)
	
	-- If the noun is a duale/plurale tantum, then ignore the 4th parameter altogether
	local num = genders[1]:sub(3,3)
	
	if num == "d" then
		table.insert(inflections, {label = "[[Lampiran:Glosari#duale tantum|duale tantum]]"})
	elseif num == "p" then
		table.insert(inflections, {label = "[[Lampiran:Glosari#plurale tantum|plurale tantum]]"})
	else
		-- Get the plural parameters
		-- First get the 4th parameter. The remainder is named pl2=, pl3= etc.
		local form = args[4]; if form == "" then form = nil end
		local plurals = {form}
		local i = 2
		
		while true do
			form = args["pl" .. i]; if form == "" then form = nil end
			
			if not form then
				break
			end
			
			table.insert(plurals, form)
			i = i + 1
		end
		
		-- Decide what to do next...
		local mode = plurals[1]
		
		if not mode then
			table.insert(inflections, "<small><sup>???</sup> sila nyatakan jamak nominatif!</small>")
			table.insert(categories, "Kata nama bahasa Slovenia yang memerlukan infleksi")
		elseif mode == "-" then
			table.insert(inflections, {label = "[[Lampiran:Glosari#tak terhitung|tak terhitung]]"})
			table.insert(categories, "Kata nama tak terhitung bahasa Slovenia")
		else
			local pl_parts = {label = "jamak nominatif"}
			
			for i, form in ipairs(plurals) do
				table.insert(pl_parts, form)
				
				if check_accents and not m_common.has_accents(form) then
					table.insert(categories, "Kata nama bahasa Slovenia yang memerlukan loghat")
				end
			end
			
			table.insert(inflections, pl_parts)
		end
	end
	
	-- Get the feminine parameters
	-- First get the f= parameter. The remainder is named f2=, f3= etc.
	local form = args["f"]; if form == "" then form = nil end
	local feminines = {form}
	local i = 2
	
	while true do
		form = args["f" .. i]; if form == "" then form = nil end
		
		if not form then
			break
		end
		
		table.insert(feminines, form)
		i = i + 1
	end
	
	if #feminines > 0 then
		local f_parts = {label = "feminin"}
		
		for i, form in ipairs(feminines) do
			table.insert(f_parts, form)
			
			if check_accents and not m_common.has_accents(form) then
				table.insert(categories, "Kata nama bahasa Slovenia yang memerlukan loghat")
			end
		end
		
		table.insert(inflections, f_parts)
	end

	-- Get the masculine parameters
	-- First get the m= parameter. The remainder is named m2=, m3= etc.
	local form = args["m"]; if form == "" then form = nil end
	local masculines = {form}
	local i = 2
	
	while true do
		form = args["m" .. i]; if form == "" then form = nil end
		
		if not form then
			break
		end
		
		table.insert(masculines, form)
		i = i + 1
	end
	
	if #masculines > 0 then
		local m_parts = {label = "maskulin"}
		
		for i, form in ipairs(masculines) do
			table.insert(m_parts, form)
			
			if check_accents and not m_common.has_accents(form) then
				table.insert(categories, "Kata nama bahasa Slovenia yang memerlukan loghat")
			end
		end
		
		table.insert(inflections, m_parts)
	end
end

-- Display additional inflection information for a proper noun
-- This is also used for nouns
pos_functions["kata nama khas"] = function(args, heads, genders, inflections, categories, check_accents)
	local valid_genders = {
		["m-?"] = true,
		["m-an"] = true,
		["m-in"] = true,
		["f"] = true,
		["n"] = true,
		["m-d"] = true,
		["f-d"] = true,
		["n-d"] = true,
		["m-p"] = true,
		["f-p"] = true,
		["n-p"] = true }
	
	-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
	local g = args[2]; if g == "" then g = nil end
	local i = 2
	
	while g do
		if g == "m" then g = "m-?" end
		
		if not valid_genders[g] then
			g = "?"
		end
		
		table.insert(genders, g)
		
		-- Categorize by gender
		if g == "m-an" then
			table.insert(categories, "Kata nama maskulin bahasa Slovenia")
			table.insert(categories, "Kata nama maskulin hidup bahasa Slovenia")
		elseif g == "m-in" then
			table.insert(categories, "Kata nama maskulin bahasa Slovenia")
			table.insert(categories, "Kata nama maskulin tak hidup bahasa Slovenia")
		elseif g:sub(1,1) == "m" then
			table.insert(categories, "Kata nama maskulin bahasa Slovenia")
		elseif g:sub(1,1) == "f" then
			table.insert(categories, "Kata nama feminin bahasa Slovenia")
		elseif g:sub(1,1) == "n" then
			table.insert(categories, "Kata nama neuter bahasa Slovenia")
		end
		
		-- Categorize by number
		if g:sub(3,3) == "d" then
			table.insert(categories, "Dualia tantum bahasa Slovenia")
		elseif g:sub(3,3) == "p" then
			table.insert(categories, "Pluralia tantum bahasa Slovenia")
		end
		
		g = args["g" .. i]; if g == "" then g = nil end
		i = i + 1
	end
	
	if #genders == 0 then
		table.insert(genders, "?")
	elseif #genders > 1 then
		table.insert(categories, "Kata nama bahasa Slovenia dengan beberapa genus")
	end
	
	-- Get the genitive parameters
	-- First get the 3rd parameter. The remainder is named gen2=, gen3= etc.
	local form = args[3]; if form == "" then form = nil end
	local genitives = {form}
	local i = 2
	
	while true do
		form = args["gen" .. i]; if form == "" then form = nil end
		
		if not form then
			break
		end
		
		table.insert(genitives, form)
		i = i + 1
	end
	
	-- Show the forms
	if #genitives > 0 then
		local gen_parts = {label = "genitif"}
		
		for i, form in ipairs(genitives) do
			table.insert(gen_parts, form)
			
			if check_accents and not m_common.has_accents(form) then
				table.insert(categories, "Kata nama bahasa Slovenia yang memerlukan loghat")
			end
		end
		
		table.insert(inflections, gen_parts)
	else
		table.insert(inflections, "<small><sup>???</sup> sila nyatakan genitif!</small>")
		table.insert(categories, "Kata nama bahasa Slovenia yang memerlukan infleksi")
	end
end

-- Display additional inflection information for a verb
pos_functions["kata kerja"] = function(args, heads, genders, inflections, categories, check_accents)
	-- Aspect
	local aspect = args[2]; if aspect == "" then aspect = nil end
	
	if aspect == "impf" then
		table.insert(genders, "impf")
		table.insert(categories, "Kata kerja tak sempurna bahasa Slovenia")
	elseif aspect == "pf" then
		table.insert(genders, "pf")
		table.insert(categories, "Kata kerja sempurna bahasa Slovenia")
	elseif aspect == "both" then
		table.insert(genders, "impf")
		table.insert(genders, "pf")
		table.insert(categories, "Kata kerja tak sempurna bahasa Slovenia")
		table.insert(categories, "Kata kerja sempurna bahasa Slovenia")
	else
		table.insert(genders, "?")
		table.insert(categories, "Kata kerja bahasa Slovenia yang memerlukan aspek")
	end
	
	-- Get all the parameters
	-- First get the 3rd and 4th parameters. The remainder is named pres2=, past2= etc.
	local pres = args[3]; if pres == "" then pres = nil end
	local past = args[4]; if past == "" then past = nil end
	local presents = {pres}
	local pasts = {past}
	local i = 2
	
	while true do
		pres = args["pres" .. i]; if pres == "" then pres = nil end
		past = args["past" .. i]; if past == "" then past = nil end
		
		if not pres and not past then
			break
		end
		
		if pres then table.insert(presents, pres) end
		if past then table.insert(pasts, past) end
		i = i + 1
	end
	
	-- Present tense (1st person singular)
	if #presents > 0 then
		local pres_parts = {label = "kala kini singular diri pertama"}
		
		for i, form in ipairs(presents) do
			table.insert(pres_parts, form)
			
			if check_accents and not m_common.has_accents(form) then
				table.insert(categories, "Kata kerja bahasa Slovenia yang memerlukan loghat")
			end
		end
		
		table.insert(inflections, pres_parts)
	else
		table.insert(inflections, "<small><sup>???</sup> sila nyatakan kala kini!</small>")
		table.insert(categories, "Kata kerja bahasa Slovenia yang memerlukan infleksi")
	end
	
	-- Past tense (past active participle / l-participle)
	if #pasts > 0 then
		local past_parts = {label = "partisip aktif kala lampau"}
		
		for i, form in ipairs(pasts) do
			table.insert(past_parts, form)
			
			if check_accents and not m_common.has_accents(form) then
				table.insert(categories, "Kata kerja bahasa Slovenia yang memerlukan aspek")
			end
		end
		
		table.insert(inflections, past_parts)
	else
		table.insert(inflections, "<small><sup>???</sup> sila nyatakan kala lampau!</small>")
		table.insert(categories, "Kata kerja bahasa Slovenia yang memerlukan infleksi")
	end
end

return export