Modul:mt-headword
A modult a Modul:mt-headword/doc lapon tudod dokumentálni
local lang = require("Module:languages").getByCode("mt")
local export = {}
local pos_functions = {}
local u = mw.ustring.char
-----------------------
-- Utility functions --
-----------------------
-- If Not Empty
local function ine(arg)
if arg == "" then
return nil
else
return arg
end
end
local function list_to_set(list)
local set = {}
for _, item in ipairs(list) do
set[item] = true
end
return set
end
-- version of mw.ustring.gsub() that discards all but the first return value
function rsub(term, foo, bar)
local retval = mw.ustring.gsub(term, foo, bar)
return retval
end
local rfind = mw.ustring.find
-- Tracking functions
local trackfn = require("Module:debug").track
function track(page)
trackfn("mt-headword/" .. page)
return true
end
local function append_cat(data, pos)
table.insert(data.categories, lang:getCanonicalName() .. " " .. pos)
end
function remove_links(text)
text = rsub(text, "%[%[[^|%]]*|", "")
text = rsub(text, "%[%[", "")
text = rsub(text, "%]%]", "")
return text
end
-- The main entry point.
function export.show(frame)
local PAGENAME = mw.title.getCurrentTitle().text
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local params = {
[1] = {list = "head", allow_holes = true, default = ""},
["head"] = {default = ""}
}
local args = frame:getParent().args
-- Gather parameters
local data = {lang = lang, pos_category = poscat, categories = {}, heads = {}, genders = {}, inflections = {}}
local head = args["head"] or PAGENAME or ""
local i = 1
while head do
table.insert(data.heads, head)
i = i + 1
head = ine(args["head" .. i])
end
if pos_functions[poscat] then
pos_functions[poscat].func(args, data)
end
return require("Module:headword").full_headword(data)
end
local function getargs(args, argpref, defgender)
-- Gather parameters
local forms = {}
local form = ine(args[argpref])
local gender = ine(args[argpref .. "g"])
local gender2 = ine(args[argpref .. "g2"])
local i = 1
while form do
local genderlist = (gender or gender2) and {gender, gender2} or defgender and {defgender} or nil
table.insert(forms, {term = form, gender = genderlist})
i = i + 1
form = ine(args[argpref .. i])
gender = ine(args[argpref .. i .. "g"])
gender2 = ine(args[argpref .. i .. "g2"])
end
return forms
end
local function handle_infl(args, data, argpref, label, defgender)
local newinfls = getargs(args, argpref, defgender)
newinfls.label = label
if #newinfls > 0 then
table.insert(data.inflections, newinfls)
end
end
local function handle_all_infl(args, data, argpref, label, nobase)
if not nobase and argpref ~= "" then
handle_infl(args, data, argpref, label)
end
local labelsp = label == "" and "" or label .. " "
handle_infl(args, data, argpref .. "cons", labelsp .. "construct state")
end
-- Handle the case where p=-, indicating an uncountable noun.
local function handle_noun_plural(args, data)
if args["p"] == "-" then
table.insert(data.inflections, {label = "általában [[Appendix:Glossary#uncountable|megszámlálhatatlan]]"})
append_cat(data, "megszámlálhatatlan főnevek")
else
handle_infl(args, data, "p", "tsz")
end
end
local valid_genders = list_to_set(
{"m", "m-s",
"f", "f-s",
"m-p", "f-p", "p",
"d", "m-d", "f-d",
})
local function is_masc_sg(g)
return g == "m" or g == "m-s" or g == "m-p" or g == "m-d"
end
local function is_fem_sg(g)
return g == "f" or g == "f-s" or g == "f-p" or g == "f-d"
end
local function handle_gender(args, data, default, nonlemma)
local PAGENAME = mw.title.getCurrentTitle().text
local g = ine(args["g"]) or default
local g2 = ine(args["g2"])
local function process_gender(g)
if not g then
table.insert(data.genders, "?")
elseif valid_genders[g] then
table.insert(data.genders, g)
else
error("Unrecognized gender: " .. g)
end
end
process_gender(g)
if g2 then
process_gender(g2)
end
if nonlemma then
return
end
if g and g2 then
append_cat(data, "terms with multiple genders")
end
end
-- Part-of-speech functions
pos_functions["melléknevek"] = {
func = function(args, data)
handle_all_infl(args, data, "", "")
handle_all_infl(args, data, "f", "nőnem esz.")
handle_all_infl(args, data, "p", "tsz.")
handle_all_infl(args, data, "dim", "diminutive")
handle_all_infl(args, data, "comp", "comparative")
end
}
function handle_sing_coll_noun_infls(args, data)
handle_all_infl(args, data, "", "")
handle_all_infl(args, data, "d", "dual")
handle_all_infl(args, data, "pauc", "paucal")
handle_noun_plural(args, data)
handle_all_infl(args, data, "p", "tsz.", "nobase")
end
pos_functions["kollektív főnevek"] = {
func = function(args, data)
data.pos_category = "főnevek"
append_cat(data, "kollektív főnevek")
table.insert(data.inflections, {label = "kollektív"})
handle_gender(args, data, "m")
-- Handle sing= (the corresponding singulative noun) and singg= (its gender)
handle_infl(args, data, "sing", "singulative", "f")
handle_sing_coll_noun_infls(args, data)
end
}
pos_functions["szingulatív főnevek"] = {
func = function(args, data)
data.pos_category = "főnevek forms"
append_cat(data, "singulative főnevek")
table.insert(data.inflections, {label = "singulative"})
handle_gender(args, data, "f")
-- Handle coll= (the corresponding collective noun) and collg= (its gender)
handle_infl(args, data, "coll", "collective", "m")
handle_sing_coll_noun_infls(args, data)
end
}
function handle_noun_infls(args, data, singonly)
handle_all_infl(args, data, "", "")
if not singonly then
handle_all_infl(args, data, "d", "dual")
handle_noun_plural(args, data)
handle_all_infl(args, data, "p", "tsz.", "nobase")
end
handle_all_infl(args, data, "f", "nőnem")
handle_all_infl(args, data, "m", "hímnem")
if not singonly then
handle_all_infl(args, data, "dim", "kicsinyítő")
end
end
pos_functions["főnevek"] = {
func = function(args, data)
handle_gender(args, data)
handle_noun_infls(args, data)
local g = ine(args["g"]) or default
local g2 = ine(args["g2"])
if is_masc_sg(g) or is_masc_sg(g2) then
append_cat(data, "hímnemű főnevek")
elseif is_fem_sg(g) or is_fem_sg(g2) then
append_cat(data, "nőnemű főnevek")
end
end
}
pos_functions["számnevek"] = {
func = function(args, data)
append_cat(data, "cardinal numbers")
handle_gender(args, data)
handle_noun_infls(args, data)
end
}
pos_functions["tulajdonnevek"] = {
func = function(args, data)
handle_gender(args, data)
handle_noun_infls(args, data, "singular only")
end
}
pos_functions["nőnemű melléknévi alakok"] = {
params = {
["g"] = {},
["g2"] = {},
["p"] = {},
["islemma"] = { type = boolean },
},
func = function(args, data)
data.pos_category = "adjective forms"
handle_noun_plural(args, data)
handle_gender(args, data, "f", "nonlemma")
end
}
pos_functions["többes melléknévi alakok"] = {
params = {
["g"] = {},
["g2"] = {},
},
func = function(args, data)
data.pos_category = "adjective forms"
handle_gender(args, data, "p", "nonlemma")
end
}
pos_functions["főnevi alakok"] = {
params = {
["g"] = {},
["g2"] = {},
},
func = function(args, data)
handle_gender(args, data, nil, "nonlemma")
end
}
pos_functions["dualis főnévi alakok"] = {
params = {
["g"] = {},
["g2"] = {},
},
func = function(args, data)
data.pos_category = "főnévi alakok"
append_cat(data, "dualis főnévi alakok")
handle_gender(args, data, "d", "nonlemma")
end
}
pos_functions["igék"] = {
func = function(args, data)
data.pos_category = "verbs"
handle_all_infl(args, data, "imper", "imperfect")
handle_all_infl(args, data, "pp", "past participle")
end
}
pos_functions["határozószók"] = {
func = function(args, data)
data.pos_category = "adverbs"
handle_all_infl(args, data, "stem", "stem")
end
}
return export