Module:rad-stem/templates
Jump to navigation
Jump to search
--[[
WORK IN PROGRESS
]]--
local export = {}
local getArgs = require('Module:Arguments').getArgs
local m_stem = require("Module:rad-stem")
local m_parameters = require("Module:parameters")
local m_links = require("Module:links")
local m_languages = require("Module:languages")
function get_stems(args)
local shifted = {"noun", "_"}
local i = 1
while args[i] do
shifted[i+2] = args[i]
i = i + 1
end
return m_stem.getNounStem(shifted)
end
function break_adj(adj)
local C = "bcdðfghħjĵkķlmnņpqrsștvwxzþ°"
local temp = adj
temp = mw.ustring.gsub(temp, "([" .. C .. "])([" .. C .. "])íș$", "%1%2ieș")
temp = mw.ustring.gsub(temp, "(°)", "")
temp = mw.ustring.gsub(temp, "(íș)$", "jeș")
temp = mw.ustring.gsub(temp, "(úș)$", "uoș")
temp = mw.ustring.gsub(temp, "(ýș)$", "yeș")
temp = mw.ustring.gsub(temp, "(oș)$", "uș")
return temp
end
function rad_link(word)
return m_links.full_link{
term = word,
language = m_languages.get_by_code("rad")
}
end
function rad_IPA(word)
local IPA = require("Module:rad-IPA").generate{
word,
"format",
"nolarge"
}
return "<span style=\"color:dimgrey\">" .. IPA .. "</span>"
end
function rad_link_IPA(word)
if type(word) == "string" then
return rad_link(word) .. "<br>" .. rad_IPA(word)
elseif type(word) == "table" then
local links = {}
local IPAs = {}
for _, i in ipairs(word) do
local new_link = rad_link(i['word'])
if i['note'] then new_link = new_link .. " <small>(<i>" .. i['note'] .. "</i>)</small>" end
table.insert(links, new_link)
table.insert(IPAs, rad_IPA(i['word']))
end
return table.concat(links, ", ") .. "<br>" .. table.concat(IPAs, " ")
else error("Incompatible input type for rad_link_IPA")
end
end
function export.show(frame)
local args = getArgs(frame)
local stem_gen = get_stems(args)
local stems = {
nom = args['nom'] or stem_gen.nom,
acc = args['acc'] or stem_gen.acc,
dat = args['dat'] or stem_gen.dat,
gen = args['gen'] or stem_gen.gen,
ins = args['ins'] or stem_gen.ins,
nompl = args['nompl'] or stem_gen.nompl,
genpl = args['genpl'] or stem_gen.genpl,
genpl_short = args['genpl_short'] or stem_gen.genpl_short,
['type'] = stem_gen['type'],
}
local adj = args['adj']
local adj_broken = ""
local adj_broken_e = ""
if adj then
if not mw.ustring.match(adj, "(ș)$") then error("All adjectives must end in -ș") end
adj = " " .. adj
adj_broken = args['adjbreak'] or break_adj(adj)
adj_broken_e = mw.ustring.gsub(adj_broken, "(uș)$", "ûș")
adj_broken_e = mw.ustring.gsub(adj_broken, "(aûș)$", "auș")
adj_broken_e = mw.ustring.gsub(adj_broken, "(aùș)$", "aûș")
adj_broken_e = adj_broken_e .. "e"
adj = mw.ustring.gsub(adj, "(°)", "")
else
adj_broken = nil
adj_broken_e = nil
end
local post = args['post']
local format_table = {}
local decl_type = {
["C"] = "heavy",
["CH"] = "heavy spirant",
["VH"] = "light spirant",
["V"] = "light",
["G"] = "semi-light"
}
local type_name = decl_type[stems['type']]
local table_type = args['type'] or "sgpl"
local function add(code)
table.insert(format_table, code)
end
local function th(data, rowspan, colspan)
local to_add = "<th"
if rowspan and rowspan~=1 then to_add = to_add .. " rowspan=" .. rowspan end
if colspan and colspan~=1 then to_add = to_add .. " colspan=" .. colspan end
to_add = to_add .. ">" .. data .. "</th>"
add(to_add)
end
local function td(data, rowspan, colspan)
local to_add = "<td"
if rowspan and rowspan~=1 then to_add = to_add .. " rowspan=" .. rowspan end
if colspan and colspan~=1 then to_add = to_add .. " colspan=" .. colspan end
to_add = to_add .. ">" .. data .. "</td>"
add(to_add)
end
-- generate forms --
local nom = stems.nom
if adj_broken_e then nom = nom .. adj_broken_e end
if post then nom = nom .. post end
local nom_cite = nom
nom = rad_link_IPA(nom)
local gen = stems.gen
if adj_broken then gen = gen .. adj_broken .. "k" end
if post then gen = gen .. post end
if args['altgen'] then
local list = {
[1] = {['word'] = gen},
[2] = {['word'] = args['altgen'], ['note'] = args['altgen_note']}
}
if adj_broken then list[2]['word'] = list[2]['word'] .. adj_broken .. "k" end
if post then list[2]['word'] = list[2]['word'] .. post end
local counter = 2
while args['altgen' .. counter] do
local temp = args['altgen' .. counter]
if adj_broken then temp = temp .. adj_broken .. "k" end
if post then temp = temp .. post end
list[counter + 1] = {['word'] = temp, ['note'] = args['altgen' .. counter .. "_note"]}
counter = counter + 1
end
gen = rad_link_IPA(list)
else
gen = rad_link_IPA(gen)
end
add("<table class=\"mw-collapsible mw-collapsed wikitable inflection table\" style=\"text-align: center\">")
if table_type == "sgpl" then
th("Declension of <i>" .. nom_cite .. "</i> (" .. type_name .. ")  ", 1, 4)
add("<tr>")
th("nominative", 1, 2)
if nom == nompl then
td(nom, 1, 2)
else
td(nom)
end
add("</tr>")
add("<tr>")
th("genitive", 2, 1)
th("proper")
td(gen)
add("</tr>")
elseif table_type == "sg" then
elseif table_type == "pl" then
elseif table_type == "du" then
elseif table_type == "dupl" then
end
add("</table>")
add("<includeonly>")
add("[[Category:" .. m_languages.get_by_code("rad").name .. " " .. type_name .. " stems]]")
if table_type == "sg" then add("[[Category:" .. m_languages.get_by_code("rad").name .. " singularia tantum]]")
elseif table_type == "pl" then add("[[Category:" .. m_languages.get_by_code("rad").name .. " pluralia tantum]]")
elseif table_type == "du" then add("[[Category:" .. m_languages.get_by_code("rad").name .. " pluralia binaria]]")
elseif table_type == "dupl" then add("[[Category:" .. m_languages.get_by_code("rad").name .. " pluralia binaria tantum]]")
end
add("</includeonly>")
return table.concat(format_table, string.char(10))
end
return export
--[[
Debug console test string:
=p.show(mw.getCurrentFrame():newChild{title="whatever",args={"hv", "o~u^u", "þ"}})
]]--