Module:snon-headword: Difference between revisions

No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 33: Line 33:


-- The main entry point.
-- The main entry point.
-- This is the only function that can be invoked from a template.
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 82: Line 81:
"m-s", "f-s", "mf-s", "mfbysense-s", "mfequiv-s", "gneut-s", "n-s",
"m-s", "f-s", "mf-s", "mfbysense-s", "mfequiv-s", "gneut-s", "n-s",
"?", "?-p", "?-s"
"?", "?-p", "?-s"
}
-- Extensible table for default plural endings by gender
local default_plural_endings = {
m = "ar",
f = "ir",
-- Easily add more later, e.g., n = "ur"
}
}


Line 93: Line 99:
end
end
end
end
end
-- 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
end


Line 101: Line 116:
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 108: Line 125:
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 = {}
local function make_plural(term)
return {{term = term .. "ar"}}
end
if is_plurale_tantum then
if is_plurale_tantum then
Line 129: Line 145:
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 150: Line 166:
["r"] = "radical", ["l"] = "lenite", ["e"] = "eclipse"
["r"] = "radical", ["l"] = "lenite", ["e"] = "eclipse"
}
}
table.insert(data.inflections, {label = mutation[args.mut]})
table.insert(data.inflections, {label = mutation[args.mut]})
end
end
if is_plurale_tantum then
if is_plurale_tantum then
-- both singular and plural
table.insert(data.inflections, {label = "sometimes " .. glossary_link("plural only") .. ", in variation"})
table.insert(data.inflections, {label = "sometimes " .. glossary_link("plural only") .. ", in variation"})
end
end
if mode == "?" then
if mode == "?" then
-- Plural is unknown
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
-- Plural is not attested
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 169: Line 182:
end
end
elseif mode == "-" then
elseif mode == "-" then
-- Uncountable noun; may occasionally have a plural
table.insert(data.categories, langname .. " uncountable " .. data.pos_category)
table.insert(data.categories, langname .. " uncountable " .. data.pos_category)
 
-- If plural forms were given explicitly, then show "usually"
if plurals[1] then
if plurals[1] then
table.insert(data.inflections, {label = "usually " .. glossary_link("uncountable")})
table.insert(data.inflections, {label = "usually " .. glossary_link("uncountable")})
Line 180: Line 190:
end
end
else
else
-- Countable or mixed countable/uncountable
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
-- Mixed countable/uncountable noun, always has a plural
table.insert(data.inflections, {label = glossary_link("countable") .. " and " .. glossary_link("uncountable")})
table.insert(data.inflections, {label = glossary_link("countable") .. " and " .. glossary_link("uncountable")})
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
-- Countable nouns
table.insert(data.categories, langname .. " countable " .. data.pos_category)
table.insert(data.categories, langname .. " countable " .. data.pos_category)
else
else
-- Uncountable nouns
table.insert(data.categories, langname .. " uncountable " .. data.pos_category)
table.insert(data.categories, langname .. " uncountable " .. data.pos_category)
end
end
Line 201: Line 207:
for _, pl in ipairs(plurals) do
for _, pl in ipairs(plurals) do
if pl.term == "+" then
if pl.term == "+" then
for _, generated_pl in ipairs(make_plural(lemma)) do
local generated_any = false
table.insert(new_plurals, generated_pl)
-- 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 216: Line 229:
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 222: Line 263:
[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"}}
["mut"] = {set = {"r", "l", "e"}}
}
}
Line 243: Line 288:


local function do_adj(args, data)
local function do_adj(args, data)
local category_pos = m_en_util.singularize(data.pos_category)
local lemma = data.pagename
local lemma = data.pagename
if args.inv then
if args.inv then
-- invariable adjective
table.insert(data.inflections, {label = glossary_link("invariable")})
table.insert(data.inflections, {label = glossary_link("invariable")})
table.insert(data.categories, langname .. " indeclinable " .. data.pos_category)
table.insert(data.categories, langname .. " indeclinable " .. data.pos_category)
else
else
local comps = m_hw_util.parse_term_list_with_modifiers {
local function process_adj_form(param, default_suffix, label, accel)
paramname = "comp",
local forms = m_hw_util.parse_term_list_with_modifiers {
forms = args.comp,
paramname = param,
splitchar = ",",
forms = args[param],
}
splitchar = ",",
}
if not comps[1] then
if not forms[1] then
comps = {{term = lemma .. "ir"}}
forms = {{term = lemma .. default_suffix}}
else
else
local new_comps = {}
local new_forms = {}
for _, c in ipairs(comps) do
for _, f in ipairs(forms) do
if c.term == "+" then
if f.term == "+" then
table.insert(new_comps, {term = lemma .. "ir"})
table.insert(new_forms, {term = lemma .. default_suffix})
else
else
table.insert(new_comps, c)
table.insert(new_forms, f)
end
end
end
forms = new_forms
end
end
comps = new_comps
insert_inflection(data, forms, label, accel)
end
end
 
local sups = m_hw_util.parse_term_list_with_modifiers {
process_adj_form("comp", "ar", "comparative", "comp")
paramname = "sup",
process_adj_form("sup", "ast", "superlative", "sup")
forms = args.sup,
splitchar = ",",
}
if not sups[1] then
sups = {{term = lemma .. "ist"}}
else
local new_sups = {}
for _, s in ipairs(sups) do
if s.term == "+" then
table.insert(new_sups, {term = lemma .. "ist"})
else
table.insert(new_sups, s)
end
end
sups = new_sups
end
insert_inflection(data, comps, "comparative", "comp")
insert_inflection(data, sups, "superlative", "sup")
end
end
end
end
Line 298: Line 323:
pos_functions["adjectives"] = {
pos_functions["adjectives"] = {
params = {
params = {
["comp"] = {list = true, disallow_holes = true},
["sup"] = {list = true, disallow_holes = true},
["sup"] = {list = true, disallow_holes = true},
["comp"] = {list = true, disallow_holes = true},
["inv"] = {type = "boolean"},
["inv"] = {type = "boolean"},
},
},
Line 310: Line 335:


local function do_verb(args, data)
local function do_verb(args, data)
local category_pos = m_en_util.singularize(data.pos_category)
local lemma = data.pagename
local lemma = data.pagename
if args.irr then
if args.irr then
-- irregular verb
table.insert(data.categories, langname .. " irregular verbs")
table.insert(data.categories, langname .. " irregular verbs")
else
else
local presents = m_hw_util.parse_term_list_with_modifiers {
local function process_verb_form(param, default_suffix, label)
paramname = "pres",
local forms = m_hw_util.parse_term_list_with_modifiers {
forms = args.pres,
paramname = param,
splitchar = ",",
forms = args[param],
}
splitchar = ",",
}
if not presents[1] then
if not forms[1] then
presents = {{term = lemma .. "ir"}}
forms = {{term = lemma .. default_suffix}}
else
else
local new_presents = {}
local new_forms = {}
for _, p in ipairs(presents) do
for _, f in ipairs(forms) do
if p.term == "+" then
if f.term == "+" then
table.insert(new_presents, {term = lemma .. "ir"})
table.insert(new_forms, {term = lemma .. default_suffix})
else
else
table.insert(new_presents, p)
table.insert(new_forms, f)
end
end
end
forms = new_forms
end
end
presents = new_presents
insert_inflection(data, forms, label)
end
end
 
local pasts = m_hw_util.parse_term_list_with_modifiers {
process_verb_form("pres", "ir", "present")
paramname = "past",
process_verb_form("past", "adhir", "past")
forms = args.past,
process_verb_form("imp", "adhist", "imperative")
splitchar = ",",
process_verb_form("fut", "ist", "future")
}
if not pasts[1] then
pasts = {{term = lemma .. "adhir"}}
else
local new_pasts = {}
for _, p in ipairs(pasts) do
if p.term == "+" then
table.insert(new_pasts, {term = lemma .. "adhir"})
else
table.insert(new_pasts, p)
end
end
pasts = new_pasts
end
local futures = m_hw_util.parse_term_list_with_modifiers {
paramname = "fut",
forms = args.fut,
splitchar = ",",
}
if not futures[1] then
futures = {{term = lemma .. "ist"}}
else
local new_futures = {}
for _, f in ipairs(futures) do
if f.term == "+" then
table.insert(new_futures, {term = lemma .. "ist"})
else
table.insert(new_futures, f)
end
end
futures = new_futures
end
local statives = m_hw_util.parse_term_list_with_modifiers {
paramname = "stat",
forms = args.stat,
splitchar = ",",
}
if not statives[1] then
statives = {{term = lemma .. "adhist"}}
else
local new_statives = {}
for _, s in ipairs(statives) do
if s.term == "+" then
table.insert(new_statives, {term = lemma .. "adhist"})
else
table.insert(new_statives, s)
end
end
statives = new_statives
end
insert_inflection(data, presents, "present")
insert_inflection(data, pasts, "past")
insert_inflection(data, futures, "future")
insert_inflection(data, statives, "stative")
end
end
end
end
Line 408: Line 373:
["pres"] = {list = true, disallow_holes = true},
["pres"] = {list = true, disallow_holes = true},
["past"] = {list = true, disallow_holes = true},
["past"] = {list = true, disallow_holes = true},
["imp"] = {list = true, disallow_holes = true},
["fut"] = {list = true, disallow_holes = true},
["fut"] = {list = true, disallow_holes = true},
["stat"] = {list = true, disallow_holes = true},
["irr"] = {type = "boolean"},
["irr"] = {type = "boolean"},
},
},