Module:qhv-noun: Difference between revisions
Jump to navigation
Jump to search
This module generates automatic High Valyrian noun inflection tables through
No edit summary |
No edit summary |
||
Line 27: | Line 27: | ||
end | end | ||
local function detect_decl(word, | local function detect_decl(word, number, class) | ||
if | if number and class then | ||
local | local decl = number .. "-" .. class | ||
return | return decl, {sub(word, 1, -(#endings_reverse[decl] + 1))} | ||
else | else | ||
for ending, | for ending, decl in pairs(endings) do | ||
if find(word, ending .. "$") then | if find(word, ending .. "$") then | ||
return | 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 | local numbers = nil | ||
local | 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 | ||
decl_type = frame.args.decl | |||
else | else | ||
if parent_args. | if parent_args.n and parent_args.c and parent_args[1] then | ||
decl_type = parent_args.n .. "-" .. parent_args.c | |||
numbers = {parent_args[1]} | |||
else | else | ||
decl_type, numbers = detect_decl(word, parent_args.n, parent_args.c) | |||
end | end | ||
end | end | ||
if not | if not decl_type then | ||
error("Unknown declension '" .. | error("Unknown declension '" .. decl_type .. "'") | ||
end | end | ||
args = require("Module:parameters").process(parent_args, m_data[ | 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 | local pass = {forms = {}, categories = {}} | ||
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, | m_data[word](parent_args, pass) | ||
else | else | ||
m_data[declension_type](args, | m_data[declension_type](args, pass) | ||
end | end | ||
-- Make the table | -- Make the table | ||
return make_table( | 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( | 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 | return pass.decl_type | ||
elseif param == "title" then | elseif param == "title" then | ||
return | return pass.forms.nom_sg[1] | ||
else | else | ||
return show_form( | 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( | table.insert(ret, "| class=\"form-cell\" | " .. show_form(pass.forms[case_short .. "_sg"]) .. "\n") | ||
if | 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( | table.insert(ret, "| class=\"form-cell\" | " .. show_form(pass.forms[case_short .. "_pl"]) .. "\n") | ||
table.insert(ret, "| class=\"form-cell\" | " .. show_form( | table.insert(ret, "| class=\"form-cell\" | " .. show_form(pass.forms[case_short .. "_pa"]) .. "\n") | ||
table.insert(ret, "| class=\"form-cell\" | " .. show_form( | 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 = | 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( | ]=]) .. make_cases(pass) .. [=[ | ||
|}]=] | |}]=] | ||
return (gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. ncategories( | return (gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. ncategories(pass.categories) | ||
end | end | ||
return export | return export |
Revision as of 14:16, 10 February 2021
- The following documentation is located at Module:qhv-noun/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module generates automatic High Valyrian noun inflection tables through
{{qhv-decl-noun}}
. Do not use directly.
local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local find = mw.ustring.find
local m_utils = require("Module:utilities")
local m_data = require('Module:qhv-noun/data')
local export = {}
local endings = {
["a"] = "1-l", ["ar"] = "1-a", ["y"] = "2-l", ["ys"] = "2-s", ["o"] = "3-l", ["os"] = "3-s", ["ȳs"] = "3-s-v", ["ks"] = "3-s-k",
["on"] = "3-t", ["or"] = "3-a", ["e"] = "4-l", ["es"] = "4-s", ["ien"] = "4-t", ["i"] = "5-l", ["is"] = "5-s", ["ir"] = "5-a",
}
local endings_reverse = {
["1-l"] = "a", ["1-a"] = "ar", ["2-l"] = "y", ["2-s"] = "ys", ["3-l"] = "o", ["3-s"] = "os", ["3-s-v"] = "ȳs", ["3-s-k"] = "ks",
["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, number, class)
if number and class then
local decl = number .. "-" .. class
return decl, {sub(word, 1, -(#endings_reverse[decl] + 1))}
else
for ending, decl in pairs(endings) do
if find(word, ending .. "$") then
return decl, {sub(word, 1, -(#ending + 1))}
end
end
-- 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 numbers = nil
local decl = {}
local word = mw.title.getCurrentTitle().text
local args = {}
if not m_data[word] then
if frame.args.decl then
decl_type = frame.args.decl
else
if parent_args.n and parent_args.c and parent_args[1] then
decl_type = parent_args.n .. "-" .. parent_args.c
numbers = {parent_args[1]}
else
decl_type, numbers = detect_decl(word, parent_args.n, parent_args.c)
end
end
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 stems then
for i, stem in ipairs(stems) do
args[i] = stem
end
end
end
local pass = {forms = {}, categories = {}}
pass.head = parent_args["head"] or nil
-- Generate the forms
if m_data[word] then
m_data[word](parent_args, pass)
else
m_data[declension_type](args, pass)
end
-- Make the table
return make_table(pass)
end
local stylesheet = require("Module:TemplateStyles")("Template:qhv-decl-noun/style.css")
function make_table(pass)
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 pass.decl_type
elseif param == "title" then
return pass.forms.nom_sg[1]
else
return show_form(pass.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(pass.forms[case_short .. "_sg"]) .. "\n")
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(pass.forms[case_short .. "_pl"]) .. "\n")
table.insert(ret, "| class=\"form-cell\" | " .. show_form(pass.forms[case_short .. "_pa"]) .. "\n")
table.insert(ret, "| class=\"form-cell\" | " .. show_form(pass.forms[case_short .. "_co"]) .. "\n")
end
end
return table.concat(ret)
end
local no_plural = pass.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(pass) .. [=[
|}]=]
return (gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. ncategories(pass.categories)
end
return export