Module:qhv-noun: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 4: Line 4:


local m_utils = require("Module:utilities")
local m_utils = require("Module:utilities")
local m_data = require('Module:qhv-noun/data')


local export = {}
local export = {}
Line 16: Line 17:
["3-t"] = "on", ["3-a"] = "or", ["4-l"] = "e", ["4-s"] = "es", ["4-t"] = "ien", ["5-l"] = "i", ["5-s"] = "is", ["5-a"] = "ir",
["3-t"] = "on", ["3-a"] = "or", ["4-l"] = "e", ["4-s"] = "es", ["4-t"] = "ien", ["5-l"] = "i", ["5-s"] = "is", ["5-a"] = "ir",
}
}
local function ncategories(categories)
local out_categories = {}
for key, cat in ipairs(categories) do
out_categories[key] = "[[Category:" .. cat .. "]]"
end
return table.concat(out_categories, "")
end


local function detect_decl(word, decl, class)
local function detect_decl(word, decl, class)
Line 27: Line 37:
end
end
end
end
-- No matches, assume sixth declension. Now check for reanalyzed paucals or collectives
-- No matches, assume sixth-declension loanwords
return "6", word
end
end
 
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local parent_args = frame:getParent().args
local stems = nil
local declension_type = {}
local word = mw.title.getCurrentTitle().text
local args = {}
 
if not m_data[word] then
if frame.args.decl then
declension_type = frame.args.decl
else
if parent_args.stem and parent_args.g and parent_args[1] then
declension_type = parent_args.stem .. "-" .. parent_args.g
stems = {parent_args[1]}
else
declension_type, stems = detect_decl(word, parent_args.stem, parent_args.g)
end
end
if not declension_type then
error("Unknown declension '" .. declension_type .. "'")
end
args = require("Module:parameters").process(parent_args, m_data[declension_type].params, true)
if stems then
for i, stem in ipairs(stems) do
args[i] = stem
end
end
end
end
local data = {forms = {}, categories = {}}
m_data.head = parent_args["head"] or nil
-- 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
end
local stylesheet = require("Module:TemplateStyles")("Template:qhv-decl-noun/style.css")
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 repl(param)
if param == "decl_type" then
return m_data.decl_type
elseif param == "title" then
return m_data.forms.nom_sg[1]
else
return show_form(m_data.forms[param])
end
end
local function make_cases(data)
local cases = {"nominative", "accusative", "genitive", "dative", "locative", "instrumental", "comitative", "vocative"}
local ret = {}
for _, case in ipairs(cases) do
local case_short = sub(case, 1, 3)
table.insert(ret, "|- \n! class=\"case-header\" | " .. case .. "\n")
table.insert(ret, "| class=\"form-cell\" | " .. show_form(m_data.forms[case_short .. "_sg"]) .. "\n")
if m_data.forms[case_short .. "_pl"] or m_data.forms[case_short .. "_pa"] or m_data.forms[case_short .. "_co"] then
table.insert(ret, "| class=\"form-cell\" | " .. show_form(m_data.forms[case_short .. "_pl"]) .. "\n")
table.insert(ret, "| class=\"form-cell\" | " .. show_form(m_data.forms[case_short .. "_pa"]) .. "\n")
table.insert(ret, "| class=\"form-cell\" | " .. show_form(m_data.forms[case_short .. "_co"]) .. "\n")
end
end
return table.concat(ret)
end
local no_plural = m_data.forms.nom_pl == nil
local wikicode = [=[
{| class="prettytable mw-collapsible inflection-table-qhv"
|-
! class="corner-header" | Case
! class="number-header" | Singular]=] .. (no_plural and "\n" or [=[
! class="number-header" style="min-width: 11em; background-color:#F4E6AC" | Plural
! class="number-header" style="min-width: 11em; background-color:#F4E6AC" | Paucal
! class="number-header" style="min-width: 11em; background-color:#F4E6AC" | Collective
]=]) .. make_cases(data) .. [=[
|}]=]
return (gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. ncategories(m_data.categories)
end


return export
return export