Module:Doth-head

From The Languages of David J. Peterson
Jump to navigation Jump to search

Documentation for this module may be created at Module:Doth-head/documentation

-- This module contains code for Dothraki headword templates.

local export = {}

local lang = require("Module:languages").getByCode("doth")

local vowels = "aeio"

local consonants = "chdfghijkkhlmnqrsshtthvwyzzh"

function export.isVowelFirst(term)
	local first = string.sub(term,1,1)
	if (string.match(vowels,first) == nil) then
		return false
	else
		return true
	end
	
end

function export.isVowelLast(term)
	local last = string.sub(term,-1)
	if (string.match(vowels,last) == nil) then
		return false
	else
		return true
	end
	
end


function export.dothadj(frame)
	local params = {
		[1] = {},
		[2] = {},
		[3] = {},
		[4] = {},
		[5] = {},
		[6] = {},
		[7] = {},
		
		["head"] = {},
		["sort"] = {},
	}
	
	local PAGENAME = mw.title.getCurrentTitle().text
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {lang = lang, pos_category = "adjectives", categories = {}, sort_key = args["sort"], inflections = {}, heads = args["head"]}
	
	local stem = ""
	
	if (args[1] == nil or args[1] == "~") then
		stem = string.lower(PAGENAME)
	else
		stem = args[1]
	end 
	
--	local end1 = args[2]
	
	local isFirst = export.isVowelFirst(stem)
	local isLast = export.isVowelLast(stem)
	
	if not stem then -- all specified
		data.heads = args[2]
		data.inflections = {
			{label = "positive", args[3]},
			{label = "comparative", args[4]},
			{label = "superlative", args[5]},
			{label = "negative", args[6]},
			{label = "contrastitive", args[7]},
			{label = "sublative", args[8]}
		}
	else
		if (args["head"] == nil) then
			data.heads = {stem}
		else
			data.heads = {args["head"]}
		end
		if (args[1] ~= "~") then
			local positive = ""
	    	local negative = ""
	    	if (isFirst == true) then
	    		positive = "as"..stem
	    	else 
	    		positive = "a"..stem
	    	end
			if (isFirst == true) then 
				negative = "os"..stem
			else
				negative = "o"..stem
			end
		
			local comparative = ""
			local superlative = ""
			local contrastive = ""
			local sublative = ""
		
			if (isLast == true) then 
				comparative = positive.."n"
				superlative = positive.."naz"
				contrastive = negative.."n"
				sublative = positive.."noz"
			else
				comparative = positive.."an"
				superlative = positive.."anaz"
				contrastive = negative.."an"
				sublative = positive.."onoz"
			end
		
			data.inflections = {
				{label = "comparative", comparative},
				{label = "superlative", superlative},
				{label = "negative", negative},
				{label = "contrastive", contrastive},
				{label = "sublative", sublative}
			}
		end
	end
	
	return require("Module:headword").full_headword(data)
end

function export.itnoun(frame)
	PAGENAME = mw.title.getCurrentTitle().text
	
	local params = {
		[1] = {list = "g", default = "?"},
		[2] = {list = "pl"},
		
		["f"] = {},
		["head"] = {},
		["m"] = {},
		["sort"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {lang = lang, pos_category = "nouns", categories = {}, sort_key = args["sort"], heads = {args["head"]}, genders = {}, inflections = {}}
	
	-- Gender
	if args[1][1] == "mf" then
		data.genders = {"m", "f"}
	else
		data.genders = args[1]
	end
	
	if #data.genders == 0 then
		data.genders = {"?"}
	end
	
	-- Plural
	local plural = args[2][1]
	
	if not plural then
		args[2][1] = make_plural(PAGENAME, data.genders[1])
	end
	
	if plural == "~" then
		table.insert(data.inflections, {label = "[[Appendix:Glossary#uncountable|uncountable]]"})
		table.insert(data.categories, "Italian uncountable nouns")
	else
		table.insert(data.categories, "Italian countable nouns")
	end
	
	if plural == "-" then
		table.insert(data.inflections, {label = "[[Appendix:Glossary#invariable|invariable]]"})
	end
	
	if plural == "-" or plural == "~" then
	else
		args[2].label = "plural"
		table.insert(data.inflections, args[2])
	end
	
	-- Other gender
	if args["f"] then
		table.insert(data.inflections, {label = "feminine", args["f"]})
	end
	
	if args["m"] then
		table.insert(data.inflections, {label = "masculine", args["m"]})
	end
	
	-- Category
	if (data.heads[1] or PAGENAME):find('o$') and data.genders[1] == "f" then
		table.insert(data.categories, "Italian nouns with irregular gender")
	end
	
	if (data.heads[1] or PAGENAME):find('a$') and data.genders[1] == "m" then
		table.insert(data.categories, "Italian nouns with irregular gender")
	end
	
	return require("Module:headword").full_headword(data)
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
		word = word:gsub("io$", "i")
	elseif word:find("ologo$") then
		word = word:gsub("o$", "i")
	elseif word:find("[cg]o$") then
		word = word:gsub("o$", "hi")
	elseif word:find("o$") then
		word = word:gsub("o$", "i")
	elseif word:find("[cg]a$") then
		word = word:gsub("a$", (gender == "m" and "hi" or "he"))
	elseif word:find("[cg]ia$") then
		word = word:gsub("ia$", "e")
	elseif word:find("a$") then
		word = word:gsub("a$", (gender == "m" and "i" or "e"))
	elseif word:find("e$") then
		word = word:gsub("e$", "i")
	end
	return word
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

function export.itprop(frame)
	local params = {
		[1] = {list = "g", default = "?"},
		["f"] = {},
		["head"] = {},
		["m"] = {},
		["sort"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {lang = lang, pos_category = "proper nouns", categories = {}, sort_key = args["sort"], heads = {args["head"]}, genders = args[1], inflections = {}}
	
	for i, g in ipairs(data.genders) do
		if g == "p" then
			data.genders[i] = "?-p"
		end
		
		if g == "m-p" or g == "f-p" or g == "?-p" or g == "p" then
			table.insert(data.inflections, {label = "[[Appendix:Glossary#plural only|plural only]]"})
			table.insert(data.categories, lang:getCanonicalName() .. " pluralia tantum")
			break
		end
	end
	if args["m"] then
		table.insert(data.inflections, {label = "masculine", args["m"]})
	end
	if args["f"] then
		table.insert(data.inflections, {label = "feminine", args["f"]})
	end
	
	return require("Module:headword").full_headword(data)
end

return export