Module:taln-headword: Difference between revisions

Nehster9 (talk | contribs)
mNo edit summary
No edit summary
 
(23 intermediate revisions by 2 users not shown)
Line 2: Line 2:
local pos_functions = {}
local pos_functions = {}


local lang = require("Module:languages").getByCode("tln")
local lang = require("Module:languages").getByCode("taln")
local langname = lang:getCanonicalName()


local PAGENAME = mw.title.getCurrentTitle().text
local require_when_needed = require("Module:utilities/require when needed")
local m_headword_utilities = require_when_needed("Module:headword utilities")


-- Nouns
local force_cat = false
pos_functions.nouns = function(class, args, data)
 
local params = {
local insert = table.insert
[1] = {required = true}, -- gender
local ipairs = ipairs
["pl"] = {},
["head"] = {},
["tr"] = {},
["pltr"] = {},
}


local args = require("Module:parameters").process(args, params)
local list_param = { list = true, disallow_holes = true }
local bool_param = { type = "boolean" }


local head = args.head or PAGENAME
local function nonempty_list(list)
local ret = {}
if not list then
return ret
end
for _, v in ipairs(list) do
if v and v ~= "" then
insert(ret, v)
end
end
return ret
end
 
local function parse_term_list(forms, paramname)
return m_headword_utilities.parse_term_list_with_modifiers{
forms = forms,
paramname = paramname,
splitchar = ",",
}
end


data.lang = lang
local function insert_inflection(data, terms, label, accel)
data.heads = {head}
m_headword_utilities.insert_inflection{
data.genders = {args[1]}
headdata = data,
data.inflections = {}
terms = terms,
label = label,
accel = accel and { form = accel } or nil,
}
end


-- plural handling
local function ensure_heads(data, args)
if args.pl then
local heads = nonempty_list(args.head)
local infl = {
local trs = args.tr or {}
label = "plural",
{ term = args.pl }
}


if args.pltr then
if not heads[1] then
infl[1].tr = args.pltr
local default_head = data.pagename
if not args.nolinkhead then
default_head = m_headword_utilities.add_links_to_multiword_term(default_head, {})
end
end
 
heads = { default_head }
table.insert(data.inflections, infl)
end
end


if args.tr then
for i, head in ipairs(heads) do
data.translits = {args.tr}
insert(data.heads, {
term = head,
tr = trs[i],
})
end
end
end
end


-- Entry point
function export.show(frame)
function export.show(frame)
local parent_args = frame:getParent().args
local iparams = {
[1] = { required = true },
}
local iargs = require("Module:parameters").process(frame.args, iparams)
local poscat = iargs[1]
 
local params = {
["head"] = list_param,
["tr"] = { list = true, allow_holes = true },
["id"] = {},
["sort"] = {},
["nolinkhead"] = bool_param,
["pagename"] = {}, -- for testing
}
 
if pos_functions[poscat] then
local posparams = pos_functions[poscat].params
if type(posparams) == "function" then
posparams = posparams(lang)
end
for key, val in pairs(posparams) do
params[key] = val
end
end


local poscat = frame.args[1] or "nouns"
local args = require("Module:parameters").process(frame:getParent().args, params)
local pagename = args.pagename or mw.loadData("Module:headword/data").pagename


local data = {
local data = {
inflections = {},
lang = lang,
pos_category = poscat,
categories = {},
heads = {},
genders = {},
genders = {},
categories = {},
inflections = { enable_auto_translit = true },
pagename = pagename,
id = args.id,
sort_key = args.sort,
force_cat_output = force_cat,
}
}


if pos_functions[poscat] then
ensure_heads(data, args)
pos_functions[poscat](nil, parent_args, data)
 
if pos_functions[poscat] and pos_functions[poscat].func then
pos_functions[poscat].func(args, data)
end
end


return require("Module:headword").full_headword(data)
return require("Module:headword").full_headword(data)
end
end
pos_functions.nouns = {
params = {
["g"] = { required = true, type = "genders", list = true, disallow_holes = true, flatten = true },
["nopl"] = bool_param,
["pl"] = list_param,
},
func = function(args, data)
local genders = nonempty_list(args.g)
if not genders[1] then
error("Parameter g= (gender) is required and must be non-empty")
end
data.genders = genders
local plurals = parse_term_list(args.pl, "pl")
if args.nopl or (plurals[1] and plurals[1].term == "-") then
insert(data.categories, langname .. " uncountable nouns")
elseif plurals[1] then
insert_inflection(data, plurals, "plural", "p")
else
insert(data.categories, langname .. " countable nouns")
end
end,
}
pos_functions.verbs = {
params = {
["pres"] = list_param,
["past"] = list_param,
["part"] = list_param,
},
func = function(args, data)
local pres = parse_term_list(args.pres, "pres")
local past = parse_term_list(args.past, "past")
local part = parse_term_list(args.part, "part")
if pres[1] then
insert_inflection(data, pres, "first-person singular present", "1|s|pres|ind")
end
if past[1] then
insert_inflection(data, past, "first-person singular past", "1|s|past|ind")
end
if part[1] then
insert_inflection(data, part, "past participle", "pastpart")
end
end,
}


return export
return export