Module:iir-nominals
Appearance
- The following documentation is located at Module:iir-nominals/documentation. [edit] Categories were auto-generated by Module:module categorization. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local m_utilities = require("Module:utilities")
local m_links = require("Module:links")
local m_common = require("Module:ine-common")
local export = {}
local lang = require("Module:languages").getByCode("iir-pro")
local endings = {
["anim"] = {
["athem"] = {
["nom_sg"] = {"s"},
["voc_sg"] = {""},
["acc_sg"] = {"a"},
["gen_sg"] = {{stressed = "ás", unstressed = "s"}},
["abl_sg"] = {{stressed = "ás", unstressed = "s"}},
["dat_sg"] = {"áy"},
["loc_sg"] = {"", "i"},
["ins_sg"] = {{stressed = "áH", unstressed = "H"}},
["nom_du"] = {"(a)"},
["voc_du"] = {"(a)"},
["acc_du"] = {"(a)"},
["gen_du"] = "?",
["abl_du"] = "?",
["dat_du"] = "?",
["loc_du"] = "?",
["ins_du"] = "?",
["nom_pl"] = {"as"},
["voc_pl"] = {"as"},
["acc_pl"] = {"as"},
["gen_pl"] = {"áHam"},
["abl_pl"] = {"más"},
["dat_pl"] = {"más"},
["loc_pl"] = {"sú"},
["ins_pl"] = {"bʰí"},
},
["them"] = {
["nom_sg"] = {"ás"},
["voc_sg"] = {"á"},
["acc_sg"] = {"ám"},
["gen_sg"] = {"ásya"},
["abl_sg"] = {"ā́t"},
["dat_sg"] = {"ā́y"},
["loc_sg"] = {"áy"},
["ins_sg"] = {"áH"},
["nom_du"] = {"áH"},
["voc_du"] = {"áH"},
["acc_du"] = {"áH"},
["gen_du"] = "?",
["abl_du"] = "?",
["dat_du"] = "?",
["loc_du"] = "?",
["ins_du"] = "?",
["nom_pl"] = {"ā́s"},
["voc_pl"] = {"ā́s"},
["acc_pl"] = {"áns"},
["gen_pl"] = {"ā́m"},
["abl_pl"] = {"ámas"},
["dat_pl"] = {"ámas"},
["loc_pl"] = {"áyšu"},
["ins_pl"] = {"ā́š"},
},
},
["inan"] = {
["athem"] = {
["nom_sg"] = {""},
["voc_sg"] = {""},
["acc_sg"] = {""},
["nom_du"] = {"iH"},
["voc_du"] = {"iH"},
["acc_du"] = {"iH"},
["nom_pl"] = {"H"},
["voc_pl"] = {"H"},
["acc_pl"] = {"H"},
},
["them"] = {
["nom_sg"] = {"ám"},
["voc_sg"] = {"ám"},
["acc_sg"] = {"ám"},
["nom_du"] = {"áy(H)"},
["voc_du"] = {"áy(H)"},
["acc_du"] = {"áy(H)"},
["nom_pl"] = {"áH"},
["voc_pl"] = {"áH"},
["acc_pl"] = {"áH"},
},
},
["coll"] = {
["athem"] = {
["nom_sg"] = {"H"},
["voc_sg"] = {"H"},
["acc_sg"] = {"H"},
},
["them"] = {
["nom_sg"] = {"áH"},
["voc_sg"] = {"áH"},
["acc_sg"] = {"áH"},
},
},
}
-- Copy over endings which are the same for animate and inanimate.
for _, t in ipairs({"athem", "them"}) do
for cn, _ in pairs(endings["anim"][t]) do
if not endings["inan"][t][cn] then
endings["inan"][t][cn] = endings["anim"][t][cn]
end
if cn:find("_sg$") and not endings["coll"][t][cn] then
endings["coll"][t][cn] = endings["anim"][t][cn]
end
end
end
local endings_pron = {
["m"] = {
["nom_sg"] = {"ás"},
["acc_sg"] = {"ám"},
["gen_sg"] = {"ásya"},
["abl_sg"] = {"ásmā́t"},
["dat_sg"] = {"ásmay"},
["loc_sg"] = {"ásmi"},
["ins_sg"] = {"ánaH"},
["nom_du"] = {"áH"},
["acc_du"] = {"áH"},
["gen_du"] = "?",
["abl_du"] = "?",
["dat_du"] = "?",
["loc_du"] = "?",
["ins_du"] = "?",
["nom_pl"] = {"áy"},
["acc_pl"] = {"áns"},
["gen_pl"] = {"áysaHam"},
["abl_pl"] = {"áymas"},
["dat_pl"] = {"áymas"},
["loc_pl"] = {"áysu"},
["ins_pl"] = {"ṓys"},
},
["f"] = {
["nom_sg"] = {"áH"},
["acc_sg"] = {"áHa"},
["gen_sg"] = {"ásyaHs"},
["abl_sg"] = {"ásyaHs"},
["dat_sg"] = {"ásyaHay"},
["loc_sg"] = {"ásyaH"},
["ins_sg"] = {"áH(a)H"},
["nom_du"] = "?",
["acc_du"] = "?",
["gen_du"] = "?",
["abl_du"] = "?",
["dat_du"] = "?",
["loc_du"] = "?",
["ins_du"] = "?",
["nom_pl"] = {"áHas"},
["acc_pl"] = {"áHas"},
["gen_pl"] = {"áHsaHam"},
["abl_pl"] = {"áHmas"},
["dat_pl"] = {"áHmas"},
["loc_pl"] = {"áHsu"},
["ins_pl"] = {"áHbʰi"},
},
["n"] = {
["nom_sg"] = {"át"},
["acc_sg"] = {"át"},
["nom_du"] = {"áy"},
["acc_du"] = {"áy"},
["nom_pl"] = {"áH"},
["acc_pl"] = {"áH"},
},
}
-- Copy over endings which are the same for animate and inanimate.
for cn, _ in pairs(endings_pron["m"]) do
if not endings_pron["n"][cn] then
endings_pron["n"][cn] = endings_pron["m"][cn]
end
end
local function inflect(data, prefix, endings, stem1, stem2, loc_sg_stem)
stem2 = stem2 or stem1
-- Is the stem thematic?
local thematic_unstressed = false
if mw.ustring.find(stem1, "[aá]$") then
endings = mw.clone(endings.them or endings)
if mw.ustring.find(stem1, "[a]$") then
thematic_unstressed = true
end
stem1 = mw.ustring.gsub(stem1, "[aá]$", "")
stem2 = stem1
else
endings = endings.athem or endings
if mw.ustring.find(stem1, "[aá]H$") and stem1 == stem2 then
thematic_unstressed = true
end
end
if not loc_sg_stem then
if mw.ustring.find(stem2, "[áíĺḿńáŕúā́́]") then
loc_sg_stem = stem2
else
loc_sg_stem = stem1
end
end
local stem2_zero = stem2
if mw.ustring.find(stem1, "[iu]$") then
stem2_zero = mw.ustring.gsub(stem2, "á[wy]$", {["áw"] = "ú", ["áy"] = "í"})
end
local stem1_full = stem1
if stem1 ~= stem2 and mw.ustring.gsub(stem1, "as$", "as") == stem2 then
stem1_full = stem2
end
local nom_pl_stem = mw.ustring.gsub(stem1, "[íiu]$", {["í"] = "áy", ["i"] = "ay", ["u"] = "aw"})
-- Go over each case-number combination
for cn, cnendings in pairs(endings) do
if cnendings == "?" then
data.forms[(prefix and prefix .. "_" or "") .. cn] = {"?"}
elseif cnendings then
data.forms[(prefix and prefix .. "_" or "") .. cn] = {}
for _, cnending in ipairs(cnendings) do
local stem = stem1
-- Use stem2 if the ending can be stressed, stem1 otherwise
if cn == "loc_sg" then
stem = loc_sg_stem
elseif cn == "ins_sg" or cn == "abl_pl" or cn == "dat_pl" or cn == "loc_pl" or cn == "ins_pl" then
stem = stem2_zero
elseif (cn == "nom_du" or cn == "voc_du" or cn == "acc_du") then
stem = stem1_full
elseif (cn == "nom_pl" or cn == "voc_pl") and cnending == "es" then
stem = nom_pl_stem
elseif cnending.stressed or mw.ustring.find(cnending, "[áíĺḿńáŕúā́́]") then
stem = stem2
end
local ending = (thematic_unstressed and (cnending.unstressed or m_common.destress(cnending))) or cnending.stressed or cnending
local ending_unstr = cnending.unstressed
if (cn == "gen_sg" or cn == "abl_sg") and ending_unstr == "s" and mw.ustring.find(stem, "s$") then
ending_unstr = "as"
end
if mw.ustring.find(stem, "[iu]$") then
if cn == "acc_sg" and ending == "a" then
ending = "m"
elseif cn == "acc_pl" and ending == "as" then
ending = "ns"
end
end
if mw.ustring.find(stem, "[aáiíuú]H$") and cn == "nom_sg" and ending == "s" then
ending = ""
end
if not (cnending == "i" and mw.ustring.find(stem, "i$")) then
table.insert(data.forms[(prefix and prefix .. "_" or "") .. cn], m_common.add_ending(stem, ending, ending_unstr, cn == "nom_sg" and ending == "s"))
end
end
end
end
end
local function postprocess(data)
for key, form in pairs(data.forms) do
-- Do not show singular, dual or plural forms for nouns that don't have them
if (not data.sg and key:find("_sg$")) or (not data.du and key:find("_du$")) or (not data.pl and key:find("_pl$")) or (not data.coll and key:find("_coll$")) then
form = nil
end
data.forms[key] = form
end
end
function export.masc(frame)
local params = {
[1] = {required = true},
[2] = {},
["nom_sg"] = {},
["loc_sg"] = {},
["coll"] = {},
["coll2"] = {},
["coll_loc"] = {},
["ac"] = {},
["n"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
if mw.title.getCurrentTitle().nsText == "Template" then
args[1] = args[1] or "Háǵra"
end
args[2] = args[2] or args[1]
local data = {forms = {}, title = nil, categories = {}}
data.sg = true
data.du = true
data.pl = true
data.coll = false
data.voc = true
if args["n"] then
if not mw.ustring.find(args["n"], "s") then
data.sg = false
end
if not mw.ustring.find(args["n"], "d") then
data.du = false
end
if not mw.ustring.find(args["n"], "p") then
data.pl = false
end
end
if mw.ustring.find(args[1], "[aá]$") then
data.info = "Thematic"
table.insert(data.categories, lang:getCanonicalName() .. " thematic nouns")
elseif mw.ustring.find(args[1], "[aá]H$") and args[1] == args[2] then
data.info = "Thematic in " .. m_links.full_link({lang = lang, alt = "*-aH"}, "term")
table.insert(data.categories, lang:getCanonicalName() .. " thematic nouns in *-aH")
else
data.info = "Athematic"
if args["ac"] then
data.info = data.info .. ", " .. args["ac"]
table.insert(data.categories, lang:getCanonicalName() .. " " .. args["ac"] .. " nouns")
else
table.insert(data.categories, lang:getCanonicalName() .. " athematic nouns")
end
end
-- Create the forms
inflect(data, nil, endings["anim"], args[1], args[2], args["loc_sg"])
if args["nom_sg"] then
data.forms["nom_sg"] = {args["nom_sg"]}
end
-- Collective
if args["coll"] then
args["coll2"] = args["coll2"] or args["coll"]
data.coll = true
local tempdata = {forms = {}}
inflect(tempdata, nil, endings["coll"], args["coll"], args["coll2"], args["coll_loc"])
for cn, forms in pairs(tempdata.forms) do
if cn:find("_sg$") then
local coll = cn:gsub("_sg$", "_coll")
data.forms[coll] = forms
end
end
end
postprocess(data)
return make_table(data)
end
function export.neut(frame)
local params = {
[1] = {required = true},
[2] = {},
["loc_sg"] = {},
["coll"] = {},
["coll2"] = {},
["coll_loc"] = {},
["ac"] = {},
["n"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
if mw.title.getCurrentTitle().nsText == "Template" then
args[1] = args[1] or "wárǵo"
end
args[2] = args[2] or args[1]
local data = {forms = {}, title = nil, categories = {}}
data.sg = true
data.du = true
data.pl = true
data.coll = false
data.voc = true
if args["n"] then
if not mw.ustring.find(args["n"], "s") then
data.sg = false
end
if not mw.ustring.find(args["n"], "d") then
data.du = false
end
if not mw.ustring.find(args["n"], "p") then
data.pl = false
end
end
if mw.ustring.find(args[1], "[aá]$") then
data.info = "Thematic"
table.insert(data.categories, lang:getCanonicalName() .. " thematic nouns")
else
data.info = "Athematic"
if args["ac"] then
data.info = data.info .. ", " .. args["ac"]
table.insert(data.categories, lang:getCanonicalName() .. " " .. args["ac"] .. " nouns")
else
table.insert(data.categories, lang:getCanonicalName() .. " athematic nouns")
end
end
-- Create the forms
inflect(data, nil, endings["inan"], args[1], args[2], args["loc_sg"])
-- Collective
if args["coll"] then
args["coll2"] = args["coll2"] or args["coll"]
data.coll = true
local tempdata = {forms = {}}
inflect(tempdata, nil, endings["coll"], args["coll"], args["coll2"], args["coll_loc"])
for cn, forms in pairs(tempdata.forms) do
if cn:find("_sg$") then
local coll = cn:gsub("_sg$", "_coll")
data.forms[coll] = forms
end
end
end
postprocess(data)
return make_table(data)
end
function export.adj(frame)
local params = {
[1] = {required = true},
[2] = {},
["loc_sg"] = {},
[3] = {},
[4] = {},
["ac"] = {},
["n"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
if mw.title.getCurrentTitle().nsText == "Template" then
args[1] = args[1] or "náwa"
end
args[2] = args[2] or args[1]
local data = {forms = {}, title = nil, categories = {}}
data.genders = true
data.sg = true
data.du = true
data.pl = true
data.voc = true
if args["n"] then
if not mw.ustring.find(args["n"], "s") then
data.sg = false
end
if not mw.ustring.find(args["n"], "d") then
data.du = false
end
if not mw.ustring.find(args["n"], "p") then
data.pl = false
end
end
if mw.ustring.find(args[1], "[aá]$") then
data.info = "Thematic"
table.insert(data.categories, lang:getCanonicalName() .. " thematic adjectives")
if not args[3] then
args[3] = mw.ustring.gsub(args[1], "[aá]$", {["a"] = "aH", ["a"] = "aH", ["á"] = "áH", ["á"] = "áH"})
args[4] = args[3]
end
else
data.info = "Athematic"
if args["ac"] then
data.info = data.info .. ", " .. args["ac"]
table.insert(data.categories, lang:getCanonicalName() .. " " .. args["ac"] .. " adjectives")
else
table.insert(data.categories, lang:getCanonicalName() .. " athematic adjectives")
end
end
-- Create the forms
inflect(data, "m", endings["anim"], args[1], args[2], args["loc_sg"])
inflect(data, "f", endings["anim"], args[3], args[4])
inflect(data, "n", endings["inan"], args[1], args[2], args["loc_sg"])
postprocess(data)
return make_table(data)
end
function export.pron_adj(frame)
local params = {
[1] = {required = true},
["m_nom_sg"] = {},
["f_nom_sg"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
if mw.title.getCurrentTitle().nsText == "Template" then
args[1] = args[1] or "Hálya"
end
local data = {forms = {}, title = nil, categories = {}}
data.genders = true
data.sg = true
data.du = true
data.pl = true
data.voc = false
if mw.ustring.find(args[1], "[aá]$") then
data.info = "Thematic pronominal"
else
error("Thematic only for now.")
end
-- Create the forms
inflect(data, "m", endings_pron["m"], args[1])
inflect(data, "f", endings_pron["f"], args[1])
inflect(data, "n", endings_pron["n"], args[1])
data.forms["m_nom_sg"] = args["m_nom_sg"] and {args["m_nom_sg"]} or data.forms["m_nom_sg"]
data.forms["f_nom_sg"] = args["f_nom_sg"] and {args["f_nom_sg"]} or data.forms["f_nom_sg"]
postprocess(data)
return make_table(data)
end
local names = {
["nom"] = "nominative",
["voc"] = "vocative",
["acc"] = "accusative",
["gen"] = "genitive",
["abl"] = "ablative",
["dat"] = "dative",
["loc"] = "locative",
["ins"] = "instrumental",
["sg"] = "singular",
["du"] = "dual",
["pl"] = "plural",
["coll"] = "collective",
["m"] = "masculine",
["f"] = "feminine",
["n"] = "neuter",
}
-- Make the table
function make_table(data)
local function repl(param)
if param == "info" then
return mw.getContentLanguage():ucfirst(data.info or "")
end
local form = data.forms[param]
if not form or #form == 0 then
return "—"
end
local ret = {}
for key, subform in ipairs(form) do
table.insert(ret, m_links.full_link({lang = lang, alt = "*" .. subform}))
end
return table.concat(ret, ", ")
end
local numbers = {"sg", "du", "pl"}
local genders = {"x"}
local cases = {"nom", "acc", "gen", "abl", "dat", "loc", "ins"}
if data.voc then
table.insert(cases, 2, "voc")
end
if data.genders then
genders = {"m", "f", "n"}
elseif data.coll then
table.insert(numbers, "coll")
end
local first_number = "sg"
if not data.sg then
first_number = "du"
if not data.du then
first_number = "pl"
end
end
local wikicode = {}
table.insert(wikicode, "{| class=\"inflection-table vsSwitcher\" data-toggle-category=\"inflection\" style=\"background: #FAFAFA; border: 1px solid #d0d0d0; text-align: left;\" cellspacing=\"1\" cellpadding=\"2\"")
table.insert(wikicode, "|- style=\"background: #CCCCFF;\"\n! class=\"vsToggleElement\" colspan=\"" .. (#numbers + 1) .. "\" | {{{info}}}")
table.insert(wikicode, "|- class=\"vsShow\" style=\"background: #CCCCFF;\"")
table.insert(wikicode, "!")
if data.genders then
table.insert(wikicode, "! style=\"min-width: 11em; background: #CCCCFF;\" | " .. names["m"])
table.insert(wikicode, "! style=\"min-width: 11em; background: #CCCCFF;\" | " .. names["f"])
else
table.insert(wikicode, "! style=\"min-width: 11em; background: #CCCCFF;\" | " .. names[first_number])
if data.coll then
table.insert(wikicode, "! style=\"min-width: 11em; background: #CCCCFF;\" | " .. names["coll"])
end
end
table.insert(wikicode, "|- class=\"vsShow\" style=\"background: #F2F2FF;\"")
table.insert(wikicode, "! style=\"min-width: 8em; background: #E6E6FF;\" | " .. names["nom"])
if data.genders then
table.insert(wikicode, "| style=\"min-width: 11em;\" | {{{m_nom_" .. first_number .. "}}}")
table.insert(wikicode, "| style=\"min-width: 11em;\" | {{{f_nom_" .. first_number .. "}}}")
else
table.insert(wikicode, "| style=\"min-width: 11em;\" | {{{nom_" .. first_number .. "}}}")
if data.coll then
table.insert(wikicode, "| style=\"min-width: 11em;\" | {{{nom_coll}}}")
end
end
table.insert(wikicode, "|- class=\"vsShow\" style=\"background: #F2F2FF;\"")
table.insert(wikicode, "! style=\"min-width: 8em; background: #E6E6FF;\" | " .. names["gen"])
if data.genders then
table.insert(wikicode, "| style=\"min-width: 11em;\" | {{{m_gen_" .. first_number .. "}}}")
table.insert(wikicode, "| style=\"min-width: 11em;\" | {{{f_gen_" .. first_number .. "}}}")
else
table.insert(wikicode, "| style=\"min-width: 11em;\" | {{{gen_" .. first_number .. "}}}")
if data.coll then
table.insert(wikicode, "| style=\"min-width: 11em;\" | {{{gen_coll}}}")
end
end
for _, gender in ipairs(genders) do
table.insert(wikicode, "|- class=\"vsHide\" style=\"background: #CCCCFF;\"")
if data.genders then
table.insert(wikicode, "! " .. names[gender])
else
table.insert(wikicode, "!")
end
for _, number in ipairs(numbers) do
table.insert(wikicode, "! style=\"min-width: 11em; background: #CCCCFF;\" | " .. names[number])
end
for _, case in ipairs(cases) do
table.insert(wikicode, "|- class=\"vsHide\" style=\"background-color: #F2F2FF;\"\n! style=\"min-width: 8em; background-color: #E6E6FF;\" | " .. names[case])
for _, number in ipairs(numbers) do
if data.genders then
table.insert(wikicode, "| {{{" .. gender .. "_" .. case .. "_" .. number .. "}}}")
else
table.insert(wikicode, "| {{{" .. case .. "_" .. number .. "}}}")
end
end
end
end
table.insert(wikicode, [=[|}]=])
wikicode = table.concat(wikicode, "\n")
return (mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. m_utilities.format_categories(data.categories, lang)
end
return export