Module:qhv-noun: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 27: Line 27:
end
end


local function detect_decl(word, decl, class)
local function detect_decl(word, number, class)
if decl and class then
if number and class then
local declension = decl .. "-" .. class
local decl = number .. "-" .. class
return declension, {sub(word, 1, -(#endings_reverse[declension] + 1))}
return decl, {sub(word, 1, -(#endings_reverse[decl] + 1))}
else
else
for ending, declension in pairs(endings) do
for ending, decl in pairs(endings) do
if find(word, ending .. "$") then
if find(word, ending .. "$") then
return declension, {sub(word, 1, -(#ending + 1))}
return decl, {sub(word, 1, -(#ending + 1))}
end
end
end
end
Line 47: Line 47:
local parent_args = frame:getParent().args
local parent_args = frame:getParent().args
local stems = nil
local numbers = nil
local declension_type = {}
local decl = {}
local word = mw.title.getCurrentTitle().text
local word = mw.title.getCurrentTitle().text
local args = {}
local args = {}
Line 54: Line 54:
if not m_data[word] then
if not m_data[word] then
if frame.args.decl then
if frame.args.decl then
declension_type = frame.args.decl
decl_type = frame.args.decl
else
else
if parent_args.stem and parent_args.g and parent_args[1] then
if parent_args.n and parent_args.c and parent_args[1] then
declension_type = parent_args.stem .. "-" .. parent_args.g
decl_type = parent_args.n .. "-" .. parent_args.c
stems = {parent_args[1]}
numbers = {parent_args[1]}
else
else
declension_type, stems = detect_decl(word, parent_args.stem, parent_args.g)
decl_type, numbers = detect_decl(word, parent_args.n, parent_args.c)
end
end
end
end
if not declension_type then
if not decl_type then
error("Unknown declension '" .. declension_type .. "'")
error("Unknown declension '" .. decl_type .. "'")
end
end
args = require("Module:parameters").process(parent_args, m_data[declension_type].params, true)
args = require("Module:parameters").process(parent_args, m_data[decl_type].params, true)
if stems then
if stems then
Line 77: Line 77:
end
end


local data = {forms = {}, categories = {}}
local pass = {forms = {}, categories = {}}
m_data.head = parent_args["head"] or nil
pass.head = parent_args["head"] or nil
-- Generate the forms
-- Generate the forms
if m_data[word] then
if m_data[word] then
m_data[word](parent_args, data)
m_data[word](parent_args, pass)
else
else
m_data[declension_type](args, data)
m_data[declension_type](args, pass)
end
end


-- Make the table
-- Make the table
return make_table(data)
return make_table(pass)
end
end


local stylesheet = require("Module:TemplateStyles")("Template:qhv-decl-noun/style.css")
local stylesheet = require("Module:TemplateStyles")("Template:qhv-decl-noun/style.css")


function make_table(data)
function make_table(pass)


local function show_form(form)
local function show_form(form)
Line 112: Line 112:
local function repl(param)
local function repl(param)
if param == "decl_type" then
if param == "decl_type" then
return m_data.decl_type
return pass.decl_type
elseif param == "title" then
elseif param == "title" then
return m_data.forms.nom_sg[1]
return pass.forms.nom_sg[1]
else
else
return show_form(m_data.forms[param])
return show_form(pass.forms[param])
end
end
end
end
Line 127: Line 127:
local case_short = sub(case, 1, 3)
local case_short = sub(case, 1, 3)
table.insert(ret, "|- \n! class=\"case-header\" | " .. case .. "\n")
table.insert(ret, "|- \n! class=\"case-header\" | " .. case .. "\n")
table.insert(ret, "| class=\"form-cell\" | " .. show_form(m_data.forms[case_short .. "_sg"]) .. "\n")
table.insert(ret, "| class=\"form-cell\" | " .. show_form(pass.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
if pass.forms[case_short .. "_pl"] or pass.forms[case_short .. "_pa"] or pass.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(pass.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(pass.forms[case_short .. "_pa"]) .. "\n")
table.insert(ret, "| class=\"form-cell\" | " .. show_form(m_data.forms[case_short .. "_co"]) .. "\n")
table.insert(ret, "| class=\"form-cell\" | " .. show_form(pass.forms[case_short .. "_co"]) .. "\n")
end
end
end
end
Line 137: Line 137:
end
end


local no_plural = m_data.forms.nom_pl == nil
local no_plural = pass.forms.nom_pl == nil


local wikicode = [=[
local wikicode = [=[
Line 149: Line 149:
! class="number-header" style="min-width: 11em; background-color:#F4E6AC" | Paucal
! class="number-header" style="min-width: 11em; background-color:#F4E6AC" | Paucal
! class="number-header" style="min-width: 11em; background-color:#F4E6AC" | Collective
! class="number-header" style="min-width: 11em; background-color:#F4E6AC" | Collective
]=]) .. make_cases(data) .. [=[
]=]) .. make_cases(pass) .. [=[
|}]=]
|}]=]


return (gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. ncategories(m_data.categories)
return (gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. ncategories(pass.categories)
end
end




return export
return export

Navigation menu