Module:it-head

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:it-head/documentation. [edit]

-- This module contains code for Italian headword templates.
-- Templates covered are it-adj and it-noun.
-- See Module:itconj for Italian conjugation templates.
local m_headword = require("Module:headword")
local m_utilities = require("Module:utilities")
 
local export = {}
 
local lang = require("Module:languages").getLanguageByCode("it")
 
function export.itadj(frame)
	local args = frame:getParent().args
	PAGENAME = mw.title.getCurrentTitle().text
 
	local genders = {}
	local inflections = {}
	local categories = {"Italian adjectives"}
 
	local head = args["head"]; if head == "" then head = nil end
	local sort_key = args["sort"] or ""; if sort_key == "" then sort_key = nil end
 
	local stem = args[1] or error("1st parameter (stem of adjective) missing!")
	local end1 = args[2]
 
	-- no ending vowel parameters - generate default
	if not end1 then
		genders = {"m"}
		inflections = {
			{label = "feminine", stem .. "a"},
			{label = "masculine plural", stem .. "i"},
			{label = "feminine plural", stem .. "e"} }
	else
		local end2 = args[3] or error("Either 0, 2 or 4 vowel endings should be supplied!")
		local end3 = args[4]
 
		-- 2 ending vowel parameters - m and f are identical
		if not end3 then
			genders = {"m", "f"}
			inflections = {
				{label = "masculine and feminine plural", stem .. end2} }
		-- 4 ending vowel parameters - specify exactly
		else
			local end4 = args[5] or error("Either 0, 2 or 4 vowel endings should be supplied!")
			genders = {"m"}
			inflections = {
				{label = "feminine", stem .. end2},
				{label = "masculine plural", stem .. end3},
				{label = "feminine plural", stem .. end4} }
		end
	end
 
	return
		m_headword.format_headword(head, lang, "Latn") ..
		m_headword.format_genders(genders, lang) ..
		m_headword.format_inflections(inflections, lang, "Latn") ..
		m_utilities.format_categories(categories, lang, sort_key)
end
 
function export.itnoun(frame)
	local args = frame:getParent().args
	PAGENAME = mw.title.getCurrentTitle().text
 
	local genders = {}
	local inflections = {}
	local categories = {"Italian nouns"}
 
	local head = args["head"]; if head == "" then head = nil end
	local sort_key = args["sort"] or ""; if sort_key == "" then sort_key = nil end
 
	local gender = args[1]; if gender == "" then gender = nil end
	local plural = args[2]; if plural == "" then plural = nil end
 
	if args[3] or args[4] then
		error("Third and fourth parameter should be empty.")
	end
 
	-- Gender
	if gender == "mf" then
		genders = {"m", "f"}
	else
		genders = {gender}
	end
 
	if #genders == 0 then
		genders = {"?"}
	end
 
	-- Plural
	if not plural then
		plural = make_plural(PAGENAME, genders[1])
	end
 
	table.insert(inflections, {label = "plural", plural})
 
	-- Other gender
	local feminine = args["f"]; if feminine == "" then feminine = nil end
	local masculine = args["m"]; if masculine == "" then masculine = nil end
 
	if feminine then
		table.insert(inflections, {label = "feminine", feminine})
	end
 
	if masculine then
		table.insert(inflections, {label = "masculine", masculine})
	end
 
	return
		m_headword.format_headword(head, lang, "Latn") ..
		m_headword.format_genders(genders, lang) ..
		m_headword.format_inflections(inflections, lang, "Latn") ..
		m_utilities.format_categories(categories, lang, sort_key)
end
 
-- Generate a default plural form, which is correct for most regular nouns
function make_plural(word, gender)
	-- If there are spaces in the term, then we can't reliably form the plural.
	-- Return nothing instead.
	if word:find(" ") then
		return nil
	elseif word:find("io$") then
		return word:gsub("io$", "i")
	elseif word:find("ologo$") then
		return word:gsub("o$", "i")
	elseif word:find("[cg]o$") then
		return word:gsub("o$", "hi")
	elseif word:find("o$") then
		return word:gsub("o$", "i")
	elseif word:find("[cg]a$") then
		return word:gsub("a$", (gender == "m" and "hi" or "he"))
	elseif word:find("[cg]ia$") then
		return word:gsub("ia$", "e")
	elseif word:find("a$") then
		return word:gsub("a$", (gender == "m" and "i" or "e"))
	elseif word:find("ie$") then
		return word
	elseif word:find("e$") then
		return word:gsub("e$", "i")
	else
		return word
	end
end
 
-- Generate a default feminine form
function make_feminine(word, gender)
	if word:find("o$") then
		return word:gsub("o$", "a")
	else
		return word
	end
end
 
return export