Module:mg-noun: Difference between revisions
Jump to navigation
Jump to search
This module implements the noun inflection-table template
No edit summary |
No edit summary |
||
Line 69: | Line 69: | ||
data.proper = parent_args["proper"] and true or false | data.proper = parent_args["proper"] and true or false | ||
data.nocat = parent_args["nocat"] and true or false | data.nocat = parent_args["nocat"] and true or false | ||
data.nopl = parent_args["nopl"] and true or false | |||
-- Generate the forms | -- Generate the forms | ||
Line 112: | Line 113: | ||
return data.forms.nom_sg[1] | return data.forms.nom_sg[1] | ||
elseif param == "pagename" and NAMESPACE == "Template" then | elseif param == "pagename" and NAMESPACE == "Template" then | ||
return " | return "mazer" | ||
elseif param == "pagename" then | elseif param == "pagename" then | ||
return PAGENAME | return PAGENAME | ||
Line 121: | Line 122: | ||
local function make_cases(data) | local function make_cases(data) | ||
local cases = {" | local cases = {"direct", "dative", "locative"} | ||
local ret = {} | local ret = {} | ||
for _, case in ipairs(cases) do | for _, case in ipairs(cases) do | ||
local case_short = sub(case, 1, | local case_short = sub(case, 1, 2) | ||
table.insert(ret, "|- \n! style=\"background-color: #dcffed;\ |" .. case .. "\n") | table.insert(ret, "|- \n! style=\"background-color: #dcffed;\ |" .. case .. "\n") | ||
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(data.forms[case_short .. " | table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(data.forms[case_short .. "_s"])) .. "\n") | ||
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(data.forms[case_short .. "_p"])) .. "\n") | |||
end | end | ||
return table.concat(ret) | return table.concat(ret) | ||
end | end | ||
local no_plural = data.forms.nom_pl == nil | local no_plural = data.nopl or data.forms.nom_pl == nil | ||
local wikicode = [=[ | local wikicode = [=[ | ||
Line 143: | Line 140: | ||
{| class="]=] .. (no_plural and "" or "mw-collapsible") .. [=[" style="background: #edfff6; border: 1px solid #d0d0d0; text-align: left;" cellspacing="1" cellpadding="2" | {| class="]=] .. (no_plural and "" or "mw-collapsible") .. [=[" style="background: #edfff6; border: 1px solid #d0d0d0; text-align: left;" cellspacing="1" cellpadding="2" | ||
|- | |- | ||
|+ style="font-weight: bold; ]=] .. (no_plural and "" or "min-width: 27em") .. [=[" colspan="]=] .. (no_plural and " | |+ style="font-weight: bold; ]=] .. (no_plural and "" or "min-width: 27em") .. [=[" colspan="]=] .. (no_plural and "1" or "2") .. [=[" | <span class="nowrap">Declension of ''<span lang="cel-gal">{{{pagename}}}</span>'' ]=] .. (no_plural and "<br>" or "") .. [=[(<small>{{{decl_type}}}</small>)</span> | ||
|- | |- | ||
! style="min-width: 8em; background-color: #acf4cf" | | ! style="min-width: 8em; background-color: #acf4cf" | | ||
Line 149: | Line 146: | ||
! style="min-width: 8em; background-color: #acf4cf" | Plural | ! style="min-width: 8em; background-color: #acf4cf" | Plural | ||
]=]) .. make_cases(data) .. [=[ | ]=]) .. make_cases(data) .. [=[ | ||
|}]=] | |}]=] |
Revision as of 17:34, 5 September 2021
- The following documentation is located at Module:mg-noun/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module implements the noun inflection-table template
{{mg-decl-noun}}
.
local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local find = mw.ustring.find
local gmatch = mw.ustring.gmatch
local m_utils = require("Module:utilities")
local m_data = require('Module:mg-noun/data')
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local NAMESPACE = mw.title.getCurrentTitle().nsText
local lang = require("Module:languages").getByCode("cel-gal")
local export = {}
local function detect_decl(word, class)
local last = sub(word, 1, -1)
if class then
return class, {last}
elseif word:match("[aeor]$") then
return mw.ustring.upper(last), {last}
elseif word:match("n$") then
return "participle", {last}
end
return "consonant", {last}
end
-- The main entry point.
function export.show(frame)
local parent_args = frame:getParent().args
local numbers = nil
local decl = {}
local word = NAMESPACE == "Template" and "mazer" or parent_args.word or PAGENAME
local args = {}
local decl_type = ""
if not m_data[word] then
if frame.args.decl then
decl_type = frame.args.decl
else
if parent_args.c and parent_args[1] then
decl_type = parent_args.c
numbers = {parent_args[1]}
else
decl_type, numbers = detect_decl(word, parent_args.c)
end
end
decl_type = "R"
if not decl_type then
error("Unknown declension '" .. decl_type .. "'")
end
args = require("Module:parameters").process(parent_args, m_data[decl_type].params, true)
if numbers then
for i, number in ipairs(numbers) do
args[i] = number
end
end
end
local data = {forms = {}, categories = {}}
data.head = parent_args["head"] or nil
data.proper = parent_args["proper"] and true or false
data.nocat = parent_args["nocat"] and true or false
data.nopl = parent_args["nopl"] and true or false
-- Generate the forms
if m_data[word] then
m_data[word](parent_args, data)
else
m_data[decl_type](args, data)
end
-- Make the table
return make_table(data)
end
function make_table(data)
local function show_form(form)
if not form then
return "—"
end
local ret = {}
for key, subform in ipairs(form) do
table.insert(ret, subform)
end
return table.concat(ret, ", ")
end
local function link(term)
local links = {}
for alt in gmatch(term, "([^%s,]+)") do
alt = "[[Contionary:" .. alt .. "|" .. alt .. "]]"
table.insert(links, alt)
end
return table.concat(links, ", ")
end
local function repl(param)
if param == "decl_type" then
return data.decl_type
elseif param == "title" then
return data.forms.nom_sg[1]
elseif param == "pagename" and NAMESPACE == "Template" then
return "mazer"
elseif param == "pagename" then
return PAGENAME
else
return show_form(data.forms[param])
end
end
local function make_cases(data)
local cases = {"direct", "dative", "locative"}
local ret = {}
for _, case in ipairs(cases) do
local case_short = sub(case, 1, 2)
table.insert(ret, "|- \n! style=\"background-color: #dcffed;\ |" .. case .. "\n")
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(data.forms[case_short .. "_s"])) .. "\n")
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(data.forms[case_short .. "_p"])) .. "\n")
end
return table.concat(ret)
end
local no_plural = data.nopl or data.forms.nom_pl == nil
local wikicode = [=[
{| class="]=] .. (no_plural and "" or "mw-collapsible") .. [=[" style="background: #edfff6; border: 1px solid #d0d0d0; text-align: left;" cellspacing="1" cellpadding="2"
|-
|+ style="font-weight: bold; ]=] .. (no_plural and "" or "min-width: 27em") .. [=[" colspan="]=] .. (no_plural and "1" or "2") .. [=[" | <span class="nowrap">Declension of ''<span lang="cel-gal">{{{pagename}}}</span>'' ]=] .. (no_plural and "<br>" or "") .. [=[(<small>{{{decl_type}}}</small>)</span>
|-
! style="min-width: 8em; background-color: #acf4cf" |
! style="min-width: 8em; background-color: #acf4cf" | Singular]=] .. (no_plural and "\n" or [=[
! style="min-width: 8em; background-color: #acf4cf" | Plural
]=]) .. make_cases(data) .. [=[
|}]=]
return gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl) .. (not data.nocat and m_utils.format_categories(data.categories, lang) or "")
end
return export