Mô đun:sms-nominals
Giao diện
local lang = require("Module:languages").getByCode("sms")
local export = {}
-- Inflection functions
function export.even(frame)
local fparams = {
[1] = {required = true},
["nograd"] = {type = "boolean"},
}
local fargs = require("Module:parameters").process(frame.args, fparams)
local params = {
[1] = {required = true, default = "{{{1}}}"},
["attr"] = fargs[1] == "adjectives" and {list = true} or nil,
["n"] = fargs[1] == "nouns" and {} or nil,
["poss"] = fargs[1] == "nouns" and {} or nil,
["Q31"] = not fargs["nograd"] and {type = "boolean"} or nil,
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local stem = require("Module:sms-common").Stem(args[1], args["Q31"] and "Q31" or not fargs["nograd"])
local data = {
has_attr = fargs[1] == "adjectives",
has_poss = fargs[1] == "nouns" and not args["poss"],
forms = {},
info = "thân từ " .. require("Module:links").full_link({lang = lang, alt = stem.uvowel}, "term") .. " chẵn",
categories = {},
}
if stem.gradation then
data.info = data.info .. ", " .. "biến đổi " ..
require("Module:links").full_link({lang = lang, alt = stem.gradation.strong.scons:gsub("ʹ", "")}, "term") .. "-" ..
require("Module:links").full_link({lang = lang, alt = stem.gradation.weak.scons:gsub("ʹ", "")}, "term")
else
data.info = data.info .. ", không có biến đổi"
end
if not mw.ustring.find(stem.uvowel, "^[aáeioå]$") and mw.title.getCurrentTitle().nsText ~= "Template" then
--error("The final vowel(s) of the stem must be one of a, á, e, i, o, å.")
end
if fargs[1] == "nouns" and args["poss"] and args["poss"] ~= "-" then
else
table.insert(data.categories, lang:getCanonicalName() .. " even " .. fargs[1])
table.insert(data.categories, lang:getCanonicalName() .. " even " .. (stem.uvowel or "") .. "-stem " .. fargs[1])
if not stem.gradation then
table.insert(data.categories, lang:getCanonicalName() .. " non-gradating even " .. fargs[1])
end
data.forms["nom|s"] = {stem:make_form{grade = "strong", variant = "normal0"}}
data.forms["acc|s"] = {stem:make_form{grade = "weak", variant = "normal0"}}
data.forms["gen|s"] = {stem:make_form{grade = "weak", variant = "normal0"}}
data.forms["ill|s"] = {stem:make_form{grade = "extra", variant = "e"}}
data.forms["loc|s"] = {stem:make_form{grade = "weak", ending = "st"}}
data.forms["com|s"] = {stem:make_form{grade = "weak", ending = "in", variant = "j0"}}
data.forms["abe|s"] = {stem:make_form{grade = "weak", ending = "tää", variant = "normal0"}}
data.forms["nom|p"] = {stem:make_form{grade = "weak", variant = "normal0"}}
data.forms["acc|p"] = {stem:make_form{grade = "weak", ending = "id", variant = "j0"}}
data.forms["gen|p"] = {stem:make_form{grade = "weak", ending = "i", variant = "j0"}}
data.forms["ill|p"] = {stem:make_form{grade = "weak", ending = "id", variant = "j0"}}
data.forms["loc|p"] = {stem:make_form{grade = "weak", ending = "in", variant = "j0"}}
data.forms["com|p"] = {stem:make_form{grade = "weak", ending = "ivuiʹm", variant = "j0"}}
data.forms["abe|p"] = {stem:make_form{grade = "weak", ending = "itää", variant = "j0"}}
data.forms["ess"] = {stem:make_form{grade = "strong", ending = "n"}}
data.forms["par"] = {stem:make_form{grade = "strong", ending = "d"}}
end
postprocess(args, data)
return make_table(data)
end
function postprocess(args, data)
if args["poss"] then
data.has_poss = false
end
data.n = args["n"]
if args["n"] == "p" then
table.insert(data.categories, "Danh từ " .. lang:getCanonicalName() .. " chỉ có số nhiều")
elseif args["n"] == "s" then
table.insert(data.categories, "Danh từ " .. lang:getCanonicalName() .. " không đếm được")
elseif args["n"] then
error("args= must be \"s\" or \"p\".")
end
for key, form in pairs(data.forms) do
-- Do not show singular or plural forms for nominals that don't have them
if (args["n"] == "p" and key:find("|s$")) or (args["n"] == "s" and key:find("|p$")) then
form = nil
end
data.forms[key] = form
end
if data.has_attr then
if not args["attr"][1] then
data.forms["attr"] = mw.clone(data.forms["nom|s"])
elseif args["attr"][1] ~= "-" then
data.forms["attr"] = args["attr"]
end
end
data.lemma = (data.forms["nom|" .. (data.n or "s")] or data.forms["acc|" .. (data.n or "s")])[1]
-- Check if the lemma form matches the page name
if (lang:makeEntryName(data.lemma)) ~= mw.title.getCurrentTitle().text then
table.insert(data.categories, lang:getCanonicalName() .. " entries with inflection not matching pagename")
end
end
-- Make the table
function make_table(data)
local function repl(param)
local accel = true
local no_store = false
if param == "info" then
return mw.getContentLanguage():ucfirst(data.info or "")
elseif string.sub(param, 1, 1) == "!" then
no_store = true
param = string.sub(param, 2)
elseif string.sub(param, 1, 1) == "#" then
accel = false
param = string.sub(param, 2)
end
local forms = data.forms[param]
if not forms then
return "—"
end
local ret = {}
for key, subform in ipairs(forms) do
table.insert(ret, require("Module:links").full_link({lang = lang, term = subform, accel = accel and {form = param, lemma = data.lemma, no_store = no_store} or nil}))
end
return table.concat(ret, "<br/>")
end
local wikicode = {}
table.insert(wikicode, [=[
{| class="inflection-table vsSwitcher" data-toggle-category="inflection" style="border:solid 1px #CCCCFF; text-align: left;" cellspacing="1" cellpadding="2"
|- style="background: #E2F6E2; text-align: left;"
! class="vsToggleElement" colspan="3" | {{{info}}}]=])
if data.has_attr then
table.insert(wikicode, [=[
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Thuộc ngữ
| colspan="2" | {{{!attr}}}]=])
end
table.insert(wikicode, [=[
|- class="vsShow" style="background: #F2F2FF;"
! style="width: 8em; background: #E2F6E2;" | [[nominative|nom.]]
| style="width: 15em;" colspan="2" | {{{!nom|]=] .. (data.n or "s") .. [=[}}}
|- class="vsShow" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[genitive|gen.]]
| colspan="2" | {{{!gen|]=] .. (data.n or "s") .. [=[}}}]=])
if data.has_attr then
table.insert(wikicode, [=[
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | Thuộc ngữ
| colspan="2" | {{{attr}}}
]=])
end
table.insert(wikicode, [=[
|- class="vsHide"
! style="width: 8em; background: #C0E4C0;" |
! style="width: 12em; background: #C0E4C0;" | Số ít
! style="width: 12em; background: #C0E4C0;" | Số nhiều
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[nominative|nom.]]
| data-accel-col="1" | {{{nom|s}}}
| data-accel-col="2" | {{{nom|p}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[accusative|acc.]]
| data-accel-col="1" | {{{acc|s}}}
| data-accel-col="2" | {{{acc|p}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[genitive|gen.]]
| data-accel-col="1" | {{{gen|s}}}
| data-accel-col="2" | {{{gen|p}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[illative|ill.]]
| data-accel-col="1" | {{{ill|s}}}
| data-accel-col="2" | {{{ill|p}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[locative|loc.]]
| data-accel-col="1" | {{{loc|s}}}
| data-accel-col="2" | {{{loc|p}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[comitative|com.]]
| data-accel-col="1" | {{{com|s}}}
| data-accel-col="2" | {{{com|p}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[abessive|abe.]]
| data-accel-col="1" | {{{abe|s}}}
| data-accel-col="2" | {{{abe|p}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[essive|ess.]]
| colspan="2" | {{{ess}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | [[partitive|par.]]
| colspan="2" | {{{par}}}]=])
-- Possessive forms
if data.has_poss then
table.insert(wikicode, [=[
|- class="vsHide"
| colspan="3" style="padding: 0;" |
{| class="inflection-table vsSwitcher" style="text-align: left; width: 100%;" cellspacing="1" cellpadding="2"
|- style="background: #E2F6E2; text-align: left;"
! class="vsToggleElement" colspan="4" | Dạng sở hữu
|- class="vsHide"
! style="width: 8em; background: #C0E4C0;" |
! style="width: 12em; background: #C0E4C0;" | Số ít
! style="width: 12em; background: #C0E4C0;" | Số kép
! style="width: 12em; background: #C0E4C0;" | Số nhiều
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | ngôi thứ nhất
| {{{1|s|poss}}}
| {{{1|d|poss}}}
| {{{1|p|poss}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | ngôi thứ hai
| {{{2|s|poss}}}
| {{{2|d|poss}}}
| {{{2|p|poss}}}
|- class="vsHide" style="background: #F2F2FF;"
! style="background: #E2F6E2;" | ngôi thứ ba
| {{{3|s|poss}}}
| {{{3|d|poss}}}
| {{{3|p|poss}}}
|}]=])
end
table.insert(wikicode, "\n|}")
return mw.ustring.gsub(table.concat(wikicode), "{{{([#!]?[a-z0-9|]+)}}}", repl) .. require("Module:utilities").format_categories(data.categories, lang)
end
return export