Module:sl-adjective

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:sl-adjective/documentation. [edit]
Useful links: subpage listtransclusionstestcases
Text-x-generic with pencil.svg This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local m_utilities = require("Module:utilities")
local m_common = require("Module:sl-common")
 
local export = {}
 
local lang = require("Module:languages").getByCode("sl")
 
-- Within this module, inflections are the functions that do the actual inflecting
-- by creating the forms of an adjective. They are defined further down.
local inflections = {}
 
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	PAGENAME = mw.title.getCurrentTitle().text
	FULLPAGENAME = mw.title.getCurrentTitle().prefixedText
	NAMESPACE = mw.title.getCurrentTitle().nsText
	local infl_type = frame.args[1] or error("Inflection type has not been specified.")
	local args = frame:getParent().args
 
	local forms = {}
	local title = nil
	local categories = {}
 
	if inflections[infl_type] then
		title = inflections[infl_type](args, forms, categories)
	else
		error("Unknown inflection type '" .. infl_type .. "'")
	end
 
	return make_table(forms, title) .. m_utilities.format_categories(categories, lang)
end
 
-- Hard stem adjective
inflections["regular"] = function(args, forms, categories)
	local stem = args[1]; if not stem or stem == "" then if NAMESPACE == "Template" then stem = "-" else error("1st parameter (stem) has not been specified.") end end
	local final = args[2]; if final == "" then final = nil end
	local def = args["def"]
 
	-- Create the full stem, which is used when endings are added
	local full_stem = stem
 
	if final then
		full_stem = full_stem .. final
	else
		full_stem = make_long(full_stem)
	end
 
	-- If the given stem doesn't contain any accent marks, flag the entry for attention
	if not m_common.has_accents(full_stem) then
		table.insert(categories, "Slovene adjectives needing accents")
	end
 
	-- Is this a hard stem or a soft stem?
	local oe = "o"
	local title = "hard"
 
	if m_common.is_soft(full_stem) then
		oe = "e"
		title = "soft"
	end
 
	-- Masculine singular
	if def == "1" then
		forms["nom_sg_m"] = full_stem .. "i"
	elseif def == "0" then
		forms["nom_sg_m"] = stem .. (final and "e" .. final or "")
	else
		forms["nom_sg_m"] = stem .. (final and "e" .. final or "")
		forms["nom_sg_m_def"] = full_stem .. "i"
	end
	-- acc_sg_m depends on animacy
	forms["gen_sg_m"] = full_stem .. "ega"
	forms["dat_sg_m"] = full_stem .. "emu"
	forms["loc_sg_m"] = full_stem .. "em"
	forms["ins_sg_m"] = full_stem .. "im"
 
	-- Feminine singular
	forms["nom_sg_f"] = full_stem .. "a"
	forms["acc_sg_f"] = full_stem .. "o"
	forms["gen_sg_f"] = full_stem .. "e"
	forms["dat_sg_f"] = full_stem .. "i"
	forms["loc_sg_f"] = full_stem .. "i"
	forms["ins_sg_f"] = full_stem .. "o"
 
	-- Neuter singular
	forms["nom_sg_n"] = full_stem .. oe
	forms["acc_sg_n"] = full_stem .. oe
	forms["gen_sg_n"] = full_stem .. "ega"
	forms["dat_sg_n"] = full_stem .. "emu"
	forms["loc_sg_n"] = full_stem .. "em"
	forms["ins_sg_n"] = full_stem .. "im"
 
	-- Masculine dual
	forms["nom_du_m"] = full_stem .. "a"
	forms["acc_du_m"] = full_stem .. "a"
	forms["gen_du_m"] = full_stem .. "ih"
	forms["dat_du_m"] = full_stem .. "ima"
	forms["loc_du_m"] = full_stem .. "ih"
	forms["ins_du_m"] = full_stem .. "ima"
 
	-- Feminine dual
	forms["nom_du_f"] = full_stem .. "i"
	forms["acc_du_f"] = full_stem .. "i"
	forms["gen_du_f"] = full_stem .. "ih"
	forms["dat_du_f"] = full_stem .. "ima"
	forms["loc_du_f"] = full_stem .. "ih"
	forms["ins_du_f"] = full_stem .. "ima"
 
	-- Neuter dual
	forms["nom_du_n"] = full_stem .. "i"
	forms["acc_du_n"] = full_stem .. "i"
	forms["gen_du_n"] = full_stem .. "ih"
	forms["dat_du_n"] = full_stem .. "ima"
	forms["loc_du_n"] = full_stem .. "ih"
	forms["ins_du_n"] = full_stem .. "ima"
 
	-- Masculine plural
	forms["nom_pl_m"] = full_stem .. "i"
	forms["acc_pl_m"] = full_stem .. "e"
	forms["gen_pl_m"] = full_stem .. "ih"
	forms["dat_pl_m"] = full_stem .. "im"
	forms["loc_pl_m"] = full_stem .. "ih"
	forms["ins_pl_m"] = full_stem .. "imi"
 
	-- Feminine plural
	forms["nom_pl_f"] = full_stem .. "e"
	forms["acc_pl_f"] = full_stem .. "e"
	forms["gen_pl_f"] = full_stem .. "ih"
	forms["dat_pl_f"] = full_stem .. "im"
	forms["loc_pl_f"] = full_stem .. "ih"
	forms["ins_pl_f"] = full_stem .. "imi"
 
	-- Neuter plural
	forms["nom_pl_n"] = full_stem .. "a"
	forms["acc_pl_n"] = full_stem .. "a"
	forms["gen_pl_n"] = full_stem .. "ih"
	forms["dat_pl_n"] = full_stem .. "im"
	forms["loc_pl_n"] = full_stem .. "ih"
	forms["ins_pl_n"] = full_stem .. "imi"
 
	return title
end
 
function make_long(stem)
	local vowel_repl = {
		["à"] = "á",
		["è"] = "ê",
		["ì"] = "í",
		["ò"] = "ô",
		["ù"] = "ú"}
 
	function repl(vowel, rest)
		return (vowel_repl[vowel] or vowel) .. rest
	end
 
	return mw.ustring.gsub(stem, "([àèìòù])([^aeiouàèìòùáéíóúêô]+)$", repl)
end
 
function make_table(forms, title)
	local m_links = require("Module:links")
	local m_scriptutils = require("Module:script utilities")
 
	-- Make links out of all forms
	for key, form in pairs(forms) do
		if type(form) == "table" then
			for key2, subform in ipairs(form) do
				form[key2] = m_links.full_link(subform, nil, lang, nil, nil, nil, {}, false)
			end
 
			forms[key] = table.concat(form, ",<br/>")
		else
			forms[key] = m_links.full_link(form, nil, lang, nil, nil, nil, {}, false)
		end
	end
 
	return [=[
<div class="NavFrame" style="width: 70em">
<div class="NavHead" style="background:#d9ebff; text-align: left">Declension of <i lang="sl">]=] .. forms["nom_sg_m"] .. "</i>" .. (title and " (" .. title .. ")" or "") .. [=[</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;width:100%" class="inflection-table"
|-
! colspan="4" style="background:#b3d7ff" | singular
|-
! style="background:#d9ebff;width:16%" | 
! style="background:#d9ebff;width:28%" | masculine
! style="background:#d9ebff;width:28%" | feminine
! style="background:#d9ebff;width:28%" | neuter
|-
! style="background:#eff7ff" | nominative
| ]=] .. (forms["nom_sg_m"] or "&mdash;") .. (forms["nom_sg_m_def"] and ' <sup style="cursor:help" title="indefinite">ind</sup><br/>' .. (forms["nom_sg_m_def"] or "&mdash;") .. ' <sup style="cursor:help" title="definite">def</sup>' or "") .. [=[
 
| ]=] .. (forms["nom_sg_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["nom_sg_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | accusative
| ''nominative''<sup style="cursor:help" title="inanimate">inan</sup>'' or genitive''<sup style="cursor:help" title="animate">anim</sup>
| ]=] .. (forms["acc_sg_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["acc_sg_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | genitive
| ]=] .. (forms["gen_sg_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["gen_sg_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["gen_sg_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | dative
| ]=] .. (forms["dat_sg_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["dat_sg_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["dat_sg_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | locative
| ]=] .. (forms["loc_sg_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["loc_sg_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["loc_sg_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | instrumental
| ]=] .. (forms["ins_sg_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["ins_sg_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["ins_sg_n"] or "&mdash;") .. [=[
 
|-
! colspan="4" style="background:#b3d7ff" | dual
|-
! style="background:#d9ebff" | 
! style="background:#d9ebff" | masculine
! style="background:#d9ebff" | feminine
! style="background:#d9ebff" | neuter
|-
! style="background:#eff7ff" | nominative
| ]=] .. (forms["nom_du_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["nom_du_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["nom_du_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | accusative
| ]=] .. (forms["acc_du_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["acc_du_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["acc_du_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | genitive
| ]=] .. (forms["gen_du_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["gen_du_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["gen_du_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | dative
| ]=] .. (forms["dat_du_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["dat_du_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["dat_du_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | locative
| ]=] .. (forms["loc_du_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["loc_du_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["loc_du_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | instrumental
| ]=] .. (forms["ins_du_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["ins_du_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["ins_du_n"] or "&mdash;") .. [=[
 
|-
! colspan="4" style="background:#b3d7ff" | plural
|-
! style="background:#d9ebff" | 
! style="background:#d9ebff" | masculine
! style="background:#d9ebff" | feminine
! style="background:#d9ebff" | neuter
|-
! style="background:#eff7ff" | nominative
| ]=] .. (forms["nom_pl_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["nom_pl_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["nom_pl_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | accusative
| ]=] .. (forms["acc_pl_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["acc_pl_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["acc_pl_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | genitive
| ]=] .. (forms["gen_pl_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["gen_pl_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["gen_pl_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | dative
| ]=] .. (forms["dat_pl_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["dat_pl_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["dat_pl_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | locative
| ]=] .. (forms["loc_pl_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["loc_pl_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["loc_pl_n"] or "&mdash;") .. [=[
 
|-
! style="background:#eff7ff" | instrumental
| ]=] .. (forms["ins_pl_m"] or "&mdash;") .. [=[
 
| ]=] .. (forms["ins_pl_f"] or "&mdash;") .. [=[
 
| ]=] .. (forms["ins_pl_n"] or "&mdash;") .. [=[
 
|}</div></div>]=]
end
 
return export