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 |
||
(125 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
local gsub = mw.ustring.gsub | local gsub = mw.ustring.gsub | ||
local find = mw.ustring.find | local find = mw.ustring.find | ||
local gmatch = mw.ustring.gmatch | |||
local u = mw.ustring.char | |||
local m_utils = require("Module:utilities") | local m_utils = require("Module:utilities") | ||
local | local syllables = require("Module:qhv-pron").write_stress | ||
local alldata = require('Module:qhv-noun/data') | |||
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ") | |||
local NAMESPACE = mw.title.getCurrentTitle().nsText | |||
local NONSYLLABIC = u(0x032F) -- non-syllabic, combining inverted breve below | |||
local DIPHTHONG = u(0x035C) -- double articulation, combining double breve below | |||
local lang = require("Module:languages").getByCode("qhv") | |||
local export = {} | local export = {} | ||
Line 10: | Line 20: | ||
local endings = { | 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", | ["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", | ["on"] = "3-t", ["or"] = "3-a", ["e"] = "4-l", ["es"] = "4-s", ["er"] = "4-a", ["ien"] = "4-t", ["i"] = "5-l", ["is"] = "5-s", ["ir"] = "5-a", | ||
} | } | ||
Line 16: | Line 26: | ||
["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", | ["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", | ["3-t"] = "on", ["3-a"] = "or", ["4-l"] = "e", ["4-s"] = "es", ["4-t"] = "ien", ["5-l"] = "i", ["5-s"] = "is", ["5-a"] = "ir", | ||
["6-u"] = "", ["3-s-h"] = "s", ["4-a"] = "er", | |||
} | } | ||
local | local reanalyzed_endings = { | ||
["[i]ar"] = "c-1", ["yn"] = "p-2", ["yr"] = "c-2", ["un"] = "p-3", ["ȳn"] = "p-3", ["[i]or"] = "c-3", ["in"] = "p-4", ["er"] = "c-4", | |||
["ir"] = "c-5", ["rjin"] = "p-5", | |||
} | |||
function export.detect_decl(word, number, class, reanalyzed) | |||
local syllables = require("Module:qhv-pron").write_stress(word, true) | |||
local IPA = require("Module:qhv-pron").crux(word) | |||
local | local vowel = "[aeiouy]ː?" | ||
if number and class then | if number and class then | ||
local decl = number .. "-" .. class | local decl = number .. "-" .. class | ||
return decl, {sub(word, 1, -(#endings_reverse[decl] + 1))} | return decl, {sub(word, 1, -(#endings_reverse[decl] + 1))} | ||
elseif word:find("illa$") then | |||
return "-illa", {sub(word, 1, -2)} | |||
elseif word == "skorlūs" then | |||
return "3-s-h", {sub(word, 1, -2)} | |||
elseif reanalyzed then | |||
for ending, decl in pairs(reanalyzed_endings) do | |||
if find(word, ending .. "$") then | |||
return "r-" .. decl, {sub(word, 1, -(#ending + 1))} | |||
end | |||
end | |||
elseif (not find(IPA, "ˈ")) and (find(IPA, NONSYLLABIC .. ".$") or find(IPA, DIPHTHONG .. vowel .. ".$") or find(IPA, "ː.$")) then | |||
return "3-s-h", {sub(word, 1, -2)} | |||
else | else | ||
for ending, decl in pairs(endings) do | for ending, decl in pairs(endings) do | ||
Line 37: | Line 59: | ||
end | end | ||
end | end | ||
end | end | ||
return "6", {word} | |||
end | end | ||
-- The main entry point. | -- The main entry point. | ||
function export.show(frame) | function export.show(frame) | ||
local parent_args = frame:getParent().args | local parent_args = frame:getParent().args | ||
Line 49: | Line 69: | ||
local numbers = nil | local numbers = nil | ||
local decl = {} | local decl = {} | ||
local word = | local word = NAMESPACE == "Template" and "vala" or parent_args.word or PAGENAME | ||
local reanalyzed = parent_args["r"] | |||
local args = {} | local args = {} | ||
if not | if not alldata[word] then | ||
if frame.args.decl then | if frame.args.decl then | ||
decl_type = frame.args.decl | decl_type = frame.args.decl | ||
Line 60: | Line 81: | ||
numbers = {parent_args[1]} | numbers = {parent_args[1]} | ||
else | else | ||
decl_type, numbers = detect_decl(word, parent_args.n, parent_args.c) | decl_type, numbers = export.detect_decl(word, parent_args.n, parent_args.c, reanalyzed) | ||
end | end | ||
end | end | ||
Line 68: | Line 89: | ||
end | end | ||
args = require("Module:parameters").process(parent_args, | args = require("Module:parameters").process(parent_args, alldata[decl_type].params, true) | ||
if | if numbers then | ||
for i, | for i, number in ipairs(numbers) do | ||
args[i] = | args[i] = number | ||
end | end | ||
end | end | ||
Line 80: | Line 101: | ||
pass.head = parent_args["head"] or nil | pass.head = parent_args["head"] or nil | ||
pass.proper = parent_args["proper"] and true or false | |||
pass.nocat = parent_args["nocat"] and true or false | |||
-- Generate the forms | -- Generate the forms | ||
if | if alldata[word] then | ||
alldata[word](parent_args, pass) | |||
else | else | ||
alldata[decl_type](args, pass) | |||
end | end | ||
Line 91: | Line 114: | ||
return make_table(pass) | return make_table(pass) | ||
end | end | ||
function make_table(pass) | function make_table(pass) | ||
Line 109: | Line 130: | ||
return table.concat(ret, ", ") | return table.concat(ret, ", ") | ||
end | 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) | local function repl(param) | ||
Line 115: | Line 145: | ||
elseif param == "title" then | elseif param == "title" then | ||
return pass.forms.nom_sg[1] | return pass.forms.nom_sg[1] | ||
elseif param == "pagename" and NAMESPACE == "Template" then | |||
return "vala" | |||
elseif param == "pagename" then | |||
return PAGENAME | |||
else | else | ||
return show_form(pass.forms[param]) | return show_form(pass.forms[param]) | ||
Line 126: | Line 160: | ||
for _, case in ipairs(cases) do | for _, case in ipairs(cases) do | ||
local case_short = sub(case, 1, 3) | local case_short = sub(case, 1, 3) | ||
table.insert(ret, "|- \n! | table.insert(ret, "|- \n! style=\"background-color: #dcffed;\ |" .. case .. "\n") | ||
table.insert(ret, "| | table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(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 | if pass.forms[case_short .. "_pl"] or pass.forms[case_short .. "_pa"] or pass.forms[case_short .. "_co"] then | ||
table.insert(ret, "| | table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(pass.forms[case_short .. "_pl"])) .. "\n") | ||
table.insert(ret, "| | table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(pass.forms[case_short .. "_pa"])) .. "\n") | ||
table.insert(ret, "| | table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(pass.forms[case_short .. "_co"])) .. "\n") | ||
end | end | ||
end | end | ||
Line 141: | Line 175: | ||
local wikicode = [=[ | local wikicode = [=[ | ||
{| class=" | {| 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 "3" or "6") .. [=[" | <span class="nowrap">Declension of ''<span lang="qhv">{{{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 | ||
! | ! style="min-width: 8em; background-color: #acf4cf" | Paucal | ||
! | ! style="min-width: 8em; background-color: #acf4cf" | Collective | ||
]=]) .. make_cases(pass) .. [=[ | ]=]) .. make_cases(pass) .. [=[ | ||
|}]=] | |}]=] | ||
return | |||
return gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl) .. (not pass.nocat and require("Module:utilities").format_categories(pass.categories, lang) or "") | |||
end | end | ||
return export | return export |
Latest revision as of 19:59, 17 July 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 gmatch = mw.ustring.gmatch
local u = mw.ustring.char
local m_utils = require("Module:utilities")
local syllables = require("Module:qhv-pron").write_stress
local alldata = require('Module:qhv-noun/data')
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local NAMESPACE = mw.title.getCurrentTitle().nsText
local NONSYLLABIC = u(0x032F) -- non-syllabic, combining inverted breve below
local DIPHTHONG = u(0x035C) -- double articulation, combining double breve below
local lang = require("Module:languages").getByCode("qhv")
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", ["er"] = "4-a", ["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",
["6-u"] = "", ["3-s-h"] = "s", ["4-a"] = "er",
}
local reanalyzed_endings = {
["[i]ar"] = "c-1", ["yn"] = "p-2", ["yr"] = "c-2", ["un"] = "p-3", ["ȳn"] = "p-3", ["[i]or"] = "c-3", ["in"] = "p-4", ["er"] = "c-4",
["ir"] = "c-5", ["rjin"] = "p-5",
}
function export.detect_decl(word, number, class, reanalyzed)
local syllables = require("Module:qhv-pron").write_stress(word, true)
local IPA = require("Module:qhv-pron").crux(word)
local vowel = "[aeiouy]ː?"
if number and class then
local decl = number .. "-" .. class
return decl, {sub(word, 1, -(#endings_reverse[decl] + 1))}
elseif word:find("illa$") then
return "-illa", {sub(word, 1, -2)}
elseif word == "skorlūs" then
return "3-s-h", {sub(word, 1, -2)}
elseif reanalyzed then
for ending, decl in pairs(reanalyzed_endings) do
if find(word, ending .. "$") then
return "r-" .. decl, {sub(word, 1, -(#ending + 1))}
end
end
elseif (not find(IPA, "ˈ")) and (find(IPA, NONSYLLABIC .. ".$") or find(IPA, DIPHTHONG .. vowel .. ".$") or find(IPA, "ː.$")) then
return "3-s-h", {sub(word, 1, -2)}
else
for ending, decl in pairs(endings) do
if find(word, ending .. "$") then
return decl, {sub(word, 1, -(#ending + 1))}
end
end
end
return "6", {word}
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 "vala" or parent_args.word or PAGENAME
local reanalyzed = parent_args["r"]
local args = {}
if not alldata[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 = export.detect_decl(word, parent_args.n, parent_args.c, reanalyzed)
end
end
if not decl_type then
error("Unknown declension '" .. decl_type .. "'")
end
args = require("Module:parameters").process(parent_args, alldata[decl_type].params, true)
if numbers then
for i, number in ipairs(numbers) do
args[i] = number
end
end
end
local pass = {forms = {}, categories = {}}
pass.head = parent_args["head"] or nil
pass.proper = parent_args["proper"] and true or false
pass.nocat = parent_args["nocat"] and true or false
-- Generate the forms
if alldata[word] then
alldata[word](parent_args, pass)
else
alldata[decl_type](args, pass)
end
-- Make the table
return make_table(pass)
end
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 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 pass.decl_type
elseif param == "title" then
return pass.forms.nom_sg[1]
elseif param == "pagename" and NAMESPACE == "Template" then
return "vala"
elseif param == "pagename" then
return PAGENAME
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! style=\"background-color: #dcffed;\ |" .. case .. "\n")
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(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, "| style=\"background-color: #edfff6;\" | " .. link(show_form(pass.forms[case_short .. "_pl"])) .. "\n")
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(pass.forms[case_short .. "_pa"])) .. "\n")
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(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="]=] .. (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 "3" or "6") .. [=[" | <span class="nowrap">Declension of ''<span lang="qhv">{{{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
! style="min-width: 8em; background-color: #acf4cf" | Paucal
! style="min-width: 8em; background-color: #acf4cf" | Collective
]=]) .. make_cases(pass) .. [=[
|}]=]
return gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl) .. (not pass.nocat and require("Module:utilities").format_categories(pass.categories, lang) or "")
end
return export