A modult a Modul:zgh-headword/doc lapon tudod dokumentálni
local zgh_translit = require("Module:zgh-translit")
local lang = require("Module:languages").getByCode("zgh")
local export = {}
local pos_functions = {}
-----------------------
-- 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 = 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
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 or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local params = {
= {list = "head", allow_holes = true, default = ""},
= {default = ""},
= {list = true, allow_holes = true},
}
local args = frame:getParent().args -- TODO: Use ] here
-- Gather parameters
local data = {lang = lang, pos_category = poscat, categories = {}, heads = {}, translits = {}, genders = {}, inflections = { enable_auto_translit = true }}
local head = args or args or PAGENAME or ""
local translit = ine(args)
local i = 1
while head do
table.insert(data.heads, head)
data.translits = translit
i = i + 1
head = ine(args)
translit = ine(args)
end
if pos_functions then
pos_functions.func(args, data)
end
return require("Module:headword").full_headword(data)
end
-- Get a list of inflections. See handle_infl() for meaning of ARGS, ARGPREF
-- and DEFGENDER.
local function getargs(args, argpref, defgender)
-- Gather parameters
local forms = {}
local form = ine(args)
local translit = ine(args)
local gender = ine(args)
local gender2 = ine(args)
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, translit = translit, gender = genderlist})
i = i + 1
form = ine(args)
translit = ine(args)
gender = ine(args)
gender2 = ine(args)
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")
handle_infl(args, data, argpref .. "def", labelsp .. "definite state")
handle_infl(args, data, argpref .. "obl", labelsp .. "oblique")
handle_infl(args, data, argpref .. "inf", labelsp .. "informal")
end
-- Handle the case where pl=-, indicating an uncountable noun.
local function handle_noun_plural(args, data)
if args == "-" then
table.insert(data.inflections, {label = "usually ]"})
table.insert(data.categories, lang:getCanonicalName() .. " uncountable nouns")
else
handle_infl(args, data, "pl", "plural")
end
end
local valid_genders = list_to_set(
{"m", "f", "m-p", "f-p", "p"})
local function is_masc_sg(g)
return g == "m"
end
local function is_fem_sg(g)
return g == "f"
end
local function handle_gender(args, data, default, nonlemma)
local g = ine(args) or default
local g2 = ine(args)
local function process_gender(g)
if not g then
table.insert(data.genders, "?")
elseif valid_genders 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
table.insert(data.categories, lang:getCanonicalName() .. " terms with multiple genders")
end
end
-- Part-of-speech functions
pos_functions = {
func = function(args, data)
handle_all_infl(args, data, "", "")
handle_all_infl(args, data, "f", "feminine")
handle_all_infl(args, data, "pl", "masculine plural")
handle_all_infl(args, data, "fpl", "feminine plural")
end
}
function handle_noun_infls(args, data, singonly)
handle_all_infl(args, data, "", "")
if not singonly then
handle_noun_plural(args, data)
handle_all_infl(args, data, "pl", "plural", "nobase")
end
handle_all_infl(args, data, "f", "feminine")
handle_all_infl(args, data, "m", "masculine")
end
pos_functions = {
func = function(args, data)
handle_gender(args, data)
handle_noun_infls(args, data)
end
}
pos_functions = {
func = function(args, data)
table.insert(data.categories, lang:getCanonicalName() .. " cardinal numbers")
handle_gender(args, data)
handle_noun_infls(args, data)
end
}
pos_functions = {
func = function(args, data)
handle_gender(args, data)
handle_noun_infls(args, data, "singular only")
end
}
return export