Module:bcl2-headword
Appearance
Documentation for this module may be created at Module:bcl2-headword/doc
local export = {}
local pos_functions = {}
local lang = require("Module:languages").getByCode("bcl")
local function glossary_link(entry, text)
text = text or entry
return "[[Appendix:Glossary#" .. entry .. "|" .. text .. "]]"
end
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
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 = {
["head"] = {list = true, default = ""},
["suff"] = {type = "boolean"},
}
local pos_data = pos_functions[poscat]
if pos_data then
for key, val in pairs(pos_data.params) do
params[key] = val
end
end
local args, unknown_args = require("Module:parameters").process(frame:getParent().args, params, pos_data.return_unknown)
if unknown_args and next(unknown_args) then
require "Module:debug".track { "bcl-headword/dai bistong argumento", "en-headword/dai bistong/POS/" .. tostring(poscat) }
for parameter, value in pairs(unknown_args) do
require "Module:debug".track("en-headword/dai bistong/param/" .. tostring(parameter))
mw.log("dai bistong parametro sa [[Module:headword]]: |" .. tostring(parameter) .. "=" .. tostring(value))
end
end
local data = {lang = lang, pos_category = poscat, categories = {}, heads = args["head"], inflections = {}}
if args["suff"] then
data.pos_category = "suffixes"
if poscat == "panmidbid" or poscat == "pan-abay" or poscat == "pangngaran" or poscat == "panhiro" then
table.insert(data.categories, ("%s %s-forming suffixes")
:format(lang:getCanonicalName(), poscat:gsub("s$", "")))
else
error("No category exists for suffixes forming " .. poscat .. ".")
end
end
if pos_data then
pos_data.func(args, data)
end
local pagename = mw.title.getCurrentTitle().text
local extra_categories = {}
if pagename:find("[Qq][^Uu]") or pagename:find("[Qq]$") then
table.insert(data.categories, lang:getCanonicalName() .. " mga tataramon na igwang Q pero dai sinusundan nin U")
end
if pagename:find("([A-Za-z])%1%1") then
table.insert(data.categories, lang:getCanonicalName() .. " mga tataramon na igwang tulong sunod na pararehong letra")
end
if pagename:find("[^c]ie") or pagename:find("cei") then
table.insert(data.categories, lang:getCanonicalName() .. " words following the I before E except after C rule")
end
if pagename:find("[^c]ei") or pagename:find("cie") then
table.insert(data.categories, lang:getCanonicalName() .. " words not following the I before E except after C rule")
end
if not mw.ustring.toNFD(pagename):lower():find("[aeiouy]") then
table.insert(data.categories, lang:getCanonicalName() .. " mga tataramon na mayong patanog")
end
if pagename:find("yre$") then
table.insert(data.categories, lang:getCanonicalName() .. ' mga tataramon na nagtatapos sa "-yre"')
end
if not pagename:find(" ") and pagename:len() > 25 then
table.insert(extra_categories, "Long " .. lang:getCanonicalName() .. ' tataramon')
end
if pagename:find("^[^aeiou ]*a[^aeiou ]*e[^aeiou ]*i[^aeiou ]*o[^aeiou ]*u[^aeiou ]*$") then
table.insert(data.categories, lang:getCanonicalName() .. ' tataramon na naggamit nin gabos na patanog sa alpabetikong pasunod-sunod')
end
return require("Module:headword").full_headword(data)
.. (#extra_categories > 0
and require("Module:utilities").format_categories(extra_categories, lang)
or "")
end
-- This function does the common work between adjectives and adverbs
function make_comparatives(params, data)
local comp_parts = {label = glossary_link ("nakokompara", "pag-agid"), accel = {form = "pag-agid"}}
local sup_parts = {label = glossary_link ("nakokompara", "palabi"), accel = {form = "palabi"}}
if #params == 0 then
table.insert(params, {"mas"})
end
-- To form the stem, replace -(e)y with -i and remove a final -e.
local stem = PAGENAME:gsub("([^aeiou])e?y$", "%1i"):gsub("e$", "")
-- Go over each parameter given and create a comparative and superlative form
for i, val in ipairs(params) do
local comp = val[1]
local sup = val[2]
if comp == "more" and PAGENAME ~= "many" and PAGENAME ~= "much" then
table.insert(comp_parts, "[[||||||||||||||||||more]] " .. PAGENAME)
table.insert(sup_parts, "[[||||||||||||||||||most]] " .. PAGENAME)
elseif comp == "further" and PAGENAME ~= "far" then
table.insert(comp_parts, "[[||||||||||||||||||further]] " .. PAGENAME)
table.insert(sup_parts, "[[||||||||||||||||||furthest]] " .. PAGENAME)
elseif comp == "er" then
table.insert(comp_parts, stem .. "er")
table.insert(sup_parts, stem .. "est")
elseif comp == "-" or sup == "-" then
-- Allowing '-' makes it more flexible to not have some forms
if comp ~= "-" then
table.insert(comp_parts, comp)
end
if sup ~= "-" then
table.insert(sup_parts, sup)
end
else
-- If the full comparative was given, but no superlative, then
-- create it by replacing the ending -er with -est.
if not sup then
if comp:find("er$") then
sup = comp:gsub("er$", "est")
else
error("An superlatibo kan \"" .. comp .. "\" dai awtomatiko. Magkaag nin \"sup" .. (i == 1 and "" or i) .. "=\" na parametro.")
end
end
table.insert(comp_parts, comp)
table.insert(sup_parts, sup)
end
end
table.insert(data.inflections, comp_parts)
table.insert(data.inflections, sup_parts)
end
pos_functions["panmidbid"] = {
params = {
[1] = {list = true, allow_holes = true},
["sup"] = {list = true, allow_holes = true},
},
func = function(args, data)
local shift = 0
local is_not_comparable = false
local is_comparative_only = false
-- If the first parameter is ?, then don't show anything, just return.
if args[1][1] == "?" then
return
-- If the first parameter is -, then move all parameters up one position.
elseif args[1][1] == "-" then
shift = 1
is_not_comparable = true
-- If the only argument is +, then remember this and clear parameters
elseif args[1][1] == "+" and args[1].maxindex == 1 then
shift = 1
is_comparative_only = true
end
-- Gather all the comparative and superlative parameters.
local params = {}
for i = 1, args[1].maxindex - shift do
local comp = args[1][i + shift]
local sup = args["sup"][i]
if comp or sup then
table.insert(params, {comp, sup})
end
end
if shift == 1 then
-- If the first parameter is "-" but there are no parameters,
-- then show "not comparable" only and return.
-- If there are parameters, then show "not generally comparable"
-- before the forms.
if #params == 0 then
if is_not_comparable then
table.insert(data.inflections, {label = "dai " .. "nakukumpara"})
table.insert(data.categories, lang:getCanonicalName() .. " dai nakukumparang panmidbid")
return
end
if is_comparative_only then
table.insert(data.inflections, {label = "pag-agid", "tangga nin" .. "pag-agid"})
table.insert(data.categories, lang:getCanonicalName() .. " panmidbid sa ta tanggang pag-agid")
return
end
else
table.insert(data.inflections, {label = "dai pirming .. nakukumpara"})
end
end
-- Process the parameters
make_comparatives(params, data)
end
}
pos_functions["pan-abay"] = {
params = {
[1] = {list = true, allow_holes = true},
["sup"] = {list = true, allow_holes = true},
},
func = function(args, data)
local shift = 0
-- If the first parameter is ?, then don't show anything, just return.
if args[1][1] == "?" then
return
-- If the first parameter is -, then move all parameters up one position.
elseif args[1][1] == "-" then
shift = 1
end
-- Gather all the comparative and superlative parameters.
local params = {}
for i = 1, args[1].maxindex - shift do
local comp = args[1][i + shift]
local sup = args["sup"][i]
if comp or sup then
table.insert(params, {comp, sup})
end
end
if shift == 1 then
-- If the first parameter is "-" but there are no parameters,
-- then show "not comparable" only and return. If there are parameters,
-- then show "not generally comparable" before the forms.
if #params == 0 then
table.insert(data.inflections, {label = "dai .. nakukumpara"})
table.insert(data.categories, lang:getCanonicalName() .. " dai nakukumparang pan-abay")
return
else
table.insert(data.inflections, {label = "dai pirming .. nakukumpara"})
end
end
-- Process the parameters
make_comparatives(params, data)
end
}
pos_functions["conjunctions"] = {
params = {
[1] = { alias_of = "head" },
},
return_unknown = true,
func = function (args, data)
end,
}
pos_functions["interjections"] = {
params = {
[1] = { alias_of = "head" },
},
return_unknown = true,
func = function (args, data)
end,
}
pos_functions["pangngaran"] = {
params = {
[1] = {list = true, allow_holes = true},
-- TODO: This should really be a list parameter too...
["plqual"] = {},
["pl2qual"] = {},
["pl3qual"] = {},
["pl4qual"] = {},
["pl5qual"] = {},
},
func = function(args, data)
-- Gather all the plural parameters from the numbered parameters.
local plurals = {}
for i = 1, args[1].maxindex do
local pl = args[1][i]
if pl then
local qual = args["pl" .. (i == 1 and "" or i) .. "qual"]
if qual then
table.insert(plurals, {term = pl, qualifiers = {qual}})
else
table.insert(plurals, pl)
end
end
end
-- Decide what to do next...
local mode = nil
if plurals[1] == "?" or plurals[1] == "!" or plurals[1] == "-" or plurals[1] == "~" then
mode = plurals[1]
table.remove(plurals, 1) -- Remove the mode parameter
end
-- Plural is unknown
if mode == "?" then
table.insert(data.categories, lang:getCanonicalName() .. " ngaran na dai sigurado an panggulpihan")
return
-- Plural is not attested
elseif mode == "!" then
table.insert(data.inflections, {label ="dai probado an panggulpihan"})
table.insert(data.categories, lang:getCanonicalName() .. "ngaran na dai probado an panggulpihan")
return
-- Uncountable noun; may occasionally have a plural
elseif mode == "-" then
table.insert(data.categories, lang:getCanonicalName() .. "dai nabibilang na ngaran")
-- If plural forms were given explicitly, then show "usually"
if #plurals > 0 then
table.insert(data.inflections, {label = "pirmi dai nabibilang"})
table.insert(data.categories, lang:getCanonicalName() .. "nabibilang na pangngaran")
else
table.insert(data.inflections, {label ="dai nabibilang"})
end
-- Mixed countable/uncountable noun, always has a plural
elseif mode == "~" then
table.insert(data.inflections, {label ="nabibilang" .. " asin " .. "dai nabibilang"})
table.insert(data.categories, lang:getCanonicalName() .. " dai nabibilang na pangngaran")
table.insert(data.categories, lang:getCanonicalName() .. " nabibilang na pangngaran")
-- If no plural was given, add a default one now
if #plurals == 0 then
plurals = {"~"}
end
-- The default, always has a plural
else
table.insert(data.categories, lang:getCanonicalName() .. " nabibilang na pangngaran")
-- If no plural was given, add a default one now
if #plurals == 0 then
plurals = {"!"}
end
if plural and not mw.title.new(plural).exists then
table.insert(categories, "Bikol Sentral na ngaran na mayong panggulpihan")
end
end
-- If there are no plurals to show, return now
if #plurals == 0 then
return
end
-- There are plural forms to show, so show them
local pl_parts = {label ="gulpihan", accel = {form ="g"}}
local function check_ies(pl, stem)
local newplural, nummatches = stem:gsub("([^aeiou])y$","%1ies")
return nummatches > 0 and pl == newplural
end
local stem = PAGENAME
local irregular = false
for i, pl in ipairs(plurals) do
if pl == "-" then
table.insert(pl_parts, stem .. "-")
elseif pl == "-" then
table.insert(pl_parts, stem .. "-")
else
table.insert(pl_parts, pl)
if type(pl) == "table" then
pl = pl.term
end
if not stem:find(" ") and not (pl == stem .. "-" or pl == stem .. "-" or check_ies(pl, stem)) then
irregular = true
if pl == stem then
table.insert(data.categories, lang:getCanonicalName() .. " invariant nouns")
end
end
end
end
if irregular then
table.insert(data.categories, lang:getCanonicalName() .. " ngaran na may irregular na panggulpihan")
end
table.insert(data.inflections, pl_parts)
end
}
pos_functions["pangngaran na pamidbid"] = {
params = {
[1] = {list = true},
},
func = function(args, data)
local plurals = args[1]
-- Decide what to do next...
local mode = nil
if plurals[1] == "?" or plurals[1] == "!" or plurals[1] == "-" or plurals[1] == "~" then
mode = plurals[1]
table.remove(plurals, 1) -- Remove the mode parameter
end
-- Plural is unknown
if mode == "?" then
table.insert(data.categories, lang:getCanonicalName() .. " pangngaran na pamidbid na dai sigurado an panggulpihan")
return
-- Plural is not attested
elseif mode == "!" then
table.insert(data.inflections, {label = "dai probado an panggulpihan"})
table.insert(data.categories, lang:getCanonicalName() .. "pangngaran na pamidbid na dai probado an panggulpihan")
return
-- Uncountable noun; may occasionally have a plural
elseif mode == "-" then
-- If plural forms were given explicitly, then show "usually"
if #plurals > 0 then
table.insert(data.inflections, {label ="dai nabibilang"})
table.insert(data.categories, lang:getCanonicalName() .. " nabibilang na pangngaran na pamidbid")
else
table.insert(data.inflections, {label = "dai nabibilang"})
end
-- Mixed countable/uncountable noun, always has a plural
elseif mode == "~" then
table.insert(data.inflections, {label = "dai nabibilang"})
table.insert(data.categories, lang:getCanonicalName() .. " nabibilang na pangngaran na pamidbid")
-- If no plural was given, add a default one now
if #plurals == 0 then
plurals = {"s"}
end
elseif #plurals > 0 then
table.insert(data.categories, lang:getCanonicalName() .. " nabibilang na pangngaran na pamidbid")
end
-- If there are no plurals to show, return now
if #plurals == 0 then
return
end
-- There are plural forms to show, so show them
local pl_parts = {label = "gulpihan", accel = {form = "g"}}
local stem = PAGENAME
for i, pl in ipairs(plurals) do
if pl == "-" then
table.insert(pl_parts, stem .. "-")
elseif pl == "-" then
table.insert(pl_parts, stem .. "-")
else
table.insert(pl_parts, pl)
end
end
table.insert(data.inflections, pl_parts)
end
}
pos_functions["panhiro"] = {
params = {
[1] = {list = "simpleng kapanahunan", allow_holes = true},
["pres_3sg_qual"] = {},
["pres_3sg2_qual"] = {},
["pres_3sg3_qual"] = {},
["pres_3sg4_qual"] = {},
["pres_3sg5_qual"] = {},
[2] = {list = "presenteng kapanahunan", allow_holes = true},
["past_qual"] = {},
["past2_qual"] = {},
["past3_qual"] = {},
["past4_qual"] = {},
["past5_qual"] = {},
[3] = {list = "nag-aging kapanahunan", allow_holes = true},
["pres_ptc_qual"] = {},
["pres_ptc2_qual"] = {},
["pres_ptc3_qual"] = {},
["pres_ptc4_qual"] = {},
["pres_ptc5_qual"] = {},
[4] = {list = "paabuton na kapanahunan", allow_holes = true},
["past_ptc_qual"] = {},
["past_ptc2_qual"] = {},
["past_ptc3_qual"] = {},
["past_ptc4_qual"] = {},
["past_ptc5_qual"] = {},
},
func = function(args, data)
-- Get parameters
local par1 = args[1][1]
local par2 = args[2][1]
local par3 = args[3][1]
local par4 = args[4][1]
local pres_3sg_forms = {label = "simpleng kapanahunan", accel = {form = "3|s|pres"}}
local past_forms = {label = "nag-aging kapanahunan", accel = {form = "past"}}
local pres_ptc_forms = {label = "presenteng kapanahunan", accel = {form = "pres|ptcp"}}
local pres_3sg_form = par1 or PAGENAME .. ""
local pres_ptc_form = par2 or PAGENAME .. ""
local past_form = par3 or PAGENAME .. ""
if par1 and not par2 and not par3 then
-- This is the "new" format, which uses only the first parameter.
if par1 == "" then
pres_3sg_form = PAGENAME .. ""
past_form = PAGENAME .. ""
pres_ptc_form = PAGENAME .. ""
elseif par1 == "ies" then
if not mw.ustring.find(PAGENAME, "y$") then
error("The first parameter is \"ies\" but the verb does not end in -y.")
end
local stem = mw.ustring.gsub(PAGENAME, "y$", "")
pres_3sg_form = stem .. ""
past_form = stem .. ""
pres_ptc_form = stem .. ""
elseif par1 == "d" then
pres_3sg_form = PAGENAME .. ""
past_form = PAGENAME .. ""
pres_ptc_form = PAGENAME .. ""
else
pres_3sg_form = PAGENAME .. ""
past_form = par1 .. ""
pres_ptc_form = par1 .. ""
end
else
-- This is the "legacy" format, using the second and third parameters as well.
-- It is included here for backwards compatibility and to ease the transition.
if par3 then
if par3 == "" then
require("Module:debug").track("bcl-headword/es3")
pres_3sg_form = par1 .. par2 .. ""
past_form = par1 .. par2 .. ""
pres_ptc_form = par1 .. par2 .. ""
elseif par3 == "" then
require("Module:debug").track("bcl-headword/ing3")
pres_3sg_form = PAGENAME .. ""
pres_ptc_form = par1 .. par2 .. ""
if par2 == "" then
past_form = PAGENAME .. ""
else
past_form = par1 .. par2 .. ""
end
elseif par3 == "" then
require("Module:debug").track("bcl-headword/ed3")
if par2 == "" then
pres_3sg_form = par1 .. par2 .. ""
pres_ptc_form = PAGENAME .. ""
else
pres_3sg_form = PAGENAME .. ""
pres_ptc_form = par1 .. par2 .. ""
end
past_form = par1 .. par2 .. ""
elseif par3 == "" then
require("Module:debug").track("bcl-headword/d3")
pres_3sg_form = PAGENAME .. ""
pres_ptc_form = par1 .. par2 .. ""
past_form = par1 .. par2 .. ""
else
require("Module:debug").track("bcl-headword/xxx3")
end
else
if par2 == "" then
require("Module:debug").track("bcl-headword/es2")
pres_3sg_form = par1 .. ""
past_form = par1 .. ""
pres_ptc_form = par1 .. ""
elseif par2 == "" then
require("Module:debug").track("bcl-headword/ies2")
if par1 .. "" ~= PAGENAME then
require("Module:debug").track("bcl-headword/ies2/par1 not pagename")
end
pres_3sg_form = par1 .. ""
past_form = par1 .. ""
pres_ptc_form = par1 .. ""
elseif par2 == "" then
require("Module:debug").track("bcl-headword/ing2")
pres_3sg_form = PAGENAME .. ""
past_form = par1 .. ""
pres_ptc_form = par1 .. ""
elseif par2 == "" then
require("Module:debug").track("bcl-headword/ed2")
pres_3sg_form = PAGENAME .. ""
past_form = par1 .. ""
pres_ptc_form = par1 .. ""
elseif par2 == "" then
require("Module:debug").track("bcl-headword/d2")
if par1 ~= PAGENAME then
require("Module:debug").track("bcl-headword/d2/par1 not pagename")
end
pres_3sg_form = PAGENAME .. ""
past_form = par1 .. ""
pres_ptc_form = par1 .. ""
else
require("Module:debug").track("bcl-headword/xxx2")
end
end
end
local pres_3sg_qual = args["pres_3sg_qual"]
local past_qual = args["past_qual"]
local pres_ptc_qual = args["pres_ptc_qual"]
table.insert(pres_ptc_forms, {term = pres_ptc_form, qualifiers = {pres_ptc_qual}})
table.insert(past_forms, {term = past_form, qualifiers = {past_qual}})
table.insert(pres_3sg_forms, {term = pres_3sg_form, qualifiers = {pres_3sg_qual}})
-- Present 3rd singular
for i = 2, args[1].maxindex do
local form = args[1][i]
local qual = args["pres_3sg" .. i .. "_qual"]
if form then
table.insert(pres_3sg_forms, {term = form, qualifiers = {qual}})
end
end
-- Past
for i = 2, args[3].maxindex do
local form = args[3][i]
local qual = args["past" .. i .. "_qual"]
if form then
table.insert(past_forms, {term = form, qualifiers = {qual}})
end
end
-- Present participle
for i = 2, args[2].maxindex do
local form = args[2][i]
local qual = args["pres_ptc" .. i .. "_qual"]
if form then
table.insert(pres_ptc_forms, {term = form, qualifiers = {qual}})
end
end
-- Past participle
local found_past_ptc = false
local past_ptc_forms = {label = "paabuton na kapanahunan", accel = {form = "past|ptcp"}}
local qual = args["past_ptc_qual"]; if qual == "" then qual = nil end
table.insert(past_ptc_forms, {term = par4 or past_form, qualifiers = {qual}})
if par4 or qual then
found_past_ptc = true
end
for i = 2, args[4].maxindex do
local form = args[4][i]
local qual = args["past_ptc" .. i .. "_qual"]
if form then
table.insert(past_ptc_forms, {term = form, qualifiers = {qual}})
found_past_ptc = true
end
end
-- Are the past forms identical to the past participle forms?
local identical = true
if #past_forms ~= #past_ptc_forms then
identical = false
else
for key, val in ipairs(past_forms) do
if past_ptc_forms[key].term ~= val.term or past_ptc_forms[key].qual ~= val.qual then
identical = false
break
end
end
end
-- Insert the forms
table.insert(data.inflections, pres_3sg_forms)
table.insert(data.inflections, pres_ptc_forms)
if not found_past_ptc or identical then
past_forms.label = "nag-aging kapanahunan"
past_forms.accel = {form = "past|and|past|ptcp"}
table.insert(data.inflections, past_forms)
else
table.insert(data.inflections, past_forms)
table.insert(data.inflections, past_ptc_forms)
end
end
}
return export