local export = {}
local pos_functions = {}
local lang = require("Module:languages").getByCode("en")
local function glossary_link(entry, text)
text = text or entry
return "]"
end
local function has_letters_in_alphabetical_order(word)
if not (word:find '^%a+$' and #word > 2) then
return false
end
word = word:lower()
local previous_byte
for letter in word:gmatch '.' do
local byte = letter:byte()
if not (not previous_byte or byte > previous_byte) then
return false
end
previous_byte = byte
end
return true
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 or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local params = {
= {list = true, default = ""},
= {type = "boolean"},
}
if pos_functions then
for key, val in pairs(pos_functions.params) do
params = val
end
end
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = poscat, categories = {}, heads = args, inflections = {}}
if args then
data.pos_category = "suffixes"
if poscat == "adjectives" or poscat == "adverbs" or poscat == "nouns" or poscat == "verbs" 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_functions then
pos_functions.func(args, data)
end
local pagename = mw.title.getCurrentTitle().text
if pagename:find("") or pagename:find("$") then
table.insert(data.categories, lang:getCanonicalName() .. " words containing Q not followed by U")
end
if pagename:find("()%1%1") then
table.insert(data.categories, lang:getCanonicalName() .. " words containing three consecutive instances of the same letter")
end
if pagename:find("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("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("") then
table.insert(data.categories, lang:getCanonicalName() .. " words without vowels")
end
if pagename:find("yre$") then
table.insert(data.categories, lang:getCanonicalName() .. ' words ending in "-yre"')
end
if not pagename:find(" ") and pagename:len() > 25 then
table.insert(data.categories, "Long " .. lang:getCanonicalName() .. ' words')
end
if pagename:find("^*a*e*i*o*u*$") then
table.insert(data.categories, lang:getCanonicalName() .. ' words that use all vowels in alphabetical order')
end
if has_letters_in_alphabetical_order(pagename) then
table.insert(data.categories, lang:getCanonicalName() .. ' words with letters in alphabetical order')
end
return require("Module:headword").full_headword(data)
end
-- This function does the common work between adjectives and adverbs
function make_comparatives(params, data)
local comp_parts = {label = glossary_link("comparable", "comparative"), accel = {form = "comparative"}}
local sup_parts = {label = glossary_link("comparable", "superlative"), accel = {form = "superlative"}}
if #params == 0 then
table.insert(params, {"more"})
end
-- To form the stem, replace -(e)y with -i and remove a final -e.
local stem = PAGENAME:gsub("()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
local sup = val
if comp == "more" and PAGENAME ~= "many" and PAGENAME ~= "much" then
table.insert(comp_parts, "] " .. PAGENAME)
table.insert(sup_parts, "] " .. PAGENAME)
elseif comp == "further" and PAGENAME ~= "far" then
table.insert(comp_parts, "] " .. PAGENAME)
table.insert(sup_parts, "] " .. 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("The superlative of \"" .. comp .. "\" cannot be generated automatically. Please provide it with the \"sup" .. (i == 1 and "" or i) .. "=\" parameter.")
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 = {
params = {
= {list = true, allow_holes = true},
= {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 == "?" then
return
-- If the first parameter is -, then move all parameters up one position.
elseif args == "-" then
shift = 1
is_not_comparable = true
-- If the only argument is +, then remember this and clear parameters
elseif args == "+" and args.maxindex == 1 then
shift = 1
is_comparative_only = true
end
-- Gather all the comparative and superlative parameters.
local params = {}
for i = 1, args.maxindex - shift do
local comp = args
local sup = args
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 = "not " .. glossary_link("comparable")})
table.insert(data.categories, lang:getCanonicalName() .. " uncomparable adjectives")
return
end
if is_comparative_only then
table.insert(data.inflections, {label = glossary_link("comparable", "comparative") .. " form only"})
table.insert(data.categories, lang:getCanonicalName() .. " comparative-only adjectives")
return
end
else
table.insert(data.inflections, {label = "not generally " .. glossary_link("comparable")})
end
end
-- Process the parameters
make_comparatives(params, data)
end
}
pos_functions = {
params = {
= {list = true, allow_holes = true},
= {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 == "?" then
return
-- If the first parameter is -, then move all parameters up one position.
elseif args == "-" then
shift = 1
end
-- Gather all the comparative and superlative parameters.
local params = {}
for i = 1, args.maxindex - shift do
local comp = args
local sup = args
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 = "not " .. glossary_link("comparable")})
table.insert(data.categories, lang:getCanonicalName() .. " uncomparable adverbs")
return
else
table.insert(data.inflections, {label = "not generally " .. glossary_link("comparable")})
end
end
-- Process the parameters
make_comparatives(params, data)
end
}
pos_functions = {
params = {
= {list = true, allow_holes = true},
-- TODO: This should really be a list parameter too...
= {},
= {},
= {},
= {},
= {},
},
func = function(args, data)
-- Gather all the plural parameters from the numbered parameters.
local plurals = {}
for i = 1, args.maxindex do
local pl = args
if pl then
local qual = args
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 == "?" or plurals == "!" or plurals == "-" or plurals == "~" then
mode = plurals
table.remove(plurals, 1) -- Remove the mode parameter
end
-- Plural is unknown
if mode == "?" then
table.insert(data.categories, lang:getCanonicalName() .. " nouns with unknown or uncertain plurals")
return
-- Plural is not attested
elseif mode == "!" then
table.insert(data.inflections, {label = "plural not attested"})
table.insert(data.categories, lang:getCanonicalName() .. " nouns with unattested plurals")
return
-- Uncountable noun; may occasionally have a plural
elseif mode == "-" then
table.insert(data.categories, lang:getCanonicalName() .. " uncountable nouns")
-- If plural forms were given explicitly, then show "usually"
if #plurals > 0 then
table.insert(data.inflections, {label = "usually " .. glossary_link("uncountable")})
table.insert(data.categories, lang:getCanonicalName() .. " countable nouns")
else
table.insert(data.inflections, {label = glossary_link("uncountable")})
end
-- Mixed countable/uncountable noun, always has a plural
elseif mode == "~" then
table.insert(data.inflections, {label = glossary_link("countable") .. " and " .. glossary_link("uncountable")})
table.insert(data.categories, lang:getCanonicalName() .. " uncountable nouns")
table.insert(data.categories, lang:getCanonicalName() .. " countable nouns")
-- If no plural was given, add a default one now
if #plurals == 0 then
plurals = {"s"}
end
-- The default, always has a plural
else
table.insert(data.categories, lang:getCanonicalName() .. " countable nouns")
-- If no plural was given, add a default one now
if #plurals == 0 then
plurals = {"s"}
end
if plural and not mw.title.new(plural).exists then
table.insert(categories, "English nouns with missing plurals")
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 = "plural", accel = {form = "p"}}
local function check_ies(pl, stem)
local newplural, nummatches = stem:gsub("()y$","%1ies")
return nummatches > 0 and pl == newplural
end
local stem = PAGENAME
local irregular = false
for i, pl in ipairs(plurals) do
if pl == "s" then
table.insert(pl_parts, stem .. "s")
elseif pl == "es" then
table.insert(pl_parts, stem .. "es")
else
table.insert(pl_parts, pl)
if type(pl) == "table" then
pl = pl.term
end
if not stem:find(" ") and not (pl == stem .. "s" or pl == stem .. "es" 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() .. " nouns with irregular plurals")
end
table.insert(data.inflections, pl_parts)
end
}
pos_functions = {
params = {
= {list = true},
},
func = function(args, data)
local plurals = args
-- Decide what to do next...
local mode = nil
if plurals == "?" or plurals == "!" or plurals == "-" or plurals == "~" then
mode = plurals
table.remove(plurals, 1) -- Remove the mode parameter
end
-- Plural is unknown
if mode == "?" then
table.insert(data.categories, lang:getCanonicalName() .. " proper nouns with unknown or uncertain plurals")
return
-- Plural is not attested
elseif mode == "!" then
table.insert(data.inflections, {label = "plural not attested"})
table.insert(data.categories, lang:getCanonicalName() .. " proper nouns with unattested plurals")
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 = "usually " .. glossary_link("uncountable")})
table.insert(data.categories, lang:getCanonicalName() .. " countable proper nouns")
else
table.insert(data.inflections, {label = glossary_link("uncountable")})
end
-- Mixed countable/uncountable noun, always has a plural
elseif mode == "~" then
table.insert(data.inflections, {label = glossary_link("countable") .. " and " .. glossary_link("uncountable")})
table.insert(data.categories, lang:getCanonicalName() .. " countable proper nouns")
-- 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() .. " countable proper nouns")
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 = "plural", accel = {form = "p"}}
local stem = PAGENAME
for i, pl in ipairs(plurals) do
if pl == "s" then
table.insert(pl_parts, stem .. "s")
elseif pl == "es" then
table.insert(pl_parts, stem .. "es")
else
table.insert(pl_parts, pl)
end
end
table.insert(data.inflections, pl_parts)
end
}
pos_functions = {
params = {
= {list = "pres_3sg", allow_holes = true},
= {},
= {},
= {},
= {},
= {},
= {list = "pres_ptc", allow_holes = true},
= {},
= {},
= {},
= {},
= {},
= {list = "past", allow_holes = true},
= {},
= {},
= {},
= {},
= {},
= {list = "past_ptc", allow_holes = true},
= {},
= {},
= {},
= {},
= {},
},
func = function(args, data)
-- Get parameters
local par1 = args
local par2 = args
local par3 = args
local par4 = args
local pres_3sg_forms = {label = "third-person singular simple present", accel = {form = "3|s|pres"}}
local pres_ptc_forms = {label = "present participle", accel = {form = "pres|ptcp"}}
local past_forms = {label = "simple past", accel = {form = "past"}}
local pres_3sg_form = par1 or PAGENAME .. "s"
local pres_ptc_form = par2 or PAGENAME .. "ing"
local past_form = par3 or PAGENAME .. "ed"
if par1 and not par2 and not par3 then
-- This is the "new" format, which uses only the first parameter.
if par1 == "es" then
pres_3sg_form = PAGENAME .. "es"
pres_ptc_form = PAGENAME .. "ing"
past_form = PAGENAME .. "ed"
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 .. "ies"
pres_ptc_form = stem .. "ying"
past_form = stem .. "ied"
elseif par1 == "d" then
pres_3sg_form = PAGENAME .. "s"
pres_ptc_form = PAGENAME .. "ing"
past_form = PAGENAME .. "d"
else
pres_3sg_form = PAGENAME .. "s"
pres_ptc_form = par1 .. "ing"
past_form = par1 .. "ed"
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 == "es" then
require("Module:debug").track("en-headword/es3")
pres_3sg_form = par1 .. par2 .. "es"
pres_ptc_form = par1 .. par2 .. "ing"
past_form = par1 .. par2 .. "ed"
elseif par3 == "ing" then
require("Module:debug").track("en-headword/ing3")
pres_3sg_form = PAGENAME .. "s"
pres_ptc_form = par1 .. par2 .. "ing"
if par2 == "y" then
past_form = PAGENAME .. "d"
else
past_form = par1 .. par2 .. "ed"
end
elseif par3 == "ed" then
require("Module:debug").track("en-headword/ed3")
if par2 == "i" then
pres_3sg_form = par1 .. par2 .. "es"
pres_ptc_form = PAGENAME .. "ing"
else
pres_3sg_form = PAGENAME .. "s"
pres_ptc_form = par1 .. par2 .. "ing"
end
past_form = par1 .. par2 .. "ed"
elseif par3 == "d" then
require("Module:debug").track("en-headword/d3")
pres_3sg_form = PAGENAME .. "s"
pres_ptc_form = par1 .. par2 .. "ing"
past_form = par1 .. par2 .. "d"
else
require("Module:debug").track("en-headword/xxx3")
end
else
if par2 == "es" then
require("Module:debug").track("en-headword/es2")
pres_3sg_form = par1 .. "es"
pres_ptc_form = par1 .. "ing"
past_form = par1 .. "ed"
elseif par2 == "ies" then
require("Module:debug").track("en-headword/ies2")
if par1 .. "y" ~= PAGENAME then
require("Module:debug").track("en-headword/ies2/par1 not pagename")
end
pres_3sg_form = par1 .. "ies"
pres_ptc_form = par1 .. "ying"
past_form = par1 .. "ied"
elseif par2 == "ing" then
require("Module:debug").track("en-headword/ing2")
pres_3sg_form = PAGENAME .. "s"
pres_ptc_form = par1 .. "ing"
past_form = par1 .. "ed"
elseif par2 == "ed" then
require("Module:debug").track("en-headword/ed2")
pres_3sg_form = PAGENAME .. "s"
pres_ptc_form = par1 .. "ing"
past_form = par1 .. "ed"
elseif par2 == "d" then
require("Module:debug").track("en-headword/d2")
if par1 ~= PAGENAME then
require("Module:debug").track("en-headword/d2/par1 not pagename")
end
pres_3sg_form = PAGENAME .. "s"
pres_ptc_form = par1 .. "ing"
past_form = par1 .. "d"
else
require("Module:debug").track("en-headword/xxx2")
end
end
end
local pres_3sg_qual = args
local pres_ptc_qual = args
local past_qual = args
table.insert(pres_ptc_forms, {term = pres_ptc_form, qualifiers = {pres_ptc_qual}})
table.insert(pres_3sg_forms, {term = pres_3sg_form, qualifiers = {pres_3sg_qual}})
table.insert(past_forms, {term = past_form, qualifiers = {past_qual}})
-- Present 3rd singular
for i = 2, args.maxindex do
local form = args
local qual = args
if form then
table.insert(pres_3sg_forms, {term = form, qualifiers = {qual}})
end
end
-- Present participle
for i = 2, args.maxindex do
local form = args
local qual = args
if form then
table.insert(pres_ptc_forms, {term = form, qualifiers = {qual}})
end
end
-- Past
for i = 2, args.maxindex do
local form = args
local qual = args
if form then
table.insert(past_forms, {term = form, qualifiers = {qual}})
end
end
-- Past participle
local found_past_ptc = false
local past_ptc_forms = {label = "past participle", accel = {form = "past|ptcp"}}
local qual = args; 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.maxindex do
local form = args
local qual = args
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.term ~= val.term or past_ptc_forms.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 = "simple past and past participle"
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