Module:taln-headword: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
Line 26: Line 26:
["pagename"] = {}, -- for testing
["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(parargs, params)
local args = require("Module:parameters").process(parargs, params)

Revision as of 12:28, 21 June 2026



local export = {}
local pos_functions = {}

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

local require_when_needed = require("Module:utilities/require when needed")
local m_headword_utilities = require_when_needed("Module:headword utilities")

local force_cat = false

local insert = table.insert

-- The main entry point.
function export.show(frame)
	local poscat = frame.args[1] or
		error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")

	local parargs = frame:getParent().args

	local params = {
		["head"] = { list = true, disallow_holes = true },
		["tr"] = { list = true, allow_holes = true },
		["id"] = {},
		["nolinkhead"] = { type = "boolean" },
		["pagename"] = {}, -- for testing
	}

	local args = require("Module:parameters").process(parargs, params)

	local pagename = args.pagename or mw.loadData("Module:headword/data").pagename

	local data = {
		lang = lang,
		pos_category = poscat,
		categories = {},
		heads = {},
		genders = {},
		inflections = { enable_auto_translit = true },
		pagename = pagename,
		id = args.id,
		sort_key = args.sort,
		force_cat_output = force_cat,
	}

	local heads = args.head
	for i = 1, #heads do
		insert(data.heads, {
			term = heads[i],
			tr = args.tr[i],
		})
	end

	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end
	
	return require("Module:headword").full_headword(data)
end

pos_functions.nouns = function(args, data)
	local params = {
		["g"] = {required = true, type = "genders"},
		["nopl"] = {type = "boolean"},
		["pl"] = {list = true, allow_holes = false},
	}
	
	args = require("Module:parameters").process(args, params)
	
	local function insert_inflection(terms, label, accel)
		m_headword_utilities.insert_inflection {
			headdata = data,
			terms = terms,
			label = label,
			accel = accel and {form = accel} or nil,
		}
	end
	
	if args.nopl or (pl and pl[1] == "-") then
		insert(data.categories, langname .. " uncountable nouns")
	elseif pl then
		insert_inflection(pl, "plural", "p")
	end
end

pos_functions.verbs = function(args, data)
	local params = {
		["pres"] = {list = true, allow_holes = false},
		["past"] = {list = true, allow_holes = false},
		["part"] = {list = true, allow_holes = false},
	}
	
	args = require("Module:parameters").process(args, params)
	
	local function insert_inflection(terms, label, accel)
		m_headword_utilities.insert_inflection {
			headdata = data,
			terms = terms,
			label = label,
			accel = accel and {form = accel} or nil,
		}
	end
	
	if pres then
		insert_inflection(pres, "first-person singular present", "1|s|pres|ind")
	end
	
	if past then
		insert_inflection(past, "first-person singular past", "1|s|past|ind")
	end
	
	if part then
		insert_inflection(part, "past participle", "pastpart")
	end
end

return export