Module:User:Erutuon/la-headword

local export = {} local pos_functions = {}

local legal_gender = { ["m"] = true, ["m-s"] = true, ["m-p"] = true, ["f"] = true, ["f-s"] = true, ["f-p"] = true, ["n"] = true, ["n-s"] = true, ["n-p"] = true, ["c"] = true, ["c-s"] = true, ["c-p"] = true, ["?"] = true, ["?-s"] = true, ["?-p"] = true, }

local legal_declension = { ["first"] = true, ["second"] = true, ["third"] = true, ["fourth"] = true, ["fifth"] = true, ["irregular"] = true, }

local gender_names = { ["m"] = "masculine", ["m-s"] = "masculine", ["m-p"] = "masculine", ["f"] = "feminine", ["f-s"] = "feminine", ["f-p"] = "feminine", ["n"] = "neuter", ["n-s"] = "neuter", ["n-p"] = "neuter", ["c"] = "common", ["c-s"] = "common", ["c-p"] = "common", ["?"] = "unknown gender", ["?-s"] = "unknown gender", ["?-p"] = "unknown gender", }

local lang = require("Module:languages").getByCode("la") local suffix = nil

-- 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 NAMESPACE = mw.title.getCurrentTitle.nsText PAGENAME = mw.title.getCurrentTitle.text local head = args["head"]; if head == "" then head = nil end local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.") local class = frame.args[2] local suff_type = frame.args.suff_type local postype = nil if suff_type then postype = poscat .. '-' .. suff_type else postype = poscat end local data = {lang = lang, pos_category = (NAMESPACE == "Reconstruction" and "reconstructed " or "") .. poscat, categories = {}, heads = {head}, genders = {}, inflections = {}} local infl_classes = {} local appendix = {} if poscat == "suffixes" then table.insert(data.categories, "Latin " .. suff_type .. "-forming suffixes") suffix = '-' end if pos_functions[postype] then pos_functions[postype](class, args, data, infl_classes, appendix) end if suffix then for i, h in ipairs(data.heads) do data.heads[i] = suffix .. h		end end if mw.ustring.find(mw.ustring.gsub(PAGENAME,"qu","kv"),"[aeiouāēīōū][iu][aeiouāēīōū]") then table.insert(data.categories, "Kenny's testing category 7") end return require("Module:headword").full_headword(data) .. format(infl_classes,"/") .. format(appendix,", ") end

function format(array, concatenater) if #array == 0 then return "" else return "; ''" .. table.concat(array, concatenater) .. "''"	end end

pos_functions["nouns"] = function(class, args, data, infl_classes, appendix) params = { [1] = {alias_of = 'head'}, [2] = {alias_of = 'gen'}, [3] = {alias_of = 'g'}, [4] = {alias_of = 'decl'}, head = {list = true, default = mw.title.getCurrentTitle.text}, gen = {list = true}, g = {list = true, default = '?'}, decl = {list = true}, indecl = {type = "boolean"}, }	local args = require("Module:parameters").process(args, params) data.heads = args.head for _, g in ipairs(args.g) do		if legal_gender[g] then table.insert(data.genders, g) table.insert(data.categories, "Latin " .. gender_names[g] .. " nouns") else error("Gender “" .. g .. "” is not an valid Latin gender.") end end

if args.indecl then table.insert(data.inflections, {label = "indeclinable"}) table.insert(data.categories, "Latin indeclinable nouns") for _, g in ipairs(args.g) do table.insert(data.categories, "Latin " .. gender_names[g] .. " indeclinable nouns") end else if #args.decl > 1 then table.insert(data.inflections, {label = 'variously declined'}) table.insert(data.categories, "Latin nouns with multiple declensions") elseif #args.decl == 0 then if NAMESPACE == "Template" then table.insert(appendix, "? declension") else error("Please provide the declension class.") end end for _, decl_class in ipairs(args.decl) do			if legal_declension[decl_class] then table.insert(appendix, "" .. decl_class .. " declension") if decl_class ~= "irregular" then table.insert(data.categories, "Latin " .. decl_class .. " declension nouns") end for _, g in ipairs(args.g) do table.insert(data.categories, "Latin " .. gender_names[g] .. " nouns in the " .. decl_class .. " declension") end else error("Declension “" .. decl_class .. "” is not an legal Latin declension.") end end if #args.gen == 0 then table.insert(data.inflections, {label = "no genitive"}) table.insert(data.categories, "Latin nouns without a genitive singular") else args.gen.label = "genitive" if suffix then for i, g in ipairs(args.gen) do args.gen[i] = suffix .. g				end end table.insert(data.inflections, args.gen) end end end

pos_functions["proper nouns"] = pos_functions["nouns"] pos_functions["suffixes-noun"] = pos_functions["nouns"]

pos_functions["verbs"] = function(class, args, data, infl_classes, appendix) params = { [1] = {alias_of = 'head'}, [2] = {alias_of = 'inf'}, [3] = {alias_of = 'perf'}, [4] = {alias_of = 'sup'}, [44] = {default = 'supine'}, head = {list = true}, inf = {list = true}, perf = {list = true}, sup = {list = true}, pattern = {}, c = {alias_of = 'conj'}, conj = {} }	local args = require("Module:parameters").process(args,params) data.heads = args.head local conj = args.conj local pattern = args.pattern args.inf.label = "present infinitive" args.perf.label = "perfect active" args.sup.label = args[44] for i, array in ipairs({args.head, args.inf, args.perf, args.sup}) do		for j, param in ipairs(array) do			if mw.ustring.gsub(param,"^[*a-zA-ZĀāĒēĪīŌōŪūȲȳÄäËëÏïÖöÜü ]+$","") ~= "" then table.insert(data.categories,"la-verb invalid parameters") end if i == 3 then array[j] = {term = mw.ustring.gsub(param," sum$",""), alt = param} end end end table.insert(data.inflections, args.inf) if #args.perf > 0 then table.insert(data.inflections, args.perf) end if #args.sup > 0 then table.insert(data.inflections, args.sup) end if #args.perf > 0 and #args.sup == 0 then pattern = pattern or "depon" end if conj == "1" then table.insert(appendix, "first conjugation") elseif conj == "2" then table.insert(appendix, "second conjugation") elseif conj == "3" then table.insert(appendix, "third conjugation") elseif conj == "io" then table.insert(appendix, "third conjugation iō-variant") elseif conj == "4" then table.insert(appendix, "fourth conjugation") elseif conj == "irreg" then --sum table.insert(appendix, "irregular conjugation") else if NAMESPACE == "Template" then table.insert(appendix, "? declension") else table.insert(data.categories, "Latin verbs without the conjugation in their headwords") end end if pattern == "impers" then --decet table.insert(appendix,"impersonal") elseif pattern == "impers-nopass" then --advesperāscit table.insert(appendix,"impersonal") table.insert(appendix,"no passive") elseif pattern == "impers-depon" then table.insert(appendix,"impersonal") table.insert(appendix,"deponent") elseif pattern == "depon" then --dēmōlior table.insert(appendix,"deponent") elseif pattern == "semi-depon" then --fido table.insert(appendix,"semi-deponent") elseif pattern == "depon-noperf" then --calvor table.insert(appendix,"deponent") table.insert(appendix,"no perfect") elseif pattern == "noperf" then --īnsolēscō table.insert(appendix,"no perfect") elseif pattern == "no-actv-perf" then --interstinguō table.insert(appendix,"defective") elseif pattern == "no-pasv-perf" then --ārēscō table.insert(appendix,"defective") elseif pattern == "nopass-noperf" then --albēscō table.insert(appendix,"no perfect or supine forms") elseif pattern == "nopass" then --coacēscō table.insert(appendix,"no passive") elseif pattern == "pass-3only" then --praefundō table.insert(appendix,"limited passive") elseif pattern == "3only-nopass" then --decet table.insert(appendix,"third person only") table.insert(appendix,"no passive") elseif pattern == "pass-impers" then --abambulō table.insert(appendix,"impersonal in the passive") elseif pattern == "perf-as-pres" then --ōdī table.insert(appendix,"defective") elseif pattern == "def" then --āiō table.insert(appendix,"defective") elseif pattern == "short-imp" then --dīcō table.insert(appendix,"irregular short imperative") elseif pattern == "facio" then --faciō table.insert(appendix,"irregular passive voice") elseif pattern == "irreg" then --ferō table.insert(appendix,"irregular") elseif pattern == "noimp" then --no example --I don't know what to do. elseif pattern then table.insert(data.categories, "la-verb invalid parameters") end end

pos_functions["adjectives"] = function(class, args, data, infl_classes, appendix) if class == "1&2" or class == "3-3E" then pos_functions["adjectives-m-f-n"](class, args, data, infl_classes, appendix) elseif class == "3-1E" then pos_functions["adjectives-mfn-gen"](class, args, data, infl_classes, appendix) elseif class == "3-2E" then pos_functions["adjectives-mf-n"](class, args, data, infl_classes, appendix) elseif class == "comp" then pos_functions["adjectives-comp"](class, args, data, infl_classes, appendix) elseif class == "sup" then pos_functions["adjectives-sup"](class, args, data, infl_classes, appendix) end end

pos_functions["adjectives-m-f-n"] = function(class, args, data, infl_classes, appendix) params = { [1] = {alias_of = 'head', required = true}, [2] = {alias_of = 'f', required = true}, [3] = {alias_of = 'n', required = true}, ["head"] = {list = true}, ["f"] = {list = true}, ["n"] = {list = true}, ["comp"] = {list = true}, ["sup"] = {list = true} }	local args = require("Module:parameters").process(args, params) data.heads = args.head args.f.label = "feminine" args.n.label = "neuter" table.insert(data.genders, "m") table.insert(data.inflections, args.f)	table.insert(data.inflections, args.n)	if #args.comp > 0 then args.comp.label = "comparative" table.insert(data.inflections, args.comp) end if #args.sup > 0 then args.sup.label = "superlative" table.insert(data.inflections, args.sup) end if class == "1&2" then table.insert(infl_classes, "first") table.insert(infl_classes, "second declension") elseif class == "3-3E" then table.insert(infl_classes, "third declension") end end

pos_functions["adjectives-mfn-gen"] = function(class, args, data, infl_classes, appendix) params = { [1] = {alias_of = 'head', required = true}, [2] = {alias_of = 'gen', required = true}, ["head"] = {list = true}, ["gen"] = {list = true}, ["comp"] = {list = true}, ["sup"] = {list = true} }	local args = require("Module:parameters").process(args, params) data.heads = args.head args.gen.label = "genitive"

table.insert(data.genders, "m") table.insert(data.genders, "f") table.insert(data.genders, "n")

table.insert(data.inflections, args.gen)

if #args.comp > 0 then args.comp.label = "comparative" table.insert(data.inflections, args.comp) end if #args.sup > 0 then args.sup.label = "superlative" table.insert(data.inflections, args.sup) end if class == "3-1E" then table.insert(infl_classes, "third declension") end end

pos_functions["adjectives-mf-n"] = function(class, args, data, infl_classes, appendix) params = { [1] = {alias_of = 'head', required = true}, [2] = {alias_of = 'n', required = true}, ["head"] = {list = true}, ["n"] = {list = true}, ["comp"] = {list = true}, ["sup"] = {list = true} }	local args = require("Module:parameters").process(args, params) data.heads = args.head args.n.label = "neuter" table.insert(data.genders, "m") table.insert(data.genders, "f") table.insert(data.inflections, args.n)	if #args.comp > 0 then args.comp.label = "comparative" table.insert(data.inflections, args.comp) end if #args.sup > 0 then args.sup.label = "superlative" table.insert(data.inflections, args.sup) end if class == "3-2E" then table.insert(infl_classes, "third declension") end end

pos_functions["adjectives-comp"] = function(class, args, data, infl_classes, appendix) params = { [1] = {alias_of = 'head'}, [2] = {alias_of = 'comp'}, ["head"] = {list = true, default = mw.title.getCurrentTitle.text}, ["comp"] = {}, }	local args = require("Module:parameters").process(args, params) data.heads = args.head table.insert(data.categories, "Latin comparative adjectives") table.insert(infl_classes, "third declension") table.insert(data.genders, "m") table.insert(data.genders, "f") local n = {label = "neuter"} for _, head in ipairs(args.head) do		local neuter = mw.ustring.gsub(head, "or$", "us") table.insert(n, neuter) end table.insert(data.inflections, n)	if args.comp then -- Special:WhatLinksHere/Wiktionary:Tracking/la-adj-comparative require("Module:debug").track("la-adj-comparative") end end

pos_functions["adjectives-sup"] = function(class, args, data, infl_classes, appendix) params = { [1] = {alias_of = 'head'}, [2] = {alias_of = 'sup'}, ["head"] = {list = true, default = mw.title.getCurrentTitle.text}, ["sup"] = {}, }	local args = require("Module:parameters").process(args, params) data.heads = args.head table.insert(data.categories, "Latin superlative adjectives") table.insert(infl_classes, "first") table.insert(infl_classes, "second declension") table.insert(data.genders, "m") local f, n = {label = "feminine"}, {label = "neuter"} for _, head in ipairs(args.head) do		local stem = mw.ustring.gsub(head, "us$", "") table.insert(f, stem .. "a") table.insert(n, stem .. "um") end table.insert(data.inflections, f)	table.insert(data.inflections, n)	if args.sup then -- Special:WhatLinksHere/Wiktionary:Tracking/la-adj-superlative require("Module:debug").track("la-adj-superlative") end end

pos_functions["adverbs"] = function(class, args, data, infl_classes, appendix) params = { [1] = {alias_of = 'head', required = true}, [2] = {alias_of = 'comp'}, [3] = {alias_of = 'sup'}, ["head"] = {list = true}, ["comp"] = {list = true}, ["sup"] = {list = true} }	local args = require("Module:parameters").process(args, params) data.heads = args.head if args.comp[1] == "-" then table.insert(data.inflections, {label = "not comparable"}) table.insert(data.categories, "Latin uncomparable adverbs") else local hasComp = false if #args.comp == 0 then local comp = {} -- label = "comparable" local sup = {} -- label = "superlative" for _, head in ipairs(args.head) do				local stem for _, suff in ipairs({"iter", "nter", "ter", "er", "iē", "ē", "im", "ō"}) do stem = mw.ustring.match(head, "(.*)" .. suff .. "$") if stem then if suff == "nter" then stem = stem .. "nt" suff = "er" end hasComp = true table.insert(comp, stem .. "ius") table.insert(sup, stem .. "issimē") break end end if not stem then error("Unrecognized adverb type, recognized types are “-ē”, “-er”, “-ter”, “-iter”, “-im”, or “-ō” or specify irregular forms or “-” if incomparable.") end end table.insert(data.inflections, comp) end if #args.comp or hasComp then end end if #args.comp > 0 then args.comp.label = "comparative" table.insert(data.inflections, args.comp) if #args.sup > 0 and args.sup[1] ~= "-" then args.sup.label = "superlative" table.insert(data.inflections, args.sup) else table.insert(data.inflections, {label = "no superlative"}) end table.insert(data.categories, "Latin irregular adverbs") elseif args.comp[1] == "-" then else if args.sup[1] ~= '-' then table.insert(data.inflections, sup) else table.insert(data.inflections, {label = "no superlative"}) table.insert(data.categories, "Latin irregular adverbs") end end end

return export