Module:la-headword

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
Text-x-generic with pencil.svg This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}
local pos_functions = {}

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

-- 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 genders = {}
	local inflections = {}
	local categories = {"Latin " .. (mw.title.getCurrentTitle().nsText == "Appendix" and "reconstructed " or "") .. poscat}
	local infl_classes = {}
	local appendix = {}
	
	if pos_functions[poscat] then
		local head2 = pos_functions[poscat](class, args, genders, inflections, categories, infl_classes, appendix)
		head = head or head2
	end
	
	return
		require("Module:headword").full_headword(lang, sc, head, nil, genders, inflections, categories, nil) ..
		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, genders, inflections, categories, infl_classes, appendix)
	local head = args[1]; if head == "" then head = nil end
	local gender = args[4]; if gender == "" then gender = nil end
	local gender2 = args["g2"]; if gender2 == "" then gender2 = nil end
	local genitive = args[3]; if genitive == "" then genitive = nil end
	local genitive2 = args["gen2"]; if genitive2 == "" then genitive2 = nil end
	local infl_class = args[5]; if infl_class == "" then infl_class = nil end
	
	table.insert(genders, gender)
	
	if gender2 then
		table.insert(genders, gender2)
	end

	if #genders == 0 then
		table.insert(genders, "?")
	end
	
	if genitive then
		local forms = {label = "genitive", genitive}
		
		if genitive2 then
			table.insert(forms, genitive2)
		end
		
		table.insert(inflections, forms)
	else
		if NAMESPACE == "Template" then
			table.insert(inflections, {label = "genitive", "genitive"})
		else
			error("Please provide the genitive.")
		end
	end
	
	if infl_class then
		table.insert(infl_classes, "[[Appendix:Latin " .. infl_class .. " declension|" .. infl_class .. " declension]]")
	else
		if NAMESPACE == "Template" then
			table.insert(infl_classes, "? declension")
		else
			error("Please provide the declension class.")
		end
	end
	
	return head
end

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

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

pos_functions["adjectives-m-f-n"] = function(class, args, genders, inflections, categories, infl_classes, appendix)
	params = {
		[1] = {required = true},
		[2] = {required = true},
		[3] = {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)
	table.insert(args.head, 1, args[1])
	table.insert(args.f, 1, args[2])
	table.insert(args.n, 1, args[3])
	
	if NAMESPACE == "Appendix" then
		for _,array in ipairs({args.f, args.n, args.comp, args.sup}) do
			for i,param in ipairs(array) do
				array[i] = {term = "Appendix:Latin/" .. param, alt = param}
			end
		end
	end
	
	args.f.label = "feminine"
	args.n.label = "neuter"
	
	table.insert(genders, "m")
	
	table.insert(inflections, args.f)
	table.insert(inflections, args.n)
	if args.comp[1] then
		args.comp.label = "comparative"
		table.insert(inflections, args.comp)
	end
	if args.sup[1] then
		args.sup.label = "superlative"
		table.insert(inflections, args.sup)
	end
	
	if class == "1&2" then
		table.insert(infl_classes, "[[Appendix:Latin first declension|first]]")
		table.insert(infl_classes, "[[Appendix:Latin second declension|second declension]]")
	elseif class == "3-3E" then
		table.insert(infl_classes, "[[Appendix:Latin third declension|third declension]]")
	end
	
	return args.head
end

pos_functions["adjectives-mfn-gen"] = function(class, args, genders, inflections, categories, infl_classes, appendix)
	params = {
		[1] = {required = true},
		[2] = {required = true},
		["head"] = {list = true},
		["gen"] = {list = true},
		["comp"] = {list = true},
		["sup"] = {list = true}
	}
	local args = require("Module:parameters").process(args, params)
	table.insert(args.head, 1, args[1])
	table.insert(args.gen, 1, args[2])

	if NAMESPACE == "Appendix" then
		for _,array in ipairs({args.gen, args.comp, args.sup}) do
			for i,param in ipairs(array) do
				array[i] = {term = "Appendix:Latin/" .. param, alt = param}
			end
		end
	end
	
	args.gen.label = "genitive"

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

	table.insert(inflections, args.gen)

	if args.comp[1] then
		args.comp.label = "comparative"
		table.insert(inflections, args.comp)
	end
	if args.sup[1] then
		args.sup.label = "superlative"
		table.insert(inflections, args.sup)
	end
	
	if class == "3-1E" then
		table.insert(infl_classes, "[[Appendix:Latin third declension|third declension]]")
	end
	
	return args.head
end

pos_functions["adjectives-mf-n"] = function(class, args, genders, inflections, categories, infl_classes, appendix)
	params = {
		[1] = {required = true},
		[2] = {required = true},
		["head"] = {list = true},
		["n"] = {list = true},
		["comp"] = {list = true},
		["sup"] = {list = true},
		["new"] = {}
	}
	local args = require("Module:parameters").process(args, params)
	table.insert(args.head, 1, args[1])
	table.insert(args.n, 1, args[2])
	
	if NAMESPACE == "Appendix" then
		for _,array in ipairs({args.n, args.comp, args.sup}) do
			for i,param in ipairs(array) do
				array[i] = {term = "Appendix:Latin/" .. param, alt = param}
			end
		end
	end
	
	args.n.label = "neuter"
	
	table.insert(genders, "m")
	table.insert(genders, "f")
	
	table.insert(inflections, args.n)
	
	if args.comp[1] then
		args.comp.label = "comparative"
		table.insert(inflections, args.comp)
	end
	if args.sup[1] then
		args.sup.label = "superlative"
		table.insert(inflections, args.sup)
	end
	
	if class == "3-2E" then
		table.insert(infl_classes, "[[Appendix:Latin third declension|third declension]]")
	end
	
	return args.head
end

return export