Mòdul:ca-pron/categories

De Viccionari

La documentació d'ús d'aquest mòdul es pot crear a Mòdul:ca-pron/categories/ús

local p = {}

local no_accents = {["à"] = "a", ["ā"] = "a", ["è"] = "e", ["é"] = "e", ["ë"] = "e", ["ê"] = "e", ["ē"] = "e",
	["í"] = "i", ["ï"] = "i", ["ò"] = "o", ["ó"] = "o", ["ô"] = "o", ["ō"] = "o", ["ú"] = "u", ["ü"] = "u"}

function p.getCat(hint, pagename)
	if hint == nil or mw.ustring.len(hint) < mw.ustring.len(pagename) - 1  or string.find(pagename, " ") then
		return ""
	end
	local respelled = mw.ustring.gsub(mw.ustring.lower(hint), ".", no_accents)
	local title = mw.ustring.gsub(mw.ustring.lower(pagename), ".", no_accents)
	
	local cat = {}

	if string.find(respelled, "gu%-") and string.gsub(respelled, "gu%-", "gu") == title then
		table.insert(cat, "Pronúncia en català amb gu formant hiat")
	end
	if string.find(respelled, "hh") and string.gsub(respelled, "hh", "h") == title then
		table.insert(cat, "Pronúncia en català amb hac aspirada")
	end
	if string.find(respelled, "^i%-o") and string.gsub(respelled, "^i%-o", "io") == title then
		table.insert(cat, "Pronúncia en català amb i inicial no consonàntica")
	end
	if string.find(respelled, "yll") and string.gsub(respelled, "yll", "ll") == title then
		table.insert(cat, "Pronúncia en català amb iodització dialectal")
	end
	if string.find(respelled, "rr$") and string.gsub(respelled, "rr$", "r") == title then
		table.insert(cat, "Pronúncia en català amb erra final sensible")
	elseif mw.ustring.len(respelled) == mw.ustring.len(title) - 1 then
		local function alphagram(word)
			local letters = {}
			for letter in mw.ustring.gmatch(word, "(.)") do
				table.insert(letters, letter)
			end
			table.sort(letters)
			return table.concat(letters)
		end
		
		if alphagram(respelled .. "r") == alphagram(title) then
			table.insert(cat, "Pronúncia en català amb erra interior muda")
		end
	end
	if string.find(respelled, "[aeiou][r-]r[aeiou]") then
		local match1, match2 = string.match(respelled, "([aeiou])[r-](r[aeiou])")
		if string.match(title, match1 .. match2) then
			table.insert(cat, "Pronúncia en català amb erra vibrant intervocàlica")
		end
	end
	if string.find(respelled, "[aeiou][s-]s[aeiou]") then
		local match1, match2 = string.match(respelled, "([aeiou])[s-](s[aeiou])")
		if string.match(title, match1 .. match2) then
			table.insert(cat, "Pronúncia en català amb essa sonora intervocàlica")
		end
	end
	if string.find(respelled, "[aeiou]ks[aeiou]") then
		local match1, match2 = string.match(respelled, "([aeiou])ks([aeiou])")
		if string.match(title, match1 .. "x" .. match2) then
			table.insert(cat, "Pronúncia en català amb ics intervocàlica")
		end
	end
	if string.find(respelled, "iks$") and string.gsub(respelled, "iks$", "ix") == title then
		table.insert(cat, "Pronúncia en català amb ics travada darrere i vocàlica")
	end
	
	if #cat > 0 then
		return require("Module:utilitats").format_categories(cat, {["code"] = "ca"})
	end
	
	return ""
end

return p