Module:pl-mid-noun

Hello, you have come here looking for the meaning of the word Module:pl-mid-noun. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:pl-mid-noun, but we will also tell you about its etymology, its characteristics and you will know how to say Module:pl-mid-noun in singular and plural. Everything you need to know about the word Module:pl-mid-noun you have here. The definition of the word Module:pl-mid-noun will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:pl-mid-noun, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

local m_links = require('Module:links')
local m_adj = require('Module:pl-adj')
local m_g = require('Module:gender and number')
local lang = require("Module:languages").getByCode("pl")

-- local consonants = "";

-- case information
local cases = {
	{ key = "nom"; en = "nominative"; pl = "mianownik (kto? co?)" },
	{ key = "gen"; en = "genitive"; pl = "dopełniacz (kogo? czego?)" },
	{ key = "dat"; en = "dative"; pl = "celownik (komu? czemu?)" },
	{ key = "acc"; en = "accusative"; pl = "biernik (kogo? co?)" },
	{ key = "ins"; en = "instrumental"; pl = "narzędnik (kim? czym?)" },
	{ key = "loc"; en = "locative"; pl = "miejscownik (o kim? o czym?)" },
	{ key = "voc"; en = "vocative"; pl = "wołacz (o!)" },
}

-- columns for normal nouns
local noun_cols = {
	{ key = "s"; title = "singular" },
	{ key = "p"; title = "plural" },
}

-- columns for Old Polish nouns
local noun_dual_cols = {
	{ key = "s"; title = "singular" },
	{ key = "d"; title = "dual" },
	{ key = "p"; title = "plural" },
}

-- columns for pronouns
local pronoun_cols = {
	{ key = "sm"; title = m_g.format_list({"m"}, lang) },
	{ key = "sf"; title = m_g.format_list({"f"}, lang) },
	{ key = "sn"; title = m_g.format_list({"n"}, lang) },
	{ key = "pm"; title = m_g.format_list({"vr-p"}, lang) },
	{ key = "po"; title = m_g.format_list({"nv-p"}, lang) },
}

local altsep = "/"

function empty_item(text)
	return (not text) or text == "" or text == "-" or text == "–" or text == "—"
end

-- add link markers, with links separated by any of splitchars
-- exported for use in testcases
-- normally the separator is altsep
function export.make_links(text, splitchars, title)
	if not title then
		title = mw.title.getCurrentTitle().fullText
	end
	if empty_item(text) then
		return "—"
	elseif not splitchars or splitchars == "" then
		return ("]"):format(text, text)
	else
		items = {}
		for word in mw.ustring.gmatch(text, "+") do
			add_archaic = ""
			if word:sub(-string.len(" (archaic)")) == " (archaic)" then
				word = (mw.text.split(word, "% %(archaic%)"))
				add_archaic = " (archaic)"
			end
			
			if word == title then
				table.insert(items, ("]"):format(word) .. add_archaic)
			else
				table.insert(items, ("]"):format(word, word) .. add_archaic)
			end
		end
		
		if #items > 1 then
			require("Module:debug").track("pl-noun/splitchars")
		end
		
		return table.concat(items, "/")
	end
end

local function linkify_info(declinfo, splitchars, nolinks)
	if nolinks then
		require("Module:debug").track("pl-noun/nolinks")
	end
	
	local linked = {}
	local title = mw.title.getCurrentTitle().fullText
	for k, v in pairs(declinfo) do
		if v == title then
			linked = "]"
		elseif nolinks then
			linked = v
		else
			linked = export.make_links(v, splitchars, title)
		end
	end
	return linked
end

local function nowiki_info(declinfo)
	require("Module:debug").track("pl-noun/nowiki")
	local nowikied = {}
	for k, v in pairs(declinfo) do
		nowikied = mw.text.nowiki(v)
	end
	return nowikied
end

local function override_col_titles(heads, cols)
	if not heads then
		return cols or {}
	end
	local new_cols = {}
	local index = 1
	for word in mw.ustring.gmatch(heads, "+") do
		if cols then
			table.insert(new_cols, { key = cols.key; title = word } )
		else
			table.insert(new_cols, { key = tostring(index); title = word } )
		end
		index = index + 1
	end
	for ci, col in ipairs(cols) do
		if ci >= index then
			table.insert(new_cols, cols)
		end
	end
	return new_cols
end

local function guess_width(declinfo, cols)
	local maxl = 0
	for k, v in pairs(declinfo) do
		local l = mw.ustring.len(mw.text.trim(v))
		if maxl < l then
			maxl = l
		end
	end
	local width = math.floor(maxl * 0.78) -- number obtained by anecdotal evidence
	width = (width < 10) and 10 or width
	width = 9 + (width * #cols)
	return width
end

-- generate the HTML code of an inflection table
-- each entry in heads must have "key" and "title"
local function make_table(declinfo, cols, preproc, width, title, nolinks, rnoms)
	local result = {}
	if not cols or not cols then
		error("make_table: invalid cols parameter")
	end

	local lemma_key = cases.key .. cols.key
	local lemma = m_links.remove_links(declinfo)
	if rnoms then
	    lemma = '*' .. m_links.remove_links(rnoms)
	end
	
	title = title or ('Attested forms of <span class="Latn mention" lang="pl" xml:lang="pl">%s</span>'):format(lemma)

	local emwidth = width or guess_width(declinfo, cols)

	if preproc == "nowiki" then
		declinfo = nowiki_info(declinfo)
	elseif preproc == "linkify" then
		declinfo = linkify_info(declinfo, altsep, nolinks)
	end

	if cols and (#cols > 0) then
		table.insert(result, '|- class="rowgroup"\n! style="background:var(--wikt-palette-lightblue, #d9ebff); width: 8em;" |\n')
		for i, col in ipairs(cols) do
			table.insert(result, ('! style="background:var(--wikt-palette-lightblue, #d9ebff);" scope="col" | %s\n'):format(col.title))
		end
	end


	local maxl = 0
	for i, case in ipairs(cases) do
		table.insert(result, ('|-\n! title="%s" style="background:var(--wikt-palette-lighterblue, #ebf4ff);" scope="row" | %s\n'):format(case.pl, case.en))
		for _, col in ipairs(cols) do
			local declkey = case.key .. col.key
			local item = mw.text.trim(declinfo)
			if empty_item(item) then
				table.insert(result, '| —\n')
			else
				local link = m_links.full_link({lang = lang, term = item, accel = {form = ("%s|%s"):format(case.key, col.key)}})
				table.insert(result, ('| %s\n'):format(link))
			end
		end
	end


	local outtext = ([=[<div class="NavFrame" data-toggle-category="declension" style="display: block; max-width: %uem;">
<div class="NavHead" style="background:var(--wikt-palette-lighterblue, #ebf4ff)" >%s</div>
<div class="NavContent">
{| style="text-align:center; width: 100%%; margin: 0;" class="inflection-table inflection"
]=]):format(emwidth, title) .. table.concat(result, "") .. "|}</div></div>"

	return outtext
end

local function get_mode()
	local frame = mw.getCurrentFrame()
	if mw.isSubsting() then
		return 'subst'
	elseif frame:getParent():getTitle() == mw.title.getCurrentTitle().fullText then
		return 'demo'
	else
		return 'xclude'
	end
end

local function make_table_from_pargs(pargs, cols)
	local width = pargs.width and tonumber(pargs.width)
	
	local declinfo = {}
	
	cols = override_col_titles(pargs.heads, cols or {})
	for i = 1, 7 do
		for j, col in ipairs(cols) do
			local case_key = cases.key .. col.key
			local argn = ((i-1) * #cols) + j
			declinfo = m_links.remove_links(mw.text.trim(pargs or pargs or "-"))
		end
	end
	
	return make_table(declinfo, cols, "linkify", pargs.width, pargs.title, pargs.nolinks, pargs)
end

-- Generate declension table for a regular noun with all forms passed explicitly as parameters
function export.template_decl_noun(frame)
	local pargs = frame:getParent().args
	return make_table_from_pargs(pargs, noun_cols)
end

return export