Module:sl-headword

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:sl-headword/documentation. [edit]
See also: subpages of this module.

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[edit]

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 m_common = require("Module:sl-common")
 
local export = {}
 
local lang = require("Module:languages").getByCode("sl")
 
local pos_functions = {}
 
-- 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 = {"Slovene " .. poscat}
 
	-- 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, "Slovene terms needing accents")
			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["adjectives"] = 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> please provide the comparative!</small>")
		table.insert(categories, "Slovene adjectives needing inflection")
	elseif mode == "-" then
		table.insert(inflections, {label = "not [[Appendix:Glossary#comparable|comparable]]"})
	else
		do_comparatives(heads, inflections, categories, comparatives, check_accents)
	end
end
 
-- Display additional inflection information for an adverb
pos_functions["adverbs"] = 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 = "[[Appendix:Glossary#comparative|comparative]]", accel = "comparative-form-of" .. encoded_head}
	local sup_parts = {label = "[[Appendix:Glossary#superlative|superlative]]", 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, "Slovene terms needing accents")
			end
		end
	end
 
	table.insert(inflections, comp_parts)
	table.insert(inflections, sup_parts)
end
 
-- Display additional inflection information for a noun
pos_functions["nouns"] = function(args, heads, genders, inflections, categories, check_accents)
	pos_functions["proper nouns"](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 = "[[Appendix:Glossary#duale tantum|duale tantum]]"})
	elseif num == "p" then
		table.insert(inflections, {label = "[[Appendix:Glossary#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> please provide the nominative plural!</small>")
			table.insert(categories, "Slovene nouns needing inflection")
		elseif mode == "-" then
			table.insert(inflections, {label = "[[Appendix:Glossary#uncountable|uncountable]]"})
			table.insert(categories, "Slovene uncountable nouns")
		else
			local pl_parts = {label = "nominative plural"}
 
			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, "Slovene nouns needing accents")
				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 = "feminine"}
 
		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, "Slovene nouns needing accents")
			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 = "masculine"}
 
		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, "Slovene nouns needing accents")
			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["proper nouns"] = 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, "Slovene masculine nouns")
			table.insert(categories, "Slovene masculine animate nouns")
		elseif g == "m-in" then
			table.insert(categories, "Slovene masculine nouns")
			table.insert(categories, "Slovene masculine inanimate nouns")
		elseif g:sub(1,1) == "m" then
			table.insert(categories, "Slovene masculine nouns")
		elseif g:sub(1,1) == "f" then
			table.insert(categories, "Slovene feminine nouns")
		elseif g:sub(1,1) == "n" then
			table.insert(categories, "Slovene neuter nouns")
		end
 
		-- Categorize by number
		if g:sub(3,3) == "d" then
			table.insert(categories, "Slovene dualia tantum")
		elseif g:sub(3,3) == "p" then
			table.insert(categories, "Slovene pluralia tantum")
		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, "Slovene nouns with multiple genders")
	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 = "genitive"}
 
		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, "Slovene nouns needing accents")
			end
		end
 
		table.insert(inflections, gen_parts)
	else
		table.insert(inflections, "<small><sup>???</sup> please provide the genitive!</small>")
		table.insert(categories, "Slovene nouns needing inflection")
	end
end
 
-- Display additional inflection information for a verb
pos_functions["verbs"] = 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, "Slovene imperfective verbs")
	elseif aspect == "pf" then
		table.insert(genders, "pf")
		table.insert(categories, "Slovene perfective verbs")
	elseif aspect == "both" then
		table.insert(genders, "impf")
		table.insert(genders, "pf")
		table.insert(categories, "Slovene imperfective verbs")
		table.insert(categories, "Slovene perfective verbs")
	else
		table.insert(genders, "?")
		table.insert(categories, "Slovene verbs needing aspect")
	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 = "first-person singular present"}
 
		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, "Slovene verbs needing accents")
			end
		end
 
		table.insert(inflections, pres_parts)
	else
		table.insert(inflections, "<small><sup>???</sup> please provide the present!</small>")
		table.insert(categories, "Slovene verbs needing inflection")
	end
 
	-- Past tense (past active participle / l-participle)
	if #pasts > 0 then
		local past_parts = {label = "past active participle"}
 
		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, "Slovene verbs needing accents")
			end
		end
 
		table.insert(inflections, past_parts)
	else
		table.insert(inflections, "<small><sup>???</sup> please provide the past!</small>")
		table.insert(categories, "Slovene verbs needing inflection")
	end
end
 
return export