Module:frm-headword

This module is used for some Middle French headword-line templates.

The module is always invoked the same way, by passing a single parameter to the "show" function. This parameter is the name of the part of speech, but in plural (examples given are for nouns, and for adjective forms respectively):

{{#invoke:frm-headword|show|nouns}}
{{#invoke:frm-headword|show|adjective forms}}

There is no parameter for the sort key, because this is not necessary. The sort key is automatically generated according to the normal alphabetical ordering in Middle French.


local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("frm")
local m_headword = require("Module:headword")

-- Clone parent's args while also assigning nil to empty strings.
-- Taken from module ru-headword.
local function clone_args(frame)
	local args = {}
	for pname, param in pairs(frame:getParent().args) do
		if param == "" then args[pname] = nil
		else args[pname] = param
		end
	end
	return args
end

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local args = clone_args(frame)
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	HEAD = args["head"] or mw.title.getCurrentTitle().subpageText

	local genders = {}
	local inflections = {}
	local categories = {"Middle French " .. poscat}

	if pos_functions[poscat] then
		pos_functions[poscat](args, genders, inflections, categories, wv)
	end

	return m_headword.full_headword{
		lang = lang,
		heads = {HEAD},
		genders = genders,
		inflections = inflections,
		categories = categories,
		sort_key = sort
	}
end

-- Apply ts > s and és > ez changes.
local function mp_morph(string)
	string = mw.ustring.gsub(string, "ts$", "s")
	string = mw.ustring.gsub(string, "és$", "ez")
	return string
end

local function make_mp()
	local plurals = {}
	if mw.ustring.match(HEAD, "[sxz]$") then
		table.insert(plurals, HEAD)
	elseif mw.ustring.match(HEAD, "eau$") ~= nil then
		table.insert(plurals, HEAD .. "x")
		table.insert(plurals, HEAD .. "lx") -- -eaulx is as common as -eaux
	elseif mw.ustring.match(HEAD, "al$") ~= nil then
		local al = mw.ustring.gsub(HEAD, "al$", "aux")
		table.insert(plurals, al) -- -aulx is less common then -alx
	else
		table.insert(plurals, mp_morph(HEAD .. "s"))
	end
	return plurals
end

pos_functions["adjectives"] = function(args, genders, inflections, categories)
	local g = args["g"] or args[1]
	local f = args["f"] or args[1]
	local plurals = {}
		table.insert(plurals, args["mp"] or args[2])
		table.insert(plurals, 2, args["mp2"])
	local fp = args["fp"] or args[3]
	local mfp = args["pl"]

	table.insert(genders, "m")

	if g == "m-f" or g == "mf" then
		table.insert(genders, "f")

		mfp = mp_morph(HEAD .. "s")

		table.insert(inflections, {label = "plural", accel = {form = "p"}, mfp})
	else
		if not fs then
			if mw.ustring.match(HEAD, "é$") ~= nil then
				fs = mw.ustring.gsub(HEAD, "é$", "ee")
			elseif mw.ustring.match(HEAD, "és$") ~= nil then
				fs = mw.ustring.gsub(HEAD, "és$", "esse")
			elseif mw.ustring.match(HEAD, "if$") ~= nil then
				fs = mw.ustring.gsub(HEAD, "if$", "ifve")
			elseif mw.ustring.match(HEAD, "eux") ~= nil then
				fs = mw.ustring.gsub(HEAD, "eux$", "euse")
			else
				fs = HEAD .. "e"
			end
		end

		if not plurals[1] then plurals = make_mp() end

		if not fp then
			fp = fs .. "s"
		end

		table.insert(inflections, {label = "feminine singular", accel = {form = "f|s"}, fs})
		table.insert(inflections, {label = "masculine plural", accel = {form = "m|p"}, plurals[1]})
		if plurals[2] then table.insert(inflections[2], plurals[2]) end
		table.insert(inflections, {label = "feminine plural", accel = {form = "f|p"}, fp})
	end
end

pos_functions["nouns"] = function(args, genders, inflections, categories)
	local g = args["g"] or args[1]
	local plurals = {}
	if args[2] ~= "-" then
		table.insert(plurals, args["pl"] or args[2])
	else
		table.insert(plurals, args["pl"])
	end
	table.insert(plurals, args["pl2"] or nil)
	local fs = args["f"]
	local fp = args["fp"]

	if not g then
		table.insert(genders, "?")
	else
		table.insert(genders, g)
		if args["g2"] then table.insert(genders, args["g2"]) end
	end

	if not plurals[1] then plurals = make_mp() end

	local function uncoutable_label_gen(p)
		export = "[[Appendix:Glossary#uncountable|uncountable]]"
		if args["pl"] then export = "usually " .. export end
		return export
	end

	if args[2] == "-" then
		table.insert(inflections, {label = uncoutable_label_gen(plurals[1])})
		pl_inflection_number = 1
		if args["pl"] then
			table.insert(inflections, {label = "plural", accel = {form = "p"}, args["pl"]})
		end
	else
		table.insert(inflections, {label = "plural", accel = {form = "p"}, plurals[1]})
		if plurals[2] then table.insert(inflections[1], plurals[2]) end
	end

	if fs then
		table.insert(inflections, {label = "feminine singular", accel = {form = "f|s"}, fs})
		fp = fp or (fs .. "s")
		table.insert(inflections, {label = "feminine plural", accel = {form = "f|p"}, fp})
	end
end

return export