local m_utilities = require("Module:utilities")
local m_common = require("Module:sl-common")
local export = {}
-- Within this module, inflections are the functions that do the actual inflecting
-- by creating the forms of a noun. 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, "sl")
end
-- Masculine o-stem
inflections["masc"] = 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 anim = args["a"]; if not anim or anim == "" then anim = false else anim = true end
-- 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 nouns needing accents")
end
-- Is this a hard stem or a soft stem?
local oe = "o"
local title = "masculine " .. (anim and "an" or "inan") .. "imate"
if m_common.is_soft(full_stem) then
oe = "e"
title = title .. ", soft"
table.insert(categories, "Slovene masculine soft nouns")
else
title = title .. ", hard"
table.insert(categories, "Slovene masculine hard nouns")
end
-- Singular
forms["nom_sg"] = stem .. (final and "e" .. final or "")
forms["acc_sg"] = (anim and full_stem .. "a" or stem .. (final and "e" .. final or ""))
forms["gen_sg"] = full_stem .. "a"
forms["dat_sg"] = full_stem .. "u"
forms["loc_sg"] = full_stem .. "u"
forms["ins_sg"] = full_stem .. oe .. "m"
-- Dual
forms["nom_du"] = full_stem .. "a"
forms["acc_du"] = full_stem .. "a"
forms["gen_du"] = full_stem .. oe .. "v"
forms["dat_du"] = full_stem .. oe .. "ma"
forms["loc_du"] = full_stem .. "ih"
forms["ins_du"] = full_stem .. oe .. "ma"
-- Plural
forms["nom_pl"] = full_stem .. "i"
forms["acc_pl"] = full_stem .. "e"
forms["gen_pl"] = full_stem .. oe .. "v"
forms["dat_pl"] = full_stem .. oe .. "m"
forms["loc_pl"] = full_stem .. "ih"
forms["ins_pl"] = full_stem .. "i"
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_scriptutils.tag_text(m_links.language_link(subform, nil, "sl", nil, FULLPAGENAME), "sl", "Latn", nil)
end
forms[key] = table.concat(form, ",<br/>")
else
forms[key] = m_scriptutils.tag_text(m_links.language_link(form, nil, "sl", nil, FULLPAGENAME), "sl", "Latn", nil)
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"] .. "</i>" .. (title and " (" .. title .. ")" or "") .. [=[</div>
<div class="NavContent">
{| style="background:#F9F9F9;text-align:center;width:100%" class="inflection-table"
|-
! style="background:#d9ebff;width:16%" |
! style="background:#d9ebff;width:28%" | singular
! style="background:#d9ebff;width:28%" | dual
! style="background:#d9ebff;width:28%" | plural
|-
! style="background:#eff7ff" | nominative
| ]=] .. (forms["nom_sg"] or "—") .. [=[
| ]=] .. (forms["nom_du"] or "—") .. [=[
| ]=] .. (forms["nom_pl"] or "—") .. [=[
|-
! style="background:#eff7ff" | accusative
| ]=] .. (forms["acc_sg"] or "—") .. [=[
| ]=] .. (forms["acc_du"] or "—") .. [=[
| ]=] .. (forms["acc_pl"] or "—") .. [=[
|-
! style="background:#eff7ff" | genitive
| ]=] .. (forms["gen_sg"] or "—") .. [=[
| ]=] .. (forms["gen_du"] or "—") .. [=[
| ]=] .. (forms["gen_pl"] or "—") .. [=[
|-
! style="background:#eff7ff" | dative
| ]=] .. (forms["dat_sg"] or "—") .. [=[
| ]=] .. (forms["dat_du"] or "—") .. [=[
| ]=] .. (forms["dat_pl"] or "—") .. [=[
|-
! style="background:#eff7ff" | locative
| ]=] .. (forms["loc_sg"] or "—") .. [=[
| ]=] .. (forms["loc_du"] or "—") .. [=[
| ]=] .. (forms["loc_pl"] or "—") .. [=[
|-
! style="background:#eff7ff" | instrumental
| ]=] .. (forms["ins_sg"] or "—") .. [=[
| ]=] .. (forms["ins_du"] or "—") .. [=[
| ]=] .. (forms["ins_pl"] or "—") .. [=[
|}</div></div>]=]
end
return export