Module:hil-headword

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Headword-line module, used to deploy the Hiligaynon headword-line templates.


local export = {}
local pos_functions = {}

local force_cat = false -- for testing

local lang = require("Module:languages").getByCode("hil")
local langname = lang:getCanonicalName()

-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local poscat = frame.args[1] or require("Module:string utilities").pluralize(args["pos"]) or error("Part of speech has not been specified. Please pass parameter 1= or pos= to the module invocation.")

	local params = {
		["head"] = {list = true, allow_holes = true},
		[1] = {alias_of = "head"},
		["id"] = {},
		["suff"] = {type = "boolean"},
		["nolinkhead"] = {type = "boolean"},
		["json"] = {type = "boolean"},
		["pagename"] = {}, -- for testing
	}
	
	if pos_functions[poscat] then
		for key, val in pairs(pos_functions[poscat].params) do
			params[key] = val
		end
	end
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local pagename = args.pagename or mw.title.getCurrentTitle().subpageText

	local user_specified_heads = args.head

	local data = {
		lang = lang,
		pos_category = poscat,
		categories = {},
		heads = args.head,
		user_specified_heads = user_specified_heads,
		inflections = {},
		pagename = pagename,
		id = args.id,
		force_cat_output = force_cat,
	}

	local is_suffix = false
	if args.suff then
		is_suffix = true
		data.pos_category = "suffixes"
		local singular_poscat = require("Module:string utilities").singularize(poscat)
		table.insert(data.categories, langname .. " " .. singular_poscat .. "-forming suffixes")
		table.insert(data.inflections, {label = singular_poscat .. "-forming suffix"})
	end

	if pos_functions[poscat] then
		pos_functions[poscat].func(args, data, is_suffix)
	end

	local content = mw.title.new(pagename):getContent()
	local code = content and mw.ustring.match(content, "{{hil%-IPA[^}]*}}")

	--Categorize words without [[Template:hil-IPA]]
	if not code then
		table.insert(data.categories, langname .. " terms without hil-IPA template")
	end

	if args.json then
		return require("Module:JSON").toJSON(data)
	end

	return require("Module:headword").full_headword(data)
end


local function handle_infl(args, data, argpref, label, accelform)
	local forms = args[argpref]
	if #forms > 0 then
		forms.label = label
		if accelform then
			forms.accel = {form = accelform}
		end
		table.insert(data.inflections, forms)
	end
end


pos_functions["verbs"] = {
	params = {
		["real"] = {list = true},
		[2] = {alias_of = "real"}, --realis aspect
		["imp"] = {list = true},
		[3] = {alias_of = "imp"}, --imperative
		["dim"] = {list = true},
		["caus"] = {list = true},
		["freq"] = {list = true},
	},
	func = function(args, data)
		handle_infl(args, data, "real", "realis", "realis")
		handle_infl(args, data, "imp", "imperative", "imp")
		handle_infl(args, data, "dim", "diminutive")
		handle_infl(args, data, "caus", "causative")
		handle_infl(args, data, "freq", "frequentative")
	end
}


pos_functions["adjectives"] = {
	params = {
		["sup"] = {list = true},
		[2] = {alias_of = "sup"}, --superlative
		["dim"] = {list = true},
		["caus"] = {list = true},
	},
	func = function(args, data)
		handle_infl(args, data, "sup", "superlative", "superlative")
		handle_infl(args, data, "caus", "causative")
		handle_infl(args, data, "dim", "diminutive")
	end
}


pos_functions["nouns"] = {
	params = {
		["pl"] = {list = true},
		[2] = {alias_of = "pl"}, --special plural cases only
		["dim"] = {list = true},
		["m"] = {list = true},
		["f"] = {list = true},
	},
	func = function(args, data)
		handle_infl(args, data, "pl", "plural", "p")
		handle_infl(args, data, "dim", "diminutive")
		handle_infl(args, data, "f", "feminine")
		handle_infl(args, data, "m", "masculine")
	end
}


return export