Module:pl-headword

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:pl-headword/documentation. [edit]
Useful links: subpage listtransclusionstestcases

This module implements the following templates:


local export = {}
 
local lang = require("Module:languages").getByCode("pl")
 
local function collect_numbered(args, prefix, target)
	local was_empty = false
	if args[prefix] then
		table.insert(target, args[prefix])
		local i = 2
		while args[prefix .. i] do
			table.insert(target, args[prefix .. i])
			i = i + 1
		end
	end
 
	return target
end
 
local function add_if_nonempty(infls, item)
	if #item > 0 then
		table.insert(infls, item)	
	end
end
 
-- verbs
 
local norm_aspect = {
	["p"]            = "pf",
	["pf"]           = "pf",
	["perf"]         = "pf",
	["perfective"]   = "pf",
	["i"]            = "impf",
	["impf"]         = "impf",
	["imperf"]       = "impf",
	["imperfective"] = "impf",
	["ii"]           = "impf-it",
	["impf-it"]      = "impf-it",
	["id"]           = "impf-dur",
	["impf-dur"]     = "impf-dur",
	["pi"]           = "pf-it",
	["pf-it"]        = "pf-it",
	["ps"]           = "pf-sem",
	["pf-sem"]       = "pf-sem",
}
 
function export.show_verb(frame)
	local args = frame:getParent().args
 
	local categories = {"Polish verbs"}
	local tracking_categories = {}
	local infls = {}
	local aspect = norm_aspect[args.aspect or args.asp or args.a or false] or "?"
	local asp_label = "?"
 
	if (aspect == "pf") or (aspect == "pf-it") or (aspect == "pf-sem") then
		asp_label = "pf"
		table.insert(categories, "Polish perfective verbs")
	elseif (aspect == "impf") or (aspect == "impf-it") or (aspect == "impf-dur") then
		asp_label = "impf"
		table.insert(categories, "Polish imperfective verbs")
	else
		table.insert(categories, "Polish verbs missing aspect")
	end
 
	if aspect == "impf-dur" then
		table.insert(infls, {label = "durative"})
	elseif aspect == "impf-it" then
		table.insert(infls, {label = "iterative"})
	elseif aspect == "pf-sem" then
		table.insert(infls, {label = "semelfactive"})
	elseif aspect == "pf-it" then
		table.insert(infls, {label = "iterative"})
	end
 
	local perf = { label = "perfective" }
	local imperf = { label = "imperfective" }
 
	-- legacy parameter
	if args[1] then
		table.insert(tracking_categories, "pl-verb with positional parameters")
		if (aspect == "impf") then
			table.insert(perf, args[1])
		elseif (aspect == "pf") then
			table.insert(imperf, args[1])
		end
	end
 
	collect_numbered(args, "perf", perf)
	collect_numbered(args, "pf", perf)
	collect_numbered(args, "imperf", imperf)
	collect_numbered(args, "impf", imperf)
 
	add_if_nonempty(infls, perf)
	add_if_nonempty(infls, imperf)
 
	return require("Module:headword").full_headword(lang, nil, args.head, nil, { asp_label }, infls, categories, args.sort) ..
		require("Module:utilities").format_categories(tracking_categories, lang, args.sort)
end
 
-- nouns and proper nouns
 
local noun_gender_cat = {
	["m"     ] = "Polish masculine nouns",
	["m-an"  ] = "Polish masculine nouns",
	["m-in"  ] = "Polish masculine nouns",
	["m-pr"  ] = "Polish masculine nouns",
	["f"     ] = "Polish feminine nouns",
	["n"     ] = "Polish neuter nouns",
	["m-p"   ] = false,
	["m-pr-p"] = false,
	["m-an-p"] = false,
	["m-in-p"] = false,
	["f-p"   ] = false,
	["n-p"   ] = false,
	["p"     ] = false,
}
 
function export.show_noun(frame)
	local args = frame:getParent().args
 
	local categories = { frame.args.proper and "Polish proper nouns" or "Polish nouns" }
	local infls = {}
 
	if args.indecl and args.indecl ~= '' then
		table.insert(infls, { label = "indeclinable" })
	end
 
	add_if_nonempty(infls, collect_numbered(args, "abbr", { label = "abbreviation" }))
	add_if_nonempty(infls, collect_numbered(args, "dim", { label = "diminutive" }))
	add_if_nonempty(infls, collect_numbered(args, "aug", { label = "augmentative" }))
	add_if_nonempty(infls, collect_numbered(args, "f", { label = "feminine" }))
	add_if_nonempty(infls, collect_numbered(args, "m", { label = "masculine" }))
 
	local g, genders = args.g or args[1]
	if g then
		if g == "mf" then
			genders = { "m", "f" }
			table.insert(categories, noun_gender_cat.m)
			table.insert(categories, noun_gender_cat.f)
		elseif noun_gender_cat[g] ~= nil then
			genders = { g }
			table.insert(categories, noun_gender_cat[g] or nil)
		else
			genders = { "?" }
			table.insert(categories, "Polish nouns lacking gender")
		end
	else
		genders = { "?" }
		table.insert(categories, "Polish nouns lacking gender")
	end
 
	return require("Module:headword").full_headword(lang, nil, args.head, nil, genders, infls, categories, args.sort)
end
 
-- adjectives and adverbs
 
local adj_gender_tab = {
	["-"]      = { },
	["m"]      = { "m" },
	["f"]      = { "f" },
	["n"]      = { "n", "f-p", "n-p" },
	["p"]      = { "m-pr-p" },
	["pl"]     = { "m-pr-p" },
	["plural"] = { "m-pr-p" }, 
}
 
function export.show_adj_adv(frame)
	local args = frame:getParent().args
	local categories = {}
	local tracking_categories = {}
	local infls = {}
	local genders
 
	local PAGENAME = mw.title.getCurrentTitle().text
 
	if frame.args.adverb then
		table.insert(categories, "Polish adverbs")
	elseif args.lemma or (args[1] == "m") or (args[1] == "-") then
		table.insert(categories, "Polish adjectives")
	else
		table.insert(categories, "Polish adjective forms")
	end
 
	if frame.args.adverb then
		genders = {}
	else
		genders = adj_gender_tab[args[1]]
		if not genders then
			genders = { "?" }
			table.insert(categories, "Polish terms needing attention")
		end
	end
 
	local comparative, superlative = {}, {}
 
	local i0, i = frame.args.adverb and 1 or 2
	i = i0
 
	if args[i0] == "-" then
		if not args[i0 + 1] then
			table.insert(infls, { label = "not comparable" })
		else
			table.insert(infls, { label = "not always comparable" })
			i = i + 1
			while args[i] do
				local comp, super
				if frame.args.adverb and ((args[i] == "j") or (args[i] == "regular")) then
					table.insert(comparative, PAGENAME .. "j")
					table.insert(superlative, "naj" .. PAGENAME .. "j")
				elseif args[i] == "bardziej" then
					table.insert(comparative, "[[bardziej]] " .. PAGENAME)
					table.insert(superlative, "[[najbardziej]] " .. PAGENAME)
				elseif args[i] then
					table.insert(comparative, args[i])
					table.insert(superlative, "naj" .. args[i])
				end
				i = i + 1
			end
 
			comparative.label, comparative.accel = "comparative", "comparative-form-of"
			superlative.label, superlative.accel = "superlative", "superlative-form-of"
 
			table.insert(infls, comparative)
			table.insert(infls, superlative)
		end
	elseif args[i0] then
		while args[i] do
			local comp, super
			if frame.args.adverb and ((args[i] == "j") or (args[i] == "regular")) then
				table.insert(comparative, PAGENAME .. "j")
				table.insert(superlative, "naj" .. PAGENAME .. "j")
			elseif args[i] == "bardziej" then
				table.insert(comparative, "[[bardziej]] " .. PAGENAME)
				table.insert(superlative, "[[najbardziej]] " .. PAGENAME)
			elseif args[i] then
				table.insert(comparative, args[i])
				table.insert(superlative, "naj" .. args[i])
			end
			i = i + 1
		end
 
		comparative.label, comparative.accel = "comparative", "comparative-form-of"
		superlative.label, superlative.accel = "superlative", "superlative-form-of"
 
		table.insert(infls, comparative)
		table.insert(infls, superlative)
	else
		table.insert(tracking_categories, "pl-adj or pl-adv without comparative form")
	end
 
	if not frame.args.adverb then
		if args.adv then
			if args.adv ~= '-' then
				add_if_nonempty(infls, collect_numbered(args, "adv", { label = "adverb" }))
			end
		else
			table.insert(tracking_categories, "pl-adj without corresponding adverb")
		end
	end
 
	add_if_nonempty(infls, collect_numbered(args, "abbr", { label = "abbreviation" }))
 
	return require("Module:headword").full_headword(lang, nil, args.head, nil, genders, infls, categories, args.sort) ..
		require("Module:utilities").format_categories(tracking_categories, lang, args.sort)
end
 
return export