Modul:gem-headword
Utsehn
This module generates headwords for Proto-Germanic terms.
local lang = require("Module:languages").getByCode("gem-pro")
local export = {}
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local args = frame:getParent().args
SUBPAGENAME = mw.title.getCurrentTitle().subpageText
local head = args["head"]; if head == "" then head = nil end
-- The part of speech. This is also the name of the category that
-- entries go in. However, the two are separate (the "cat" parameter)
-- because you sometimes want something to behave as an adjective without
-- putting it in the adjectives category.
local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
local cat = args["cat"]; if cat == "" then cat = nil end
local genders = {}
local inflections = {}
local categories = {"Proto-Germaansch " .. (cat or poscat)}
local ctemp = {}
if poscat == "Substantiven" then
if SUBPAGENAME:find("^-") then
categories = {"Proto-Germaansch " .. (cat or "noun-forming suffixes")}
end
genders, ctemp = noun_gender(args)
for k,v in ipairs(ctemp) do table.insert(categories, v) end
elseif poscat == "proper nouns" then
genders, ctemp = noun_gender(args)
for k,v in ipairs(ctemp) do table.insert(categories, v) end
elseif poscat == "Adjektiven" then
inflections, ctemp = adjective(args)
for k,v in ipairs(ctemp) do table.insert(categories, v) end
elseif poscat == "adverbs" then
inflections, ctemp = adverb(args)
for k,v in ipairs(ctemp) do table.insert(categories, v) end
end
return require("Module:headword").full_headword(lang, nil, head, nil, genders, inflections, categories, nil)
end
-- Display information for a noun's gender
-- This is separate so that it can also be used for proper nouns
function noun_gender(args)
local categories = {}
local valid_genders = {
["m"] = true,
["f"] = true,
["n"] = true,
["m-p"] = true,
["f-p"] = true,
["n-p"] = true}
-- Iterate over all gn parameters (g2, g3 and so on) until one is empty
local genders = {}
local g = args[1] or ""; if g == "" then g = "?" end
local i = 2
while g ~= "" do
if not valid_genders[g] then
g = "?"
end
-- If any of the specifications is a "?", add the entry
-- to a cleanup category.
if g == "?" then
table.insert(categories, "Proto-Germanic terms with incomplete gender")
elseif g == "m-p" or g == "f-p" or g == "n-p" then
table.insert(categories, "Proto-Germanic pluralia tantum")
end
table.insert(genders, g)
g = args["g" .. i] or ""
i = i + 1
end
return genders, categories
end
function adjective(args)
local inflections = {}
local categories = {}
local adverb = args["adv"]; if adverb == "" then adverb = nil end
local comparative = args[1]; if comparative == "" then comparative = nil end
local superlative = args[2]; if superlative == "" then superlative = nil end
if adverb then
table.insert(inflections, {
"adverb", adverb})
end
if comparative then
table.insert(inflections, {
"comparative", comparative})
end
if superlative then
table.insert(inflections, {
"superlative", superlative})
end
return inflections, categories
end
function adverb(args)
local inflections = {}
local categories = {}
local adjective = args["adj"]; if adjective == "" then adjective = nil end
local comparative = args[1]; if comparative == "" then comparative = nil end
local superlative = args[2]; if superlative == "" then superlative = nil end
if adjective then
table.insert(inflections, {
"adjective", adjective})
end
if comparative then
table.insert(inflections, {
"comparative", comparative})
end
if superlative then
table.insert(inflections, {
"superlative", superlative})
end
return inflections, categories
end
return export