Документација модула[прикажи] [уреди] [историја] [освежи]

This module is used for all Slovene headword-line templates. It provides a basic functionality common to all of them, but some of the templates have specific additional functionality to show genders or inflected forms.

Accented headwords уреди

All Slovene headword-line templates use the first parameter to provide the headword, with accented vowels where present. This uses the stress-based diacritics (with only `, ´ and ^). Tonal diacritics should be given in the pronunciation section using the {{sl-tonal}} template. See Appendix:Slovene pronunciation and Wiktionary:About Slovene for more details. For example:

{{sl-noun|jéž|m-an|jéža|jéži}}
{{sl-adj|nòv|novêjši}}
{{sl-pron|ôna}}

If the word can be accented in more than one way, use additional |head2=, |head3= (etc.) parameters. For example on takoj:

{{sl-adv|takój|head2=takòj}}

The headword parameter works exactly like |head= on the {{head}} template, so it supports all the same special features. You can therefore also use this parameter to link to individual words of a multi-word term. These words can be linked with accents still in place; the module will remove them from the page name before creating a link, much like {{l}} does.

All Slovene words are expected to have accents specified. The module will check the parameter for the presence of accents, and categorize the entry in Category:Slovene terms needing accents if none are found. Some words like prepositions really have no inherent accent of their own, and some words with foreign spelling (like Sydney) can't be reliably given accents without respelling them. For such words, give - as the first parameter, as on the preposition brez:

{{sl-prep|-}}

This tells the module that you are sure that the word should not have accents, so that it will not check for them.

If you don't know where to place the accents, you can leave the parameter empty, or just write the page name without accents. Don't use - unless you're sure the word should not have any accents.

local lang = require("Модул:languages").getByCode("sl")

local export = {}


local function do_headwords(data)
	-- If the first headword given is "-", then skip the check.
	if data.heads[1] == "-" then
		data.heads[1] = ""
		return false
	end
	
	for i, head in ipairs(data.heads) do
		if head == "" or not require("Модул:sl-common").has_accents(head) then
			table.insert(data.categories, "Requests for accents in Slovene entries")
		end
	end
	
	return true
end


local function do_genders(data)
	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,
	}
	
	for i, g in ipairs(data.genders) do
		if g == "m" then
			g = "m-?"
		elseif not valid_genders[g] then
			g = "?"
		end
		
		data.genders[i] = g
		
		-- Categorize by gender
		if g == "m-an" then
			table.insert(data.categories, "Slovene masculine nouns")
			table.insert(data.categories, "Slovene masculine animate nouns")
		elseif g == "m-in" then
			table.insert(data.categories, "Slovene masculine nouns")
			table.insert(data.categories, "Slovene masculine inanimate nouns")
		elseif g:sub(1,1) == "m" then
			table.insert(data.categories, "Slovene masculine nouns")
		elseif g:sub(1,1) == "f" then
			table.insert(data.categories, "Slovene feminine nouns")
		elseif g:sub(1,1) == "n" then
			table.insert(data.categories, "Slovene neuter nouns")
		end
		
		-- Categorize by number
		if g:sub(3,3) == "d" then
			table.insert(data.categories, "Slovene dualia tantum")
		elseif g:sub(3,3) == "p" then
			table.insert(data.categories, "Slovene pluralia tantum")
		end
	end
	
	if #data.genders > 1 then
		table.insert(data.categories, "Slovene nouns with multiple genders")
	end
end


local function do_comparatives(data, comparatives, check_accents)
	local encoded_head = data.heads[1]
	
	if encoded_head == "" then
		encoded_head = nil
	end
	
	local comp_parts = {label = "[[Додатак:Речник#comparative|comparative]]", request = true} --accel = {form = "comparative", lemma = encoded_head}
	local sup_parts = {label = "[[Додатак:Речник#superlative|superlative]]"} --accel = {form = "superlative", lemma = encoded_head}
	
	for i, comp in ipairs(comparatives) do
		if comp == "bolj" then
			table.insert(comp_parts, "[[bȍlj]] " .. (data.heads[1] ~= "" and data.heads[1] or mw.title.getCurrentTitle().text))
			table.insert(sup_parts, "[[nȁjbolj]] " .. (data.heads[1] ~= "" and data.heads[1] or mw.title.getCurrentTitle().text))
		else
			table.insert(comp_parts, comp)
			table.insert(sup_parts, "nȁj" .. comp)
			
			if check_accents and not require("Module:sl-common").has_accents(comp) then
				table.insert(data.categories, "Requests for accents in Slovene entries")
			end
		end
	end
	
	table.insert(data.inflections, comp_parts)
	table.insert(data.inflections, sup_parts)
end


function export.default(frame)
	local params = {
		[1] = {list = "head"},
	}
	
	local args = require("Модул:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = frame.args[1], categories = {}, heads = args[1], inflections = {}}
	
	local check_accents = do_headwords(data)
	
	return require("Module:headword").full_headword(data)
end


function export.adjectives(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {list = true},
	}
	
	local args = require("Модул:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "adjectives", categories = {}, heads = args[1], inflections = {}}
	
	local check_accents = do_headwords(data)

	-- Decide what to do next...
	if args[2][1] == "-" then
		table.insert(data.inflections, {label = "not [[Appendix:Glossary#comparable|comparable]]"})
	else
		do_comparatives(data, args[2], check_accents)
	end
	
	return require("Module:headword").full_headword(data)
end


function export.adverbs(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "adverbs", categories = {}, heads = args[1], inflections = {}}
	
	local check_accents = do_headwords(data)

	-- Decide what to do next...
	if args[2][1] and args[2][1] ~= "-" then
		do_comparatives(data, args[2], check_accents)
	end
	
	return require("Module:headword").full_headword(data)
end


function export.nouns(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {list = "g", default = "?"},
		
		["f"] = {list = true},
		["m"] = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "именице", categories = {}, heads = args[1], genders = args[2], inflections = {}}
	
	local check_accents = do_headwords(data)
	do_genders(data)
	
	-- Female equivalent
	if #args["f"] > 0 then
		args["f"].label = "female equivalent"
		
		if check_accents then
			for i, form in ipairs(args["f"]) do
				if not require("Module:sl-common").has_accents(form) then
					table.insert(data.categories, "Requests for accents in Slovene noun entries")
				end
			end
		end
		
		-- Tone check
		for i, form in ipairs(args["f"]) do
			local found_tonal = false
			local found_stress = false
			local found_ambiguous = false
			form = mw.ustring.lower(form)
			
			if mw.ustring.find(form, "[ȃȇȋȏȗȓāēīōūȁȅȉȍȕẹọ" .. mw.ustring.char(0x0304) .. "]") then
				found_tonal = true
			end
			
			if mw.ustring.find(form, "[êô]") then
				found_stress = true
			end
			
			if mw.ustring.find(form, "[áéíóúŕàèìòù]") then
				found_ambiguous = true
			end
			
			if found_stress then
				require("Module:debug").track("sl-headword/stress")
			elseif found_ambiguous then
				require("Module:debug").track("sl-headword/ambiguous")
			elseif found_tonal then
				require("Module:debug").track("sl-headword/tonal")
			end
		end
		
		table.insert(data.inflections, args["f"])
	end
	
	-- Male equivalent
	if #args["m"] > 0 then
		args["m"].label = "male equivalent"
		
		if check_accents then
			for i, form in ipairs(args["m"]) do
				if not require("Module:sl-common").has_accents(form) then
					table.insert(data.categories, "Requests for accents in Slovene noun entries")
				end
			end
		end
		
		-- Tone check
		for i, form in ipairs(args["m"]) do
			local found_tonal = false
			local found_stress = false
			local found_ambiguous = false
			form = mw.ustring.lower(form)
			
			if mw.ustring.find(form, "[ȃȇȋȏȗȓāēīōūȁȅȉȍȕẹọ" .. mw.ustring.char(0x0304) .. "]") then
				found_tonal = true
			end
			
			if mw.ustring.find(form, "[êô]") then
				found_stress = true
			end
			
			if mw.ustring.find(form, "[áéíóúŕàèìòù]") then
				found_ambiguous = true
			end
			
			if found_stress then
				require("Module:debug").track("sl-headword/stress")
			elseif found_ambiguous then
				require("Module:debug").track("sl-headword/ambiguous")
			elseif found_tonal then
				require("Module:debug").track("sl-headword/tonal")
			end
		end
		
		table.insert(data.inflections, args["m"])
	end
	
	return require("Module:headword").full_headword(data)
end


function export.proper_nouns(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {list = "g", default = "?"},
		
		["f"] = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "властите именице", categories = {}, heads = args[1], genders = args[2], inflections = {}}
	
	local check_accents = do_headwords(data)
	do_genders(data)
	
	-- Female equivalent
	if #args["f"] > 0 then
		args["f"].label = "female equivalent"
		
		if check_accents then
			for i, form in ipairs(args["f"]) do
				if not require("Module:sl-common").has_accents(form) then
					table.insert(data.categories, "Requests for accents in Slovene noun entries")
				end
			end
		end
		
		table.insert(data.inflections, args["f"])
	end
	
	return require("Module:headword").full_headword(data)
end


function export.verbs(frame)
	local params = {
		[1] = {list = "head"},
		[2] = {default = "?"},
		
		["impf"] = {list = true},
		["pf"] = {list = true},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local data = {lang = lang, pos_category = "verbs", categories = {}, heads = args[1], genders = {args[2]}, inflections = {}}
	
	local check_accents = do_headwords(data)
	
	-- Check aspect
	if data.genders[1] == "impf" then
		table.insert(data.categories, "Slovene imperfective verbs")
		
		if #args["impf"] > 0 then
			error("Imperfective verbs cannot have an imperfective equivalent")
		end
		
		-- Perfective equivalents
		if #args["pf"] > 0 then
			if check_accents then
				for _, form in ipairs(args["pf"]) do
					if require("Module:sl-common").has_accents(form) then
						table.insert(data.categories, "Requests for accents in Slovene verb entries")
					end
				end
			end
			
			args["pf"].label = "perfective"
			table.insert(data.inflections, args["pf"])
		end
	elseif data.genders[1] == "pf" then
		table.insert(data.categories, "Slovene perfective verbs")
		
		if #args["pf"] > 0 then
			error("Perfective verbs cannot have a perfective equivalent")
		end
		
		-- Imperfective equivalents
		if #args["impf"] > 0 then
			if check_accents then
				for _, form in ipairs(args["impf"]) do
					if require("Module:sl-common").has_accents(form) then
						table.insert(data.categories, "Requests for accents in Slovene verb entries")
					end
				end
			end
			
			args["impf"].label = "imperfective"
			table.insert(data.inflections, args["impf"])
		end
	elseif data.genders[1] == "both" then
		data.genders = {"impf", "pf"}
		table.insert(data.categories, "Slovene biaspectual verbs")
		
		if #args["impf"] > 0 or #args["pf"] > 0 then
			error("Bispectual verbs cannot have an imperfective or perfective equivalent")
		end
	else
		data.genders = {"?"}
		table.insert(data.categories, "Requests for aspect in Slovene entries")
	end
	
	return require("Module:headword").full_headword(data)
end

return export