Module:yi-headword
Appearance
- The following documentation is located at Module:yi-headword/documentation. [edit] Categories were auto-generated by Module:module categorization. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local com = require("Module:yi-common")
local lang = require("Module:languages").getByCode("yi")
local Latn = require("Module:scripts").getByCode("Latn")
local export = {}
local pos_functions = {}
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
SUBPAGENAME = mw.title.getCurrentTitle().subpageText
local args = {}
for key, val in pairs(frame:getParent().args) do
if val ~= "" then
args[key] = val
end
end
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local head = com.form(args["head"] or SUBPAGENAME, args["tr"])
local genders = {}
local inflections = {}
local categories = {lang:getCanonicalName() .. " " .. poscat}
-- Call POS-specific function
if pos_functions[poscat] then
pos_functions[poscat](args, head, genders, inflections, categories)
end
return require("Module:headword").full_headword(lang, nil, {args["head"]}, {args["tr"]}, genders, inflections, categories, args["sort"])
end
local function get_form(args, argname, trname)
local form = args[argname]
if form then
return com.form(form, args[trname or (argname .. "tr")])
else
return form
end
end
local function get_numbered_forms(args, argname, startat, output)
output = output or {}
while true do
local form = get_form(args, argname .. startat)
if form then
table.insert(output, form)
else
break
end
startat = startat + 1
end
return output
end
local function add_inflections(inflections, ...)
for _, inflection in ipairs({...}) do
if inflection[1] then
for i, form in ipairs(inflection) do
if form == "-" then
inflection[i] = {term = "—", translit = "-", nolink = true, sc = Latn}
else
inflection[i] = {term = form.text, translit = form.tr, accel = inflection.accel and form.tr and ("transliteration-" .. form.tr:gsub(" ", "_"))}
end
end
table.insert(inflections, inflection)
end
end
end
pos_functions["adjectives"] = function(args, head, genders, inflections, categories)
local comparatives = {get_form(args, 1, "ctr"), label = "comparative", enable_auto_translit = true}
if comparatives[1] then
get_numbered_forms(args, "c", 2, comparatives)
end
local superlatives = {get_form(args, 2, "str"), label = "superlative", enable_auto_translit = true}
if superlatives[1] then
get_numbered_forms(args, "s", 2, superlatives)
end
add_inflections(inflections, comparatives, superlatives)
end
pos_functions["verbs"] = function(args, head, genders, inflections, categories)
local past_participles = {get_form(args, 1, 2), label = "past participle", enable_auto_translit = true, accel = "past-participle-form-of"}
if past_participles[1] then
get_numbered_forms(args, "p", 2, past_participles)
end
add_inflections(inflections, past_participles)
end
local compound_genders = {
["mp"] = {"m-p"},
["np"] = {"n-p"},
["fp"] = {"f-p"},
["mn"] = {"m", "n"},
["mf"] = {"m", "f"},
["fn"] = {"f", "n"},
["mnp"] = {"m-p", "n-p"},
["mfp"] = {"m-p", "f-p"},
["fnp"] = {"f-p", "n-p"},
["mfn"] = {"m", "f", "n"},
["mfnp"] = {"m-p", "f-p", "n-p"},
}
pos_functions["nouns"] = function(args, head, genders, inflections, categories)
local gs = compound_genders(args["g"])
if gs then
for _, g in ipairs(gs) do
table.insert(genders, g)
end
elseif args["g"] then
table.insert(genders, args["g"])
local i = 2
while args["g" .. i] do
table.insert(genders, args["g" .. i])
i = i + 1
end
end
add_inflections(inflections, past_participles)
end
pos_functions["prepositions"] = function(args, head, genders, inflections, categories)
local dem_forms = {get_form(args, "dem", "demtr"), label = "dem-form", enable_auto_translit = true}
if dem_forms[1] then
get_numbered_forms(args, "dem", 2, dem_forms)
end
add_inflections(inflections, dem_forms)
end
return export