မော်ဂျူး:la-headword

ဝစ်ရှင်နရီ မှ

Documentation for this module may be created at မော်ဂျူး:la-headword/doc

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"},
		id = {},
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = args.head
	data.id = args.id
	
	for _, g in ipairs(args.g) do
		if legal_gender[g] then
			table.insert(data.genders, g)
			table.insert(data.categories, "လက်တင် " .. gender_names[g] .. " နာမ်များ")
		else
			error("Gender “" .. g .. "” is not an valid Latin gender.")
		end
	end

	if args.indecl then
		table.insert(data.inflections, {label = "[[နောက်ဆက်တွဲ:ခက်ဆစ်#indeclinable|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|" .. 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 = {},
		id = {},
	}
	local args = require("Module:parameters").process(args,params)
	data.heads = args.head
	data.id = args.id
	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, "[[နောက်ဆက်တွဲ:Latin first conjugation|first conjugation]]")
	elseif conj == "2" then
		table.insert(appendix, "[[နောက်ဆက်တွဲ:Latin second conjugation|second conjugation]]")
	elseif conj == "3" then
		table.insert(appendix, "[[နောက်ဆက်တွဲ:Latin third conjugation|third conjugation]]")
	elseif conj == "io" then
		table.insert(appendix, "[[နောက်ဆက်တွဲ:Latin third conjugation|third conjugation]] iō-variant")
	elseif conj == "4" then
		table.insert(appendix, "[[နောက်ဆက်တွဲ:Latin fourth conjugation|fourth conjugation]]")
	elseif conj == "irreg" then --sum
		table.insert(appendix, "[[နောက်ဆက်တွဲ:Latin irregular verbs|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#အင်္ဂလိပ်|impersonal]]")
	elseif pattern == "impers-nopass" then --advesperāscit
		table.insert(appendix,"[[impersonal#အင်္ဂလိပ်|impersonal]]")
		table.insert(appendix,"no [[passive#အင်္ဂလိပ်|passive]]")
	elseif pattern == "impers-depon" then
		table.insert(appendix,"[[impersonal#အင်္ဂလိပ်|impersonal]]")
		table.insert(appendix,"[[deponent#အင်္ဂလိပ်|deponent]]")
	elseif pattern == "depon" then --dēmōlior
		table.insert(appendix,"[[deponent#အင်္ဂလိပ်|deponent]]")
	elseif pattern == "semi-depon" then --fido
		table.insert(appendix,"[[semi-deponent#အင်္ဂလိပ်|semi-deponent]]")
	elseif pattern == "depon-noperf" then --calvor
		table.insert(appendix,"[[deponent#အင်္ဂလိပ်|deponent]]")
		table.insert(appendix,"no [[perfect#အင်္ဂလိပ်|perfect]]")
	elseif pattern == "noperf" then --īnsolēscō
		table.insert(appendix,"no [[perfect#အင်္ဂလိပ်|perfect]]")
	elseif pattern == "no-actv-perf" then --interstinguō
		table.insert(appendix,"[[defective#အင်္ဂလိပ်|defective]]")
	elseif pattern == "no-pasv-perf" then --ārēscō
		table.insert(appendix,"[[defective#အင်္ဂလိပ်|defective]]")
	elseif pattern == "nopass-noperf" then --albēscō
		table.insert(appendix,"no [[perfect#အင်္ဂလိပ်|perfect]] or [[supine#အင်္ဂလိပ်|supine]] forms")
	elseif pattern == "nopass" then --coacēscō
		table.insert(appendix,"no [[passive#အင်္ဂလိပ်|passive]]")
	elseif pattern == "pass-3only" then --praefundō
		table.insert(appendix,"limited [[passive#အင်္ဂလိပ်|passive]]")
	elseif pattern == "3only-nopass" then --decet
		table.insert(appendix,"[[third person#အင်္ဂလိပ်|third person]] only")
		table.insert(appendix,"no [[passive#အင်္ဂလိပ်|passive]]")
	elseif pattern == "pass-impers" then --abambulō
		table.insert(appendix,"[[impersonal#အင်္ဂလိပ်|impersonal]] in the passive")
	elseif pattern == "perf-as-pres" then --ōdī
		table.insert(appendix,"[[defective#အင်္ဂလိပ်|defective]]")
	elseif pattern == "def" then --āiō
		table.insert(appendix,"[[defective#အင်္ဂလိပ်|defective]]")
	elseif pattern == "short-imp" then --dīcō
		table.insert(appendix,"irregular short [[imperative#အင်္ဂလိပ်|imperative]]")
	elseif pattern == "facio" then --faciō
		table.insert(appendix,"irregular [[passive voice#အင်္ဂလိပ်|passive voice]]")
	elseif pattern == "irreg" then --ferō
		table.insert(appendix,"[[irregular#အင်္ဂလိပ်|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'},
		[2] = {alias_of = 'f'},
		[3] = {alias_of = 'n'},
		["head"] = {list = true, required = true},
		["f"] = {list = true, required = true},
		["n"] = {list = true, required = true},
		["comp"] = {list = true},
		["sup"] = {list = true},
		["id"] = {},
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = args.head
	data.id = args.id
	
	args.f.label = "feminine"
	args.n.label = "neuter"
	
	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, "[[နောက်ဆက်တွဲ:Latin first declension|first]]")
		table.insert(infl_classes, "[[နောက်ဆက်တွဲ:Latin second declension|second declension]]")
	elseif class == "3-3E" then
		table.insert(infl_classes, "[[နောက်ဆက်တွဲ:Latin third declension|third declension]]")
	end
end

pos_functions["adjectives-mfn-gen"] = function(class, args, data, infl_classes, appendix)
	params = {
		[1] = {alias_of = 'head'},
		[2] = {alias_of = 'gen'},
		["head"] = {list = true, required = true},
		["gen"] = {list = true, required = true},
		["comp"] = {list = true},
		["sup"] = {list = true},
		["id"] = {},
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = args.head
	data.id = args.id
	
	args.gen.label = "genitive"
	
	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, "[[နောက်ဆက်တွဲ:Latin third declension|third declension]]")
	end
end

pos_functions["adjectives-mf-n"] = function(class, args, data, infl_classes, appendix)
	params = {
		[1] = {alias_of = 'head'},
		[2] = {alias_of = 'n'},
		["head"] = {list = true, required = true},
		["n"] = {list = true, required = true},
		["comp"] = {list = true},
		["sup"] = {list = true},
		["id"] = {},
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = args.head
	data.id = args.id
	
	args.n.label = "neuter"
	
	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, "[[နောက်ဆက်တွဲ:Latin third declension|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"] = {},
		["id"] = {},
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = args.head
	data.id = args.id
	table.insert(data.categories, "Latin comparative adjectives")
	table.insert(infl_classes, "[[နောက်ဆက်တွဲ:Latin third declension|third declension]]")
	
	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/Template: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"] = {},
		["id"] = {},
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = args.head
	data.id = args.id
	
	table.insert(data.categories, "Latin superlative adjectives")
	table.insert(infl_classes, "[[နောက်ဆက်တွဲ:Latin first declension|first]]")
	table.insert(infl_classes, "[[နောက်ဆက်တွဲ:Latin second declension|second declension]]")
	
	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/Template: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'},
		[2] = {alias_of = 'comp'},
		[3] = {alias_of = 'sup'},
		["head"] = {list = true, required = true},
		["comp"] = {list = true},
		["sup"] = {list = true},
		["id"] = {},
	}
	
	local args = require("Module:parameters").process(args, params)
	data.heads = args.head
	data.id = args.id
	
	if #args.comp > 0 and args.comp[1] ~= "-" 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 = "[[နောက်ဆက်တွဲ:ခက်ဆစ်#superlative|အသာလွန်ဆုံး]]မရှိ"})
		end
		table.insert(data.categories, "Latin irregular adverbs")
	elseif args.comp[1] == "-" then
		table.insert(data.inflections, {label = "[[နောက်ဆက်တွဲ:ခက်ဆစ်#comparative|နှိုင်းယှဉ်မရနိုင်]]"})
		table.insert(data.categories, "Latin uncomparable adverbs")
	else
		local comp = {label = "[[နောက်ဆက်တွဲ:ခက်ဆစ်#comparative|နှိုင်းယှဉ်နိုင်သော]]"}
		local sup = {label = "[[နောက်ဆက်တွဲ:ခက်ဆစ်#superlative|အသာလွန်ဆုံး]]"}
		for _, head in ipairs(args.head) do
			local stem = nil
			for _, suff in ipairs({"iter", "nter", "ter", "er", "iē", "ē", "im", "ō"}) do
				stem = mw.ustring.match(head, "(.*)" .. suff .. "$")
				if stem ~= nil then
					if suff == "nter" then
						stem = stem .. "nt"
						suff = "er"
					end
					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)
		if args.sup[1] ~= '-' then
			table.insert(data.inflections, sup)
		else
			table.insert(data.inflections, {label = "[[နောက်ဆက်တွဲ:ခက်ဆစ်#superlative|အသာလွန်ဆုံး]]မရှိ"})
			table.insert(data.categories, "Latin irregular adverbs")
		end
	end
end

return export