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")
local m_ipa = require("Module:rad-IPA")
local C = "bcdðfghħjĵkķlmnņpqrsștvwxzþ°"
local format_table = {}
function add(code)
table.insert(format_table, code)
end
function tr()
table.insert(format_table, "<tr>")
end
function tr_()
table.insert(format_table, "</tr>")
end
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
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
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 temp = adj
temp = mw.ustring.gsub(temp, "([" .. C .. "])([" .. C .. "])íș$", "%1%2ieș")
temp = mw.ustring.gsub(temp, "([jșxķ])íș$", "%1ieș")
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 = m_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['note'] .. ")</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.decline(frame)
local args = getArgs(frame)
local stem_gen = get_stems(args)
local stems = {
nom = args['nom'] or stem_gen.nom,
voc = args['voc'] or stem_gen.voc,
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_broken = args['adjbreak'] or break_adj(adj)
adj_broken_e = mw.ustring.gsub(adj_broken, "(uș)$", "ûș")
adj_broken_e = mw.ustring.gsub(adj_broken_e, "(aûș)$", "auș")
adj_broken_e = mw.ustring.gsub(adj_broken_e, "(aùș)$", "aûș")
adj_broken_e = adj_broken_e .. "e"
adj = mw.ustring.gsub(adj, "(°)", "")
adj = " " .. adj
adj_broken = " " .. adj_broken
adj_broken_e = " " .. adj_broken_e
else
adj_broken = nil
adj_broken_e = nil
end
local post = args['post']
format_table = {}
local decl_type = {
["C"] = "heavy",
["CH"] = "spirant",
["VH"] = "spirant",
["V"] = "light",
["G"] = "semi-light"
}
local type_name = decl_type[stems['type']]
local table_type = args['type'] or args['t'] or "sgpl"
-- generate forms --
local function get_forms(case, base, adj_base, adj_ending, nolink)
if adj_base then
--adjust definite article --
local oblique_pl = {['genpl'] = true, ['datpl'] = true, ['accpl'] = true, ['inspl'] = true, ['gendu'] = true, ['datdu'] = true, ['accdu'] = true, ['insdu'] = true,}
-- detect inanimate --
if mw.ustring.match(mw.ustring.lower(adj_base), "^( ?a [" .. C .. "])") or mw.ustring.match(adj_base, "^( ag )") then
if oblique_pl[case] then
adj_base = mw.ustring.gsub(adj_base, "^( ?)ag ([iíỉIÍỈ])", "%1a’ %2")
adj_base = mw.ustring.gsub(adj_base, "^( ?)ag? ", "%1ai ")
elseif case == "genpl_short" or case == "gendu_short" then
adj_base = mw.ustring.gsub(adj_base, "^( ?)ag? ", "%1ais ")
end
end
-- append --
base = base .. adj_base
if adj_ending then base = base .. adj_ending end
end
if post then base = base .. post end
if args['alt' .. case] then
local list = {
[1] = {['word'] = base},
[2] = {['word'] = args['alt' .. case], ['note'] = args['alt' .. case .. '_note']}
}
if adj_base then
list[2]['word'] = list[2]['word'] .. adj_base
if adj_ending then list[2]['word'] = list[2]['word'] .. adj_ending end
end
if post then list[2]['word'] = list[2]['word'] .. post end
local counter = 2
while args['alt' .. case .. counter] do
local temp = args['alt' .. case .. counter]
if adj_base then
temp = temp .. adj_base
if adj_ending then temp = temp .. adj_ending end
end
if post then temp = temp .. post end
list[counter + 1] = {['word'] = temp, ['note'] = args['alt' .. case .. counter .. "_note"]}
counter = counter + 1
end
if nolink then
return list[1].word
else
return rad_link_IPA(list)
end
else
if nolink then
return base
else
return rad_link_IPA(base)
end
end
end
local nom = ""
local nom_cite = ""
if table_type == "adj" then
nom = get_forms("nom", stems.nompl, adj_broken_e)
nom_cite = get_forms("nom", stems.nompl, adj_broken_e, "", true)
else
nom = get_forms("nom", stems.nom, adj_broken_e)
nom_cite = get_forms("nom", stems.nom, adj_broken_e, "", true)
end
local voc = get_forms("voc", stems.voc, adj_broken_e)
local gen = get_forms("gen", stems.gen, adj_broken, "k")
local dat = get_forms("dat", stems.dat, adj, "a")
local acc = get_forms("acc", stems.acc, adj_broken, "t")
local ins = get_forms("ins", stems.ins, adj, "úr")
local nompl = get_forms("nompl", stems.nompl, adj_broken_e)
local nompl_cite = get_forms("nompl", stems.nompl, adj_broken_e, "", true)
local genpl = get_forms("genpl", stems.genpl .. "ris", adj, "eris")
local genpl_short = get_forms("genpl_short", stems.genpl_short, adj, "es")
local datpl = get_forms("genpl", stems.genpl .. "rín", adj, "erín")
local accpl = get_forms("accpl", stems.genpl .. "rid", adj, "erid")
local inspl = get_forms("inspl", stems.genpl .. "ríe", adj, "eríe")
local nomdu = get_forms("nomdu", stems.dat .. "te", adj_broken_e)
local nomdu_cite = get_forms("nomdu", stems.dat .. "te", adj_broken_e, "", true)
local gendu = get_forms("gendu", stems.dat .. "tis", adj, "eris")
local gendu_short = get_forms("gendu_short", stems.dat .. "ts", adj, "es")
local datdu = get_forms("datdu", stems.dat .. "tín", adj, "erín")
local accdu = get_forms("accdu", stems.dat .. "tid", adj, "erid")
local insdu = get_forms("insdu", stems.dat .. "tíe", adj, "eríe")
add("<table class=\"mw-collapsible mw-collapsed wikitable inflection table\" style=\"text-align: center\">")
if table_type == "sgpl" or table_type == "adj" then
if table_type == "adj" then
th("Substantive declension of <i>" .. nom_cite .. "</i> ", 1, 4)
else
th("Declension of <i>" .. nom_cite .. "</i> (" .. type_name .. ") ", 1, 4)
end
tr()
th("", 1, 2)
th("singular")
th("plural")
tr_()
tr()
th("nominative", 1, 2)
if nom == nompl then
td(nompl, 2, 2)
elseif nom == voc then
td(nom, 2)
td(nompl, 2)
else
td(nom)
td(nompl, 2)
end
tr_()
tr()
th("vocative", 1, 2)
if nom ~= nompl and nom ~= voc then td(voc) end
tr_()
tr()
th("genitive", 2, 1)
th("long")
td(gen, 2, 1)
td(genpl)
tr_()
tr()
th("short")
td(genpl_short)
tr_()
tr()
th("dative", 1, 2)
td(dat)
td(datpl)
tr_()
tr()
th("accusative", 1, 2)
td(acc)
td(accpl)
tr_()
tr()
th("instrumental", 1, 2)
td(ins)
td(inspl)
tr_()
elseif table_type == "sg" then
th("Declension of <i>" .. nom_cite .. "</i> (" .. type_name .. ") ", 1, 2)
tr()
th("")
th("singular")
tr_()
tr()
th("nominative")
if nom == voc then td(nom, 2) else td(nom) end
tr_()
tr()
th("vocative")
if nom ~= voc then td(voc) end
tr_()
tr()
th("genitive")
td(gen)
tr_()
tr()
th("dative")
td(dat)
tr_()
tr()
th("accusative")
td(acc)
tr_()
tr()
th("instrumental")
td(ins)
tr_()
elseif table_type == "pl" then
th("Declension of <i>" .. nompl_cite .. "</i> (" .. type_name .. ") ", 1, 3)
tr()
th("", 1, 2)
th("plural")
tr_()
tr()
th("nominative", 1, 2)
td(nompl, 2)
tr_()
tr()
th("vocative", 1, 2)
tr_()
tr()
th("genitive", 2, 1)
th("long")
td(genpl)
tr_()
tr()
th("short")
td(genpl_short)
tr_()
tr()
th("dative", 1, 2)
td(datpl)
tr_()
tr()
th("accusative", 1, 2)
td(accpl)
tr_()
tr()
th("instrumental", 1, 2)
td(inspl)
tr_()
elseif table_type == "du" then
th("Declension of <i>" .. nom_cite .. "</i> (" .. type_name .. ") ", 1, 5)
tr()
th("", 2, 2)
th("singular", 2, 1)
th("plural", 1, 2)
tr_()
tr()
th("binary")
th("true")
tr_()
tr()
th("nominative", 1, 2)
if nom == voc then td(nom, 2) else td(nom) end
td(nomdu, 2)
td(nompl, 2)
tr_()
tr()
th("vocative", 1, 2)
if nom ~= voc then td(voc) end
tr_()
tr()
th("genitive", 2, 1)
th("long")
td(gen, 2, 1)
td(gendu)
td(genpl)
tr_()
tr()
th("short")
td(gendu_short)
td(genpl_short)
tr_()
tr()
th("dative", 1, 2)
td(dat)
td(datdu)
td(datpl)
tr_()
tr()
th("accusative", 1, 2)
td(acc)
td(accdu)
td(accpl)
tr_()
tr()
th("instrumental", 1, 2)
td(ins)
td(insdu)
td(inspl)
tr_()
elseif table_type == "dupl" then
th("Declension of <i>" .. nomdu_cite .. "</i> (" .. type_name .. ") ", 1, 3)
tr()
th("", 1, 2)
th("binary plural")
tr_()
tr()
th("nominative", 1, 2)
td(nomdu, 2)
tr_()
tr()
th("vocative", 1, 2)
tr_()
tr()
th("genitive", 2, 1)
th("long")
td(gendu)
tr_()
tr()
th("short")
td(gendu_short)
tr_()
tr()
th("dative", 1, 2)
td(datdu)
tr_()
tr()
th("accusative", 1, 2)
td(accdu)
tr_()
tr()
th("instrumental", 1, 2)
td(insdu)
tr_()
end
add("</table>")
if args['notags'] ~= "true" or args['notags'] == nil then
if table_type ~= "adj" then
add("[[Category:" .. m_languages.get_by_code("rad").name .. " " .. type_name .. " stems]]")
end
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]]" .. "[[Category:" .. m_languages.get_by_code("rad").name .. " pluralia binaria tantum]]")
end
end
return table.concat(format_table, string.char(10))
end
function export.conjugate(frame)
local args = getArgs(frame)
local pp = m_stem.getVerbStem(args)
mw.logObject(pp)
format_table = {}
if (args["t"] == "tr" or args["t"] == "pass") and args[6] == nil and args[7] == nil then error("Passive conjugation tables require arguments 6 (infinitive) and 7 (present participle stem).") end
add("<small>")
add("<table class=\"mw-collapsible mw-collapsed wikitable inflection table\" width=100% style=\"text-align: center\">")
tr()
th("Conjugation of ''" .. pp.inf .. "'' (active voice) ", 1, 14)
tr_()
add("</table>")
add("</small")
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", "þ"}})
=p.conjugate(mw.getCurrentFrame():newChild{title="whatever",args={"deat","de",["1s"]="dei",["3s"]="deaș",["pl"]="di","diș","deti","dev"}})
]]--