Modul:he-headword

Vikilug‘atdan olingan

Bu modul uchun Modul:he-headword/doc nomli hujjat sahifasini yaratishingiz mumkin

local m_headword = require("Module:headword")
local com = require("Module:he-common")

local export = {}
local pos_functions = {}

local tili = require("Module:tili").getByCode("he")

function maybe_get_inflection(args, name, params)
	local tbl = {}
	if type(params) ~= "table" then
		params = {params}
	end
	for _, param in ipairs(params) do
		local paramwv = param .. "wv"
		local paramdwv = param .. "dwv"
		if args[param] or args[paramwv] or args[paramdwv] then
			tbl.label = name
			table.insert(tbl, com.gen_link(args[param], args[paramwv], args[paramdwv]))
		end
	end
	return next(tbl) and tbl
end

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

	local head = args["bosh"]; if head == "" then head = nil end
	if not head then
		local wv = args["wv"]
		local dwv = args["dwv"]
		wv = wv or PAGENAME
		if dwv then
			head = wv .. " \\ " .. dwv
		else
			head = wv
		end
	end
	local tr = args["tr"]
	local genders = {}
	local inflections = {}
	local categories = {"Ivritchada " .. poscat}

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

	table.insert(inflections, maybe_get_inflection(args, "Biblical Hebrew [[w:Pausa|pausal form]]", "pausal"))

	return (m_headword.full_headword(tili, nil, head, tr, genders, inflections, categories))
end

pos_functions["adjectives"] = function(args, genders, inflections, categories)
	table.insert(genders, "m")
	if args["auto"] == nil or args["auto"] == "" then
		-- Use only provided inflections
		table.insert(inflections, maybe_get_inflection(args, "feminine", {"f", "f2"}))
		table.insert(inflections, maybe_get_inflection(args, "masculine plural", {"mp", "mp2"}))
		table.insert(inflections, maybe_get_inflection(args, "feminine plural", "fp"))
	else
		-- Automatically generate inflections
		local stem, stemwv, stemdwv = com.process_wv_triad(args["stem"], args["stemwv"], args["stemdwv"])
		if not stem then
			stemwv = args["wv"] or args["dwv"]
			stemdwv = args["wv"] and args["dwv"]
			stem = com.remove_nikud(stemwv) or PAGENAME
		end
		local f, fwv, fdwv = com.process_wv_triad(args["f"], args["fwv"], args["fdwv"])
		local f2, f2wv, f2dwv = com.process_wv_triad(args["f2"], args["f2wv"], args["f2dwv"])
		local mp, mpwv, mpdwv = com.process_wv_triad(args["mp"], args["mpwv"], args["mpdwv"])
		local mp2, mp2wv, mp2dwv = com.process_wv_triad(args["mp2"], args["mp2wv"], args["mp2dwv"])
		local fp, fpwv, fpdwv = com.process_wv_triad(args["fp"], args["fpwv"], args["fpdwv"])
		if f ~= "-" then
			if not (f or fwv or fdwv) then
				f = stem and (stem .. "ה")
				fwv = stemwv and (stemwv .. "ָה")
				fdwv = stemdwv and (stemdwv .. "ָה")
			end
			tbl = {label = "feminine", com.gen_link(f, fwv, fdwv)}
			if f2 or f2wv or f2dwv then
				table.insert(tbl, com.gen_link(f2, f2wv, f2dwv))
			end
			table.insert(inflections, tbl)
		end
		if mp ~= "-" then
			if not (mp or mpwv or mpdwv) then
				mp = stem and (stem .. "ות")
				mpwv = stemwv and (stemwv .. "וֹת")
				mpdwv = stemdwv and (stemdwv .. "וֹת")
			end
			tbl = {label = "masculine plural", com.gen_link(mp, mpwv, mpdwv)}
			if mp2 or mp2wv or mp2dwv then
				table.insert(tbl, com.gen_link(mp2, mp2wv, mp2dwv))
			end
			table.insert(inflections, tbl)
		end
		if fp ~= "-" then
			if not (fp or fpwv or fpdwv) then
				fp = stem and (stem .. "ים")
				fpwv = stemwv and (stemwv .. "ִים")
				fpdwv = stemdwv and (stemdwv .. "ִים")
			end
			tbl = {label = "feminine plural", com.gen_link(fp, fpwv, fpdwv)}
			table.insert(inflections, tbl)
		end
	end
end

pos_functions["nouns"] = function(args, genders, inflections, categories)
	if args["g"] then
		table.insert(genders, args["g"])
	end
	table.insert(inflections, maybe_get_inflection(args, "dual indefinite", "dual"))
	table.insert(inflections, maybe_get_inflection(args, "plural indefinite", "pl"))
	table.insert(inflections, maybe_get_inflection(args, "singular construct", "cons"))
	table.insert(inflections, maybe_get_inflection(args, "plural construct", "plcons"))
	table.insert(inflections, maybe_get_inflection(args, "masculine counterpart", "m"))
	table.insert(inflections, maybe_get_inflection(args, "feminine counterpart", "f"))
end

return export