Módulo:decl.pl.adj
A documentação para este módulo pode ser criada na página Módulo:decl.pl.adj/doc
-- This module is inteded to contain functions that build declination tables for:
-- 1. Polish adjectives (not ready yet),
-- 2. Polish adjectival pronouns (working),
-- 3. Polish numerals (not ready yet).
local export = {}
-- Terminations for different types of declensions
local terminations = {}
terminations.y = {"ego", "emu", "ym", "a", "ej", "ą", "e", "ych", "ymi"} -- endings for adjectives that ends with -y
terminations.l = {"ego", "emu", "im", "a", "ej", "ą", "e", "ich", "imi"} -- endings for adjectives that ends with -i
terminations.i = {"iego", "iemu", "im", "ia", "iej", "ią", "ie", "ich", "imi"} -- endings with additional i where needed
terminations.j = {"jego", "jemu", "im", "ja", "jej", "ją", "je", "ich", "imi"} -- endings with additional j where needed
terminations.k = {"iego", "iemu", "im", "a", "iej", "ą", "ie", "ich", "imi"} -- endings with additional i where needed
-- Abbreviations for form names
-- Capital letters NGDAILV indicate case
-- Middle part (m, ma, mi, f, s, mp, nmp) indicate gender
-- Terminations (s, pl) indicate number
local abbrevFormNames = {"Nms", "Nfs", "Nns", "Nmppl", "Nnmppl",
"Gms", "Gfs", "Gns", "Gpl",
"Dms", "Dfs", "Dns", "Dpl",
"Amas", "Amis", "Afs", "Ans", "Amppl", "Anmppl",
"Ims", "Ifs", "Ins", "Ipl",
"Lms", "Lfs", "Lns", "Lpl",
"Vms", "Vfs", "Vns", "Vmppl", "Vnmppl"}
-- private functions for decl_pl_pron_adj
local decl_pl_pron_adj = {}
-- This function recognizes if the given adjectival pronoun is complex
-- and returns its main part in [pronoun] and the suffix in [suffix].
decl_pl_pron_adj.getComponents = function(pronoun)
local result = {}
-- cut off a suffix (-ś, -ż/-że, -kolwiek) or an additional word "bądź"
if mw.ustring.sub(pronoun, -1) == "ś" then
result.suffix = "ś"
result.pronoun = mw.ustring.sub(pronoun, 1, -2)
elseif mw.ustring.sub(pronoun, -1) == "ż" then
result.suffix = "ż"
result.pronoun = mw.ustring.sub(pronoun, 1, -2)
elseif mw.ustring.sub(pronoun, -2) == "że" then
result.suffix = "ż"
result.pronoun = mw.ustring.sub(pronoun, 1, -3)
elseif mw.ustring.sub(pronoun, -7) == "kolwiek" then
result.suffix = "kolwiek"
result.pronoun = mw.ustring.sub(pronoun, 1, -8)
elseif mw.ustring.sub(pronoun, -5) == " bądź" then
result.suffix = " bądź"
result.pronoun = mw.ustring.sub(pronoun, 1, -6)
else
-- result.suffix = nil
result.pronoun = pronoun
end
return result
end
-- This function extracts and returns the stem from the given adjectival pronoun in [stem]
-- and a type of declension of the pronoun in [declensionType].
-- Moreover:
-- - if the plural forms exist then the nominative plural virile form is returned in [Nmppl]
-- - if the nominative singular neuter form is irregular then it is returned in [Nns]
-- - if the accusative singular feminine form is irregular then it is returned in [Afs]
-- - if the argument is not an adjectival pronoun then "-" is returned in [Nms] and [stem]
decl_pl_pron_adj.getStemAndDeclensionType = function(pronoun)
local result = {}
local part
if pronoun == "sam" then
result.declensionType = "y"
result.stem = pronoun
result.Nmppl = "sami"
result.Nns = "samo"
elseif pronoun == "ów" then
result.declensionType = "y"
result.stem = "ow"
result.Nmppl = "owi"
result.Nns = "owo"
elseif pronoun == "ten" then
result.declensionType = "y"
result.stem = "t"
result.Nmppl = "ci"
result.Afs = "tę"
result.Nns = "to"
elseif pronoun == "tamten" then
result.declensionType = "y"
result.stem = "tamt"
result.Nmppl = "tamci"
result.Nns = "tamto"
elseif pronoun == "wszystek" then
result.declensionType = "k"
result.stem = "wszystk"
result.Nmppl = "wszyscy"
result.Nns = "wszystko"
elseif pronoun == "pewien" then
result.declensionType = "y"
result.stem = "pewn"
result.Nmppl = "pewni"
elseif pronoun == "każdy" then
result.declensionType = "y"
result.stem = "każd"
elseif mw.ustring.sub(pronoun, -2) == "ój" then
part = mw.ustring.sub(pronoun, 1, -3)
result.declensionType = "j"
result.stem = part .. "o" -- not actually a stem (but it is better to do it that way)
result.Nmppl = part .. "oi"
elseif mw.ustring.sub(pronoun, -1) == "j" then
result.declensionType = "j"
result.stem = mw.ustring.sub(pronoun, 1, -2) -- not actually a stem (but it is better to do it that way)
result.Nmppl = result.stem .. "i"
elseif mw.ustring.sub(pronoun, -2) == "sz" then
result.declensionType = "y"
result.stem = pronoun
result.Nmppl = mw.ustring.sub(pronoun, 1, -2) .. "i"
elseif mw.ustring.sub(pronoun, -2) == "ki" then
part = mw.ustring.sub(pronoun, 1, -3)
result.declensionType = "k"
result.stem = part .. "k"
result.Nmppl = part .. "cy"
elseif mw.ustring.sub(pronoun, -2) == "ry" then
result.declensionType = "y"
result.stem = mw.ustring.sub(pronoun, 1, -2)
result.Nmppl = result.stem .. "zy"
elseif mw.ustring.sub(pronoun, -1) == "y" then
result.declensionType = "y"
result.stem = mw.ustring.sub(pronoun, 1, -2)
result.Nmppl = result.stem .. "i"
elseif mw.ustring.sub(pronoun, -5) == "jeden" then
result.declensionType = "y"
result.stem = mw.ustring.sub(pronoun, 1, -3) .. "n"
result.Nmppl = result.stem .. "i"
result.Nns = result.stem .. "o"
elseif mw.ustring.sub(pronoun, -2) == "en" then
result.declensionType = "y"
result.stem = mw.ustring.sub(pronoun, 1, -3) .. "n"
result.Nmppl = result.stem .. "i"
else
result.declensionType = "y"
result.stem = "-"
result.Nms = "-"
result.Nmppl = "-"
end
return result
end
-- private tables and functions for tableConstruction
local tableConstruction = {}
-- Gender names for headers
tableConstruction.genderNamesForTableHeaders = {
"[[masculino|Masculino]]<br /><small>[[pessoal]]</small>",
"[[masculino|Masculino]]<br /><small>[[animado]]<br />não [[pessoal]]</small>",
"[[masculino|Masculino]]<br /><small>[[inanimado]]</small>",
"[[feminino|Feminino]]",
"[[neutro|Neutro]]",
"[[masculino|Masculino]] <small>[[inanimado]]</small><br /><small>ou [[animado]] não [[pessoal]]</small>",
"[[feminino|Feminino]], [[neutro|Neutro]]",
}
-- Case names for tables
tableConstruction.caseNamesForTables = {
"[[nominativo|Nominativo]]",
"[[genitivo|Genitivo]]",
"[[dativo|Dativo]]",
"[[acusativo|Acusativo]]",
"[[instrumental|Instrumental]]",
"[[locativo|Locativo]]",
"[[vocativo|Vocativo]]",
}
-- This function builds and returns the declension table of an adjective or adjectival pronoun
-- Optional arguments:
-- number equal to "s" (or "pl") indicates that only singular (or plural) forms should be visible,
-- tableTitle is the title of the table to be built,
-- singularTitle and pluralTitle are the titles of the parts of the table,
-- mainForms, inflectedForms and exceptions contain all forms of the pronoun to be included
-- hideVocative = false/nil indicates that vocative forms should be hidden
tableConstruction.getTable = function(number, tableTitle, singularTitle, pluralTitle, mainForms, inflectedForms, exceptions, hideVocative)
return [=[
<div class="NavFrame" style="clear:both;">
<div class="NavHead" align="center">]=] .. tableTitle .. [=[</div>
<div class="NavContent">
{| border="0" width="100%"
|- bgcolor="#fff" valign="top" align="center"
|
{| style="margin:0.5em 0.5em 0.5em 0.5em; border:1px solid #aaa; border-collapse:collapse;" cellpadding="3" rules="all"
]=]
.. tableConstruction.header(number, singularTitle, pluralTitle)
.. tableConstruction.rows(number, mainForms, inflectedForms, exceptions, hideVocative)
.. [=[
|-
|}
|-
|}
</div>
</div>]=]
end
-- This function returns an associative array with values "" or 'class="hiddenStructure"'
-- indicating if a row or a column in a table contaning ["s"]ingular, ["pl"]ural or ["vocative"] forms
-- should be hidden
-- Optional arguments:
-- number equal to "s" (or "pl") indicates that only singular (or plural) forms should be visible,
-- hideVocative = false/nil indicates that vocative forms should be hidden
tableConstruction.getHiddenStructureText = function(number, hideVocative)
local isHidden = {}
isHidden["s"] = (number == "pl") and 'class="hiddenStructure"' or ""
isHidden["pl"] = (number == "s") and 'class="hiddenStructure"' or ""
isHidden["vocative"] = hideVocative and 'class="hiddenStructure"' or ""
return isHidden
end
-- This function builds and returns the header for the declension table of an adjective or adjectival pronoun
-- Optional arguments:
-- number equal to "s" (or "pl") indicates that only singular (or plural) forms should be visible,
-- singularTitle and pluralTitle are the titles of the parts of the table,
tableConstruction.header = function(number, singularTitle, pluralTitle)
local isHidden = tableConstruction.getHiddenStructureText(number)
local genderNames = tableConstruction.genderNamesForTableHeaders
local header = '|- style="background:#ffffe0;" \n'
.. '! style="background:#f4f4f4;" rowspan="3" | [[caso#Substantivo|Caso]]\n'
.. '! colspan="5" ' .. isHidden["s"] .. ' | ' .. singularTitle .. '\n'
.. '! colspan="2" ' .. isHidden["pl"] .. ' | ' .. pluralTitle .. '\n'
.. '|- style="background:#ffffe0;"\n'
for i = 1, 5 do
header = header .. '! rowspan="2" ' .. isHidden["s"] .. ' | ' .. genderNames[i] .. '\n'
end
header = header .. '! rowspan="2" ' .. isHidden["pl"] .. ' | ' .. genderNames[1] .. '\n'
.. '! ' .. isHidden["pl"] .. ' | ' .. genderNames[6] .. '\n'
.. ' |- style="background:#ffffe0;" \n'
.. '! ' .. isHidden["pl"] .. ' | ' .. genderNames[7] .. '\n'
return header
end
-- This function builds and returns the rows for the declension table of an adjective or adjectival pronoun
-- Optional arguments:
-- number equal to "s" (or "pl") indicates that only singular (or plural) forms should be visible,
-- mainForms and inflectedForms and exceptions contain all forms of the pronoun to be included
-- hideVocative = false/nil indicates that vocative forms should be hidden
tableConstruction.rows = function(number, mainForms, inflectedForms, exceptions, hideVocative)
local isHidden = tableConstruction.getHiddenStructureText(number, hideVocative)
local caseNames = tableConstruction.caseNamesForTables
return ([=[
|- |+ align="center"
! style="background:#f4f4f4;" | %s
| colspan="3" %s | %s || %s | %s || %s | %s || %s | %s || %s | %s
|- |+ align="center"
! style="background:#f4f4f4;" | %s
| colspan="3" %s | %s || %s | %s || %s | %s || colspan="2" %s | %s
|- |+ align="center"
! style="background:#f4f4f4;" | %s
| colspan="3" %s | %s || %s | %s || %s | %s || colspan="2" %s | %s
|- |+ align="center"
! style="background:#f4f4f4;" | %s
| colspan="2" %s | %s || %s | %s || %s | %s || %s | %s || %s | %s || %s | %s
|- |+ align="center"
! style="background:#f4f4f4;" | %s
| colspan="3" %s | %s || %s | %s || %s | %s || colspan="2" %s | %s
|- |+ align="center"
! style="background:#f4f4f4;" | %s
| colspan="3" %s | %s || %s | %s || %s | %s || colspan="2" %s | %s
|- |+ align="center" %s
! style="background:#f4f4f4;" | %s
| colspan="3" %s | %s || %s | %s || %s | %s || %s | %s || %s | %s
]=]):format(
caseNames[1], -- nominative
isHidden["s"], (exceptions["Nms"] or mainForms[1]) or "{{{Nms}}}",
isHidden["s"], (exceptions["Nfs"] or inflectedForms[4]) or "{{{Nfs}}}",
isHidden["s"], (exceptions["Nns"] or inflectedForms[7]) or "{{{Nns}}}",
isHidden["pl"], (exceptions["Nmppl"] or mainForms[2]) or "{{{Nmppl}}}",
isHidden["pl"], (exceptions["Nnmppl"] or inflectedForms[7]) or "{{{Nnmppl}}}",
caseNames[2], -- genitive
isHidden["s"], (exceptions["Gms"] or inflectedForms[1]) or "{{{Gms}}}",
isHidden["s"], (exceptions["Gfs"] or inflectedForms[5]) or "{{{Gfs}}}",
isHidden["s"], (exceptions["Gns"] or inflectedForms[1]) or "{{{Gns}}}",
isHidden["pl"], (exceptions["Gpl"] or inflectedForms[8]) or "{{{Gpl}}}",
caseNames[3], -- dative
isHidden["s"], (exceptions["Dms"] or inflectedForms[2]) or "{{{Dms}}}",
isHidden["s"], (exceptions["Dfs"] or inflectedForms[5]) or "{{{Dfs}}}",
isHidden["s"], (exceptions["Dns"] or inflectedForms[2]) or "{{{Dns}}}",
isHidden["pl"], (exceptions["Dpl"] or inflectedForms[3]) or "{{{Dpl}}}",
caseNames[4], -- accusative
isHidden["s"], (exceptions["Amas"] or inflectedForms[1]) or "{{{Amas}}}",
isHidden["s"], (exceptions["Amis"] or mainForms[1]) or "{{{Amis}}}",
isHidden["s"], (exceptions["Afs"] or inflectedForms[6]) or "{{{Afs}}}",
isHidden["s"], (exceptions["Ans"] or inflectedForms[7]) or "{{{Ans}}}",
isHidden["pl"], (exceptions["Amppl"] or inflectedForms[8]) or "{{{Amppl}}}",
isHidden["pl"], (exceptions["Anmppl"] or inflectedForms[7]) or "{{{Anmppl}}}",
caseNames[5], -- instrumental
isHidden["s"], (exceptions["Ims"] or inflectedForms[3]) or "{{{Ims}}}",
isHidden["s"], (exceptions["Ifs"] or inflectedForms[6]) or "{{{Ifs}}}",
isHidden["s"], (exceptions["Ins"] or inflectedForms[3]) or "{{{Ins}}}",
isHidden["pl"], (exceptions["Ipl"] or inflectedForms[9]) or "{{{Ipl}}}",
caseNames[6], -- locative
isHidden["s"], (exceptions["Lms"] or inflectedForms[3]) or "{{{Lms}}}",
isHidden["s"], (exceptions["Lfs"] or inflectedForms[5]) or "{{{Lfs}}}",
isHidden["s"], (exceptions["Lns"] or inflectedForms[3]) or "{{{Lns}}}",
isHidden["pl"], (exceptions["Lpl"] or inflectedForms[8]) or "{{{Lpl}}}",
isHidden["vocative"], caseNames[7], -- vocative
isHidden["s"], (exceptions["Vms"] or mainForms[1]) or "{{{Vms}}}",
isHidden["s"], (exceptions["Vfs"] or inflectedForms[4]) or "{{{Vfs}}}",
isHidden["s"], (exceptions["Vns"] or inflectedForms[7]) or "{{{Vns}}}",
isHidden["pl"], (exceptions["Vmppl"] or mainForms[2]) or "{{{Vmppl}}}",
isHidden["pl"], (exceptions["Vnmppl"] or inflectedForms[7]) or "{{{Vnmppl}}}"
)
end
-- public functions
-- This function is intended to be used in Predefinição:decl.pl.pron.adj
-- It returns the declination table for an adjectival pronoun
function export.decl_pl_pron_adj(frame)
local parentArgs = frame:getParent().args
local hideVocative = ((parentArgs["vocativo"] or "") == "excluir") -- says if vocative forms should be hidden
local number = parentArgs["número"] or "" -- "s" for singular forms only, "pl" for plural
local Nms = parentArgs["Nms"] or mw.title.getCurrentTitle().text -- get nominative masculine singular form
local components = decl_pl_pron_adj.getComponents(Nms)
local data = decl_pl_pron_adj.getStemAndDeclensionType(components.pronoun)
-- build forms
local terminations = terminations[data.declensionType]
local inflectedForms = {}
if components.suffix then
-- inflected forms
for index, value in ipairs(terminations) do
inflectedForms[index] = data.stem .. value .. components.suffix
end
if components.suffix == "ż" then
inflectedForms[3] = inflectedForms[3] .. "e" -- -ymże, -imże
inflectedForms[5] = inflectedForms[5] .. "e" -- -ejże
inflectedForms[8] = inflectedForms[8] .. "e" -- -ychże, -ichże
end
-- nominative masculino pessoal plural is formally the second main form
data.Nmppl = data.Nmppl .. components.suffix
-- add suffixes to exceptions
data.Afs = data.Afs and (data.Afs .. components.suffix)
data.Nns = data.Nns and (data.Nns .. components.suffix)
-- the case when Nms is not an adjectival pronoun
if data.Nms then
data.Nms = data.Nms .. components.suffix
end
else
for index, value in ipairs(terminations) do
inflectedForms[index] = data.stem .. value
end
end
local mainForms = {data.Nms or Nms, data.Nmppl}
local exceptions = {}
exceptions.Afs = data.Afs or nil
exceptions.Nns = data.Nns or nil
exceptions.Ans = data.Nns or nil
exceptions.Vns = data.Nns or nil
for index, value in ipairs(abbrevFormNames) do
exceptions[value] = exceptions[value] or (parentArgs[value] and parentArgs[value] or nil)
end
local tableTitle = parentArgs["título"] or ("Declinação de <i>" .. Nms .. "</i>")
local singularTitle = (parentArgs.s == "g" and "[[género|Género]]" or "[[singular|Singular]]")
local pluralTitle = (parentArgs.pl == "g" and "[[género|Género]]" or "[[plural|Plural]]")
return tableConstruction.getTable(number, tableTitle, singularTitle, pluralTitle, mainForms, inflectedForms, exceptions, hideVocative)
end
return export