local export = {}
local pos_functions = {}
local list_to_set = require("Module:table").listToSet
local lang = require("Module:languages").getByCode("bar")
local script = require('Module:scripts').getByCode("Latn")
-- If Not Empty
local function ine(arg)
if arg == "" then
return nil
else
return arg
end
end
local function append_cat(data, pos)
table.insert(data.categories, lang:getCanonicalName() .. " " .. pos)
end
local function handle_infl(args, data, argpref, label)
if args and args then
local forms = {}
local form = argpref
local i = 1
while args do
table.insert (forms, args)
i = i + 1
form = argpref..i
end
forms.label = mw.ustring.gsub(label, 'form', 'forms')
table.insert(data.inflections, forms )
elseif args then
table.insert(data.inflections, { label = label, args})
end
end
function export.show(frame)
local args = frame:getParent().args
local poscat = frame.args or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
poscat = string.gsub(poscat, 'form', 'forms')
local data = {lang = lang, sc = script, pos_category = poscat, categories = {}, heads = {args or PAGENAME}, genders = {}, inflections = {}, sort_key = args}
if poscat == 'nouns' then
if ine(args) then
args = args
end
if ine(args) then
args = args
end
if ine(args) then
args = args
end
end
if args then
table.insert(data.categories, "Bavarian " .. args)
end
if args then
table.insert(data.categories, "Bavarian " .. args)
end
handle_infl(args, data, "stem", "stem")
if pos_functions then
pos_functions(args, data)
end
return require("Module:headword").full_headword(data)
end
local valid_genders = list_to_set(
{ "m", "m-p",
"f", "f-p",
"n", "n-p"
})
local function handle_gender(args, data, default, nonlemma, optional)
local g = ine(args) or default
local g2 = ine(args)
local function process_gender(gender)
if not gender and not optional then
table.insert(data.genders, "?")
elseif not gender and optional then
-- do nothing
elseif valid_genders then
table.insert(data.genders, gender)
else
error("Unrecognized gender: " .. gender)
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
local function is_masc_sg(g)
return g == "m" or g == "m-p"
end
local function is_fem_sg(g)
return g == "f" or g == "f-p"
end
local function is_neut_sg(g)
return g == "n" or g == "n-p"
end
pos_functions = function(args, data)
handle_infl(args, data, "cp", "comperative")
handle_infl(args, data, "sup", "superlative")
end
pos_functions = function(args, data)
handle_gender(args, data)
handle_infl(args, data, "acc", "accusative")
handle_infl(args, data, "dat", "dative")
end
pos_functions = function(args, data)
handle_gender(args, data)
handle_infl(args, data, "gen", "genitive")
handle_infl(args, data, "pl", "plural")
handle_infl(args, data, "f", "feminine")
local g = ine(args) or default
local g2 = ine(args)
if is_masc_sg(g) or is_masc_sg(g2) then
append_cat(data, "masculine nouns")
elseif is_fem_sg(g) or is_fem_sg(g2) then
append_cat(data, "feminine nouns")
elseif is_neut_sg(g) or is_neut_sg(g2) then
append_cat(data, "neuter nouns")
end
end
pos_functions = function(args, data)
handle_infl(args, data, "pl", "plural")
end
pos_functions = function(args, data)
handle_infl(args, data, "pp", "past participle")
handle_infl(args, data, "past", "3rd person singular past")
if ine(args) then
handle_infl(args, data, "subj", "subjunctive")
else
handle_infl(args, data, "subj", "3rd person singular subjunctive")
end
end
return export