Icona de documentació de mòdul Documentació del mòdul[mostra] [modifica] [refresca]

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


Mòdul de suport per la plantilla {{ro-nom-decl}}. Genera una taula de declinació d’un substantiu romanès. Vegeu la documentació de la plantilla per a la seva utilització.

local p = {}
local m_link = require("Mòdul:enllaç")
local lang = {code = "ro", name = "romanès", sc = "Latn"}

local function notEmpty(var)
	if var == nil or (type(var) == 'string' and mw.text.trim(var) == '') then
		return nil
	end
	return var
end

--[[ Cases:
		nais: nominative and accusative indefinite singular; naip: ... plural
		nads: n&a definite singular; nadp: ... plural
		gdis: genitive and dative indefinite singular; gdip: ... plural
		gdds: g&d definite singular; gddp: ... plural
		vs: vocative singular; vp: vocative plural
]]

local function first_decl(nominative, plural, gender)
	local decl = {}
	if plural == "-" then
		if mw.ustring.find(nominative, "[ou]ră$") then
			plural = mw.ustring.gsub(nominative, "ă$", "i")
		elseif mw.ustring.find(nominative, "cică$") then
			plural = mw.ustring.gsub(nominative, "ică$", "ele")
		elseif mw.ustring.find(nominative, "ă$") then
			plural = mw.ustring.gsub(nominative, "ă$", "e")
		else
			plural = nominative .. "le"
		end
	end
	decl.nais = nominative
	decl.gdds = plural .. "i"
	decl.gddp = plural .. "lor"
	decl.vs = nominative
	decl.naip = plural
	decl.gdip = plural
	decl.vp = plural
	if mw.ustring.find(nominative, "ă$") then
		decl.nads = mw.ustring.gsub(nominative, "ă$", "a")
		if plural:find("i$") and gender == "m" then
			decl.gdis = nominative
			decl.nadp = plural .. "i"
		else
			decl.gdis = plural
			decl.nadp = plural .. "le"
			decl.vs2 = mw.ustring.gsub(nominative, "ă$", "o")
			decl.vp = plural .. "lor"
		end
	else
		decl.gdis = plural
		decl.nads = nominative .. "ua"
		decl.nadp = plural .. "le"
	end
	
	return decl
end

function second_decl(nominative, plural, gender)
	local decl = {}
	decl.nais = nominative
	decl.gdis = nominative
	decl.naip = plural
	decl.gdip = plural
	decl.gddp = plural .. "lor"
	decl.vp = plural .. "lor"
	if mw.ustring.find(nominative, "u$") then
		decl.nads = nominative .. "l"
		decl.gdds = nominative .. "lui"
		decl.vs = nominative .. "le"
	else
		decl.nads = nominative .. "ul"
		decl.gdds = nominative .. "ului"
		decl.vs = nominative .. "ule"
		decl.vs2 = nominative .. "e"
	end
	if gender == "m" then
		decl.nadp = plural .. "i"
	else
		decl.nadp = plural .. "le"
	end
	
	return decl
end

function third_decl(nominative, plural, gender)
	local decl = {}
	decl.nais = nominative
	decl.vs = nominative
	decl.naip = plural
	decl.gdip = plural
	decl.gddp = plural .. "lor"
	decl.vp = plural
	if gender == "m" then
		decl.gdis = nominative
		decl.nads = nominative .. "le"
		decl.gdds = nominative .. "lui"
		decl.nadp = plural .. "i"
	elseif gender == "n" then
		decl.gdis = nominative
		decl.nads = nominative .. "le"
		decl.gdds = nominative .. "lui"
		decl.nadp = plural .. "le"
	elseif gender == "f" then
		if plural == "-" then
			plural = nominative:gsub("e$", "i")
		end
		decl.gdis = plural
		decl.nadp = plural .. "le"
		if nominative:find("ie$") then
			decl.nads = nominative:gsub("e$", "a")
			decl.gdds = nominative .. "i"
		else 
			decl.nads = nominative .. "a"
			decl.gdds = plural .. "i"
		end
	end
	
	return decl
end

local function make_link(declension, case)
	local ret = '-'
	if notEmpty(declension[case]) then
		ret = m_link.full_link({term = declension[case], lang = lang}, nil, false)
		if notEmpty(declension[case .. "2"]) then
			ret = ret .. ", " .. m_link.full_link({term = declension[case .. "2"], lang = lang}, nil, false)
		end
	end
	return ret
end

local function make_table(declension, gender)
	if declension.nais == nil and declension.naip == nil  then
		return ""
	end
	-- articles for the table
	local art_na_s = (declension.nais and "(un)" or "")
	local art_gd_s = (declension.gdis and "(unui)" or "")
	if gender == "f" then
		art_na_s = (declension.nais and "(o)" or " ")
		art_gd_s = (declension.gdis and "(unei)" or "")
	end
	local art_na_p = (declension.naip and "(niște)" or "")
	local art_gd_p = (declension.gdip and "(unor)" or "")

	ret = [=[ 
{| class="wikitable" style="margin-left: 0.5em; float: left; font-size: 90%;"
|- style="background:#EEEEEE"
| rowspan="2" |
| colspan="3" style="text-align:center;" | ''Singular''
| colspan="3" style="text-align:center;" | ''Plural''
|- style="background:#EEEEEE"
| colspan="2" style="text-align:center;" | ''Indefinit''
| style="text-align:center;" | ''Definit''
| colspan="2" style="text-align:center;" | ''Indefinit''
| style="text-align:center;" | ''Definit''
|-
| style="background:#EEEEEE" | ''Nominatiu-acusatiu''
| style="border-right-width: 0px; padding-right: 0em;" | ]=] .. art_na_s .. [=[ 
| style="border-left-width: 0px;" | ]=] .. make_link(declension, "nais") .. [=[ 
| ]=] .. make_link(declension, "nads") .. [=[ 
| style="border-right-width: 0px; padding-right: 0em;" | ]=] .. art_na_p .. [=[ 
| style="border-left-width: 0px;" | ]=] .. make_link(declension, "naip") .. [=[ 
| ]=] .. make_link(declension, "nadp") .. [=[ 
|-
| style="background:#EEEEEE" | ''Genitiu-datiu''
| style="border-right-width: 0px; padding-right: 0em;" | ]=] .. art_gd_s .. [=[ 
| style="border-left-width: 0px;" | ]=] .. make_link(declension, "gdis") .. [=[ 
| ]=] .. make_link(declension, "gdds") .. [=[ 
| style="border-right-width: 0px; padding-right: 0em;" | ]=] .. art_gd_p .. [=[ 
| style="border-left-width: 0px;" | ]=] .. make_link(declension, "gdip") .. [=[ 
| ]=] .. make_link(declension, "gddp") .. [=[ 
|-
| style="background:#EEEEEE" | ''Vocatiu''
| style="border-right-width: 0px; padding-right: 0em;" |
| colspan="2" style="border-left-width: 0px;" | ]=] .. make_link(declension, "vs") .. [=[ 
| style="border-right-width: 0px; padding-right: 0em;" |
| colspan="2" style="border-left-width: 0px;" | ]=] .. make_link(declension, "vp") .. [=[ 
|}
<br clear="all>]=]
	
	return ret
end

function p.show(frame)
	local args = frame:getParent().args
	local pagename = notEmpty(args.pagename) or mw.title.getCurrentTitle().subpageText
	local gender = notEmpty(args[1])
	local plural = notEmpty(args[2])
	
	if not gender or plural == "?" or args.decl == "no" then
		return
	end
	
	-- Make declension 1st, 2nd or 3rd
	local declension = {}
	if mw.ustring.find(pagename, "[ăai]$") and (gender == "f" or gender == "m") then
		declension = first_decl(pagename, plural, gender)
	elseif mw.ustring.find(pagename, "[^ăaei]$") and (gender == "m" or gender == "n") then
		declension = second_decl(pagename, plural, gender)
	elseif pagename:find("e$") then
		declension = third_decl(pagename, plural, gender)
	end
	
	-- parameters provided
	local cases = {"nai", "gdi", "nad", "gdd", "v"}
	for i, case in ipairs(cases) do
		declension[case .. "s"] = args[case .. "s"] or declension[case .. "s"]
		declension[case .. "s2"] = args[case .. "s2"] or declension[case .. "s2"]
		if plural == "-" then
			declension[case .. "p"] = nil
			declension[case .. "p2"] = nil
		else
			declension[case .. "p"] = args[case .. "p"] or declension[case .. "p"]
			declension[case .. "p2"] = args[case .. "p2"] or declension[case .. "p2"]
		end
	end
	
	-- Redlinks?
	local categories = {}
	for _, form in pairs(declension) do
		if form ~= "" and not mw.title.new(form).exists then
			table.insert(categories, "Termes en romanès amb flexions a crear")
			break
		end
	end
	
	if args.bot then
		return require('Module:lema').make_bot_list(declension)
	else
		local ret = make_table(declension, gender)
		if #categories > 0 then
			ret = ret .. require("Module:utilitats").format_categories(categories, lang)
		end
		return ret
	end
end

return p