Module:snon-headword: Difference between revisions
No edit summary |
No edit summary |
||
| (27 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
local pos_functions = {} | local pos_functions = {} | ||
local match = mw.ustring.match | |||
local gsub = mw.ustring.gsub | |||
local m_links = require("Module:links") | local m_links = require("Module:links") | ||
| Line 19: | Line 22: | ||
} | } | ||
local function | local function glossary_link(...) | ||
return m_hw_util.glossary_link(...) | |||
end | |||
local function insert_inflection(data, terms, label, accel) | |||
m_hw_util.insert_inflection { | |||
headdata = data, | |||
terms = terms, | |||
label = label, | |||
accel = accel and {form = accel} or nil, | |||
} | |||
end | end | ||
-- The main entry point. | -- The main entry point. | ||
function export.show(frame) | function export.show(frame) | ||
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.") | local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.") | ||
| Line 38: | Line 43: | ||
["head"] = {list = true, disallow_holes = true}, | ["head"] = {list = true, disallow_holes = true}, | ||
["nomut"] = {type = "boolean"}, | ["nomut"] = {type = "boolean"}, | ||
["type"] = {set = {"b", "s"}, default = "b"}, | |||
} | } | ||
| Line 74: | Line 80: | ||
----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | ||
local allowed_genders = m_table.listToSet | local allowed_genders = m_table.listToSet{ | ||
"m", "f", "mf", "mfbysense", "mfequiv", "gneut", "n", | |||
"m-p", "f-p", "mf-p", "mfbysense-p", "mfequiv-p", "gneut-p", "n-p", | |||
"m-s", "f-s", "mf-s", "mfbysense-s", "mfequiv-s", "gneut-s", "n-s", | |||
"?", "?-p", "?-s" | |||
} | |||
local function validate_genders(genders) | local function validate_genders(genders) | ||
| Line 88: | Line 97: | ||
end | end | ||
end | end | ||
local function do_noun(args, data, is_proper) | local function do_noun(args, data, is_proper) | ||
local default_plural_endings = { | |||
m = (args.type == "s" and "e" or "") .. "ar", | |||
f = (args.type == "b" and "á" or "") .. "ir", | |||
} | |||
-- Extracts the base gender ("m", "f", etc.) ignoring number suffixes like "-p" or "-s" | |||
local function get_base_gender(g) | |||
if type(g) == "table" then g = g.spec end | |||
g = g:gsub("%-p$", ""):gsub("%-s$", "") | |||
if g == "mf" then return {"m", "f"} end | |||
if default_plural_endings[g] then return {g} end | |||
return {} | |||
end | |||
local is_plurale_tantum = false | local is_plurale_tantum = false | ||
local category_pos = m_en_util.singularize(data.pos_category) | local category_pos = m_en_util.singularize(data.pos_category) | ||
| Line 95: | Line 120: | ||
validate_genders(args[1]) | validate_genders(args[1]) | ||
data.genders = args[1] | data.genders = args[1] | ||
-- Check for specific genders and pluralia tantum. | -- Check for specific genders and pluralia tantum. | ||
local base_genders_present = {} | |||
for _, g in ipairs(args[1]) do | for _, g in ipairs(args[1]) do | ||
if type(g) == "table" then | if type(g) == "table" then | ||
| Line 102: | Line 129: | ||
if g:find("-p$") then | if g:find("-p$") then | ||
is_plurale_tantum = true | is_plurale_tantum = true | ||
end | |||
for _, bg in ipairs(get_base_gender(g)) do | |||
base_genders_present[bg] = true | |||
end | end | ||
end | end | ||
local lemma = data.pagename | local lemma = data.pagename | ||
local plurals = {} | local plurals = {} | ||
if is_plurale_tantum then | if is_plurale_tantum then | ||
| Line 126: | Line 143: | ||
error("Can't specify plurals of plurale tantum " .. category_pos) | error("Can't specify plurals of plurale tantum " .. category_pos) | ||
end | end | ||
else | else | ||
plurals = m_hw_util.parse_term_list_with_modifiers { | plurals = m_hw_util.parse_term_list_with_modifiers { | ||
| Line 133: | Line 149: | ||
splitchar = ",", | splitchar = ",", | ||
} | } | ||
-- Check for special plural signals | -- Check for special plural signals | ||
local mode = nil | local mode = nil | ||
local pl1 = plurals[1] | local pl1 = plurals[1] | ||
if pl1 and #pl1.term == 1 then | if pl1 and #pl1.term == 1 then | ||
| Line 149: | Line 165: | ||
end | end | ||
end | end | ||
if args.mut then | |||
local mutation = { | |||
["r"] = "radical", ["l"] = "lenite", ["e"] = "eclipse" | |||
} | |||
table.insert(data.inflections, {label = mutation[args.mut]}) | |||
end | |||
if is_plurale_tantum then | if is_plurale_tantum then | ||
table.insert(data.inflections, {label = "sometimes " .. glossary_link("plural only") .. ", in variation"}) | |||
table.insert(data.inflections, {label = "sometimes " . | |||
end | end | ||
if mode == "?" then | if mode == "?" then | ||
table.insert(data.categories, langname .. " " .. data.pos_category .. " with unknown or uncertain plurals") | table.insert(data.categories, langname .. " " .. data.pos_category .. " with unknown or uncertain plurals") | ||
elseif mode == "!" then | elseif mode == "!" then | ||
table.insert(data.inflections, {label = "plural not attested"}) | table.insert(data.inflections, {label = "plural not attested"}) | ||
table.insert(data.categories, langname .. " " .. data.pos_category .. " with unattested plurals") | table.insert(data.categories, langname .. " " .. data.pos_category .. " with unattested plurals") | ||
| Line 165: | Line 186: | ||
end | end | ||
elseif mode == "-" then | elseif mode == "-" then | ||
table.insert(data.categories, langname .. " uncountable " .. data.pos_category) | |||
if plurals[1] then | if plurals[1] then | ||
table.insert(data.inflections, {label = "usually " . | table.insert(data.inflections, {label = "usually " .. glossary_link("uncountable")}) | ||
table.insert(data.categories, langname .. " countable " .. data.pos_category) | table.insert(data.categories, langname .. " countable " .. data.pos_category) | ||
else | else | ||
table.insert(data.inflections, {label = | table.insert(data.inflections, {label = glossary_link("uncountable")}) | ||
end | end | ||
else | else | ||
if not plurals[1] and not is_proper then | if not plurals[1] and not is_proper then | ||
plurals[1] = {term = "+"} | plurals[1] = {term = "+"} | ||
end | end | ||
if mode == "~" then | if mode == "~" then | ||
table.insert(data.inflections, {label = glossary_link("countable") .. " and " .. glossary_link("uncountable")}) | |||
table.insert(data.inflections, {label = | |||
table.insert(data.categories, langname .. " uncountable " .. data.pos_category) | table.insert(data.categories, langname .. " uncountable " .. data.pos_category) | ||
table.insert(data.categories, langname .. " countable " .. data.pos_category) | table.insert(data.categories, langname .. " countable " .. data.pos_category) | ||
elseif plurals[1] then | elseif plurals[1] then | ||
table.insert(data.categories, langname .. " countable " .. data.pos_category) | table.insert(data.categories, langname .. " countable " .. data.pos_category) | ||
else | else | ||
table.insert(data.categories, langname .. " uncountable " .. data.pos_category) | table.insert(data.categories, langname .. " uncountable " .. data.pos_category) | ||
end | end | ||
| Line 197: | Line 211: | ||
for _, pl in ipairs(plurals) do | for _, pl in ipairs(plurals) do | ||
if pl.term == "+" then | if pl.term == "+" then | ||
for _ | local generated_any = false | ||
table.insert(new_plurals, | -- Generate default plurals for all matched base genders | ||
for bg, _ in pairs(base_genders_present) do | |||
table.insert(new_plurals, {term = lemma .. default_plural_endings[bg]}) | |||
generated_any = true | |||
end | |||
-- Fallback if no specific gender mapped | |||
if not generated_any then | |||
table.insert(new_plurals, {term = lemma .. "ar"}) | |||
end | end | ||
else | else | ||
| Line 206: | Line 227: | ||
plurals = new_plurals | plurals = new_plurals | ||
insert_inflection(data, plurals, "plural", "p") | |||
if plurals[2] then | if plurals[2] then | ||
| Line 212: | Line 233: | ||
end | end | ||
end | end | ||
-- Generalized handler for other gendered forms with specific default suffixes | |||
local function process_gender_form(param, label, accel, default_suffix) | |||
local forms = m_hw_util.parse_term_list_with_modifiers { | |||
paramname = param, | |||
forms = args[param], | |||
splitchar = ",", | |||
} | |||
if forms[1] then | |||
local new_forms = {} | |||
for _, f in ipairs(forms) do | |||
if f.term == "+" and default_suffix then | |||
table.insert(new_forms, {term = lemma .. default_suffix}) | |||
else | |||
table.insert(new_forms, f) | |||
end | |||
end | |||
insert_inflection(data, new_forms, label, accel) | |||
end | |||
end | |||
process_gender_form("m", "masculine", "m") | |||
process_gender_form("f", "feminine", "f") | |||
process_gender_form("mpl", "masculine plural", "m|p", default_plural_endings["m"]) | |||
process_gender_form("fpl", "feminine plural", "f|p", default_plural_endings["f"]) | |||
-- Extensible for new forms like neuter: | |||
-- process_gender_form("n", "neuter", "n") | |||
-- process_gender_form("npl", "neuter plural", "n|p", default_plural_endings["n"]) | |||
end | end | ||
| Line 218: | Line 267: | ||
[1] = {list = "g", disallow_holes = true, required = not is_proper, default = "?", type = "genders", flatten = true}, | [1] = {list = "g", disallow_holes = true, required = not is_proper, default = "?", type = "genders", flatten = true}, | ||
[2] = {list = "pl", disallow_holes = true}, | [2] = {list = "pl", disallow_holes = true}, | ||
[" | ["m"] = {list = true}, | ||
["f"] = {list = true}, | |||
["mpl"] = {list = true}, | |||
["fpl"] = {list = true}, | |||
["mut"] = {set = {"r", "l", "e"}} | |||
} | } | ||
end | end | ||
| Line 232: | Line 285: | ||
do_noun(args, data, "is proper noun") | do_noun(args, data, "is proper noun") | ||
end, | end, | ||
} | |||
----------------------------------------------------------------------------------------- | |||
-- Adjectives -- | |||
----------------------------------------------------------------------------------------- | |||
local function do_adj(args, data) | |||
local lemma = data.pagename | |||
if args.inv then | |||
table.insert(data.inflections, {label = glossary_link("invariable")}) | |||
table.insert(data.categories, langname .. " indeclinable " .. data.pos_category) | |||
else | |||
local function process_adj_form(param, default_suffix, label, accel) | |||
local forms = m_hw_util.parse_term_list_with_modifiers { | |||
paramname = param, | |||
forms = args[param], | |||
splitchar = ",", | |||
} | |||
if not forms[1] then | |||
forms = {{term = lemma .. default_suffix}} | |||
else | |||
local new_forms = {} | |||
for _, f in ipairs(forms) do | |||
if f.term == "+" then | |||
table.insert(new_forms, {term = lemma .. default_suffix}) | |||
else | |||
table.insert(new_forms, f) | |||
end | |||
end | |||
forms = new_forms | |||
end | |||
insert_inflection(data, forms, label, accel) | |||
end | |||
process_adj_form("comp", (args.type == "s" and "e" or "") .. "ar", "comparative", "comp") | |||
process_adj_form("sup", (args.type == "s" and "e" or "") .. "ast", "superlative", "sup") | |||
end | |||
end | |||
pos_functions["adjectives"] = { | |||
params = { | |||
["comp"] = {list = true, disallow_holes = true}, | |||
["sup"] = {list = true, disallow_holes = true}, | |||
["inv"] = {type = "boolean"}, | |||
}, | |||
func = do_adj, | |||
} | |||
----------------------------------------------------------------------------------------- | |||
-- Verbs -- | |||
----------------------------------------------------------------------------------------- | |||
local function do_verb(args, data) | |||
local lemma = data.pagename | |||
if args.irr then | |||
table.insert(data.categories, langname .. " irregular verbs") | |||
else | |||
local function process_verb_form(param, default_suffix, label) | |||
local forms = m_hw_util.parse_term_list_with_modifiers { | |||
paramname = param, | |||
forms = args[param], | |||
splitchar = ",", | |||
} | |||
if match(lemma, "[aeiouàèìòù]$") then | |||
default_suffix = "th" .. default_suffix | |||
end | |||
if not forms[1] then | |||
forms = {{term = lemma .. default_suffix}} | |||
else | |||
local new_forms = {} | |||
for _, f in ipairs(forms) do | |||
if f.term == "+" then | |||
table.insert(new_forms, {term = lemma .. default_suffix}) | |||
else | |||
table.insert(new_forms, f) | |||
end | |||
end | |||
forms = new_forms | |||
end | |||
insert_inflection(data, forms, label) | |||
end | |||
process_verb_form("pres", (args.type == "b" and "á" or "") .. "ir", "present") | |||
process_verb_form("past", (args.type == "s" and "e" or "") .. "aidhir", "past") | |||
process_verb_form("fut", (args.type == "b" and "á" or "") .. "ist", "future") | |||
process_verb_form("cond", (args.type == "s" and "e" or "") .. "aidhist", "conditional") | |||
end | |||
end | |||
pos_functions["verbs"] = { | |||
params = { | |||
["pres"] = {list = true, disallow_holes = true}, | |||
["past"] = {list = true, disallow_holes = true}, | |||
["cond"] = {list = true, disallow_holes = true}, | |||
["fut"] = {list = true, disallow_holes = true}, | |||
["irr"] = {type = "boolean"}, | |||
}, | |||
func = do_verb, | |||
} | } | ||
return export | return export | ||