Module:ln-derivations
Jump to navigation
Jump to search
- The following documentation is located at Module:ln-derivations/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
For use in {{ln-derivations}}
.
--Based on [[Module:sw-derivations]]
local m_links = require("Module:links")
local lang = require("Module:languages").getByCode("ln")
local match = mw.ustring.match
local gsub = mw.ustring.gsub
local PAGENAME = mw.title.getCurrentTitle().text or ''
local export = {}
local classes = {
"appl",
"caus",
"pass",
"recip",
} --missing reversive/conversive
local classes_names = {
appl = "Applicative",
caus = "Causative",
pass = "Passive",
recip = "Reciprocal",
}
-- local function join_E_suffix(stem, suffix)
-- if match(stem, "[aiu][^aeiou]*$") then
-- return stem .. gsub(suffix, "E", "i")
-- elseif match(stem, "[oe][^aeiou]*$") then
-- return stem .. gsub(suffix, "E", "e")
-- else -- Default to an 'e'. Perhaps throw an error instead?
-- return stem .. gsub(suffix, "E", "e")
-- end
-- end
local auto_deriv = {}
auto_deriv.appl = function(lemma)
if match(lemma, "a$") then
return gsub(lemma, "a$", "ela")
elseif match(lemma, "[ɛɔ]$") then
return gsub(lemma, "[ɛɔ]$", "ɛlɛ")
end
return lemma
end
auto_deriv.caus = function(lemma)
if match(lemma, "[aɛɔ]$") then
return gsub(lemma, "[aɛɔ]$", "isa")
end
return lemma
end
auto_deriv.pass = function(lemma)
if match(lemma, "[aɛɔ]$") then
return gsub(lemma, "([aɛɔ])$", "%1m%1")
end
return lemma
end
auto_deriv.recip = function(lemma)
if match(lemma, "[aɛɔ]$") then
return gsub(lemma, "([aɛɔ])$", "%1n%1")
end
return lemma
end
local function pop_contains(arr, val)
for i, v in pairs(arr) do
if val == v then
table.remove(arr, i)
return true
end
end
return false
end
local function get_remaining(arr)
local out = {}
for _, v in ipairs(arr) do
table.insert(out, v)
end
return out
end
local function make_verb_row(lemma, code, autogen, forms, gloss)
if autogen and auto_deriv[code] then
local autoval = auto_deriv[code](lemma)
table.insert(forms, 1, autoval)
end
local row = {}
for i, term in pairs(forms) do
table.insert(row, m_links.full_link({ lang = lang, term = term, alt = '-' .. term, gloss = gloss[i] }))
end
return table.concat{"** ''", classes_names[code], "'': ", table.concat(row, ", ")}
end
local function make_other_verb_row(forms, gloss)
local row = {}
for i, term in pairs(forms) do
table.insert(row, m_links.full_link({ lang = lang, term = term, alt = '-' .. term, gloss = gloss[i] }))
end
table.sort(row)
return table.concat{"** ''Other formations'': ", table.concat(row, ", ")}
end
local function make_noun_row(term, gloss)
return table.concat{
"** ",
m_links.full_link({ lang = lang, term = term, gloss = gloss })
}
end
local function make_output(args)
local output = {}
local autogen = nil
local verb_output = {}
for _, code in ipairs(classes) do
autogen = pop_contains(args[1], code)
if autogen or #args[code] > 0 then
table.insert(verb_output, make_verb_row(args.lemma, code, autogen, args[code], args[code .. "-g"]))
end
end
if #args.vrb > 0 then
table.insert(verb_output, make_other_verb_row(args.vrb, args["vrb-g"]))
end
if #args[1] > 0 then
error('Unrecognized Lingala derivation type(s) "' .. table.concat(get_remaining(args[1]), '", "') .. '".')
end
if #verb_output > 0 then
table.insert(verb_output, 1, "* '''Verbal derivations''':")
table.insert(output, table.concat(verb_output, "\n"))
end
local noun_output = {}
for i, noun in pairs(args.nom) do
table.insert(noun_output, make_noun_row(noun, args["nom-g"][i]))
end
if #noun_output > 0 then
table.sort(noun_output)
table.insert(noun_output, 1, "* '''Nominal derivations''':")
table.insert(output, table.concat(noun_output, "\n"))
end
local other_output = {}
for i, other in pairs(args.other) do
table.insert(other_output, make_noun_row(other, args["other-g"][i]))
end
if #other_output > 0 then
table.sort(other_output)
table.insert(other_output, 1, "* '''Other derivations''':")
table.insert(output, table.concat(other_output, "\n"))
end
return table.concat(output, "\n\n")
end
function export.show(frame)
local params = {
--verbal derivatives
[1] = {list = true},
["appl"] = {list = true},
["appl-g"] = {list = true, allow_holes=true},
["caus"] = {list = true},
["caus-g"] = {list = true, allow_holes=true},
["conv"] = {list = true},
["conv-g"] = {list = true, allow_holes=true},
["pass"] = {list = true},
["pass-g"] = {list = true, allow_holes=true},
["recip"] = {list = true},
["recip-g"] = {list = true, allow_holes=true},
["stat"] = {list = true},
["stat-g"] = {list = true, allow_holes=true},
-- other verbal formations
["vrb"] = {list = true},
["vrb-g"] = {list = true, allow_holes=true},
-- nominal derivatives
["nom"] = {list = true},
["nom-g"] = {list = true, allow_holes=true},
-- other non-verbal derivatives
["other"] = {list = true},
["other-g"] = {list = true, allow_holes=true},
-- other
["lemma"] = {default = PAGENAME},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
return make_output(args)
end
return export