Module:Doth-head: Difference between revisions

From The Languages of David J. Peterson
Jump to navigation Jump to search
(Created page with "-- This module contains code for Dothraki headword templates. local export = {} local lang = require("Module:languages").getByCode("doth") local vowels = "aeio" local cons...")
 
m (Djpwikiadmin moved page Module:Val-head to Module:Doth-head without leaving a redirect)
(No difference)

Revision as of 19:32, 20 April 2019

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)
	return string.match(vowels,first) == nil
	
end

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


function export.dothadj(frame)
	local params = {
		[1] = {},
		[2] = {},
		[3] = {},
		[4] = {},
		[5] = {},
		
		["head"] = {},
		["sort"] = {},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local data = {lang = lang, pos_category = "adjectives", categories = {}, sort_key = args["sort"], inflections = {}}
	
	local stem = args[1]
--	local end1 = args[2]
	
	local isFirst = isVowelFirst(stem)
	local isLast = isVowelLast(stem)
	
	if not stem then -- all specified
--		data.heads = args[2]
		data.inflections = {
			{label = "positive", args[2]},
			{label = "comparative", args[3]},
			{label = "superlative", args[4]},
			{label = "negative", args[5]},
			{label = "contrastitive", args[6]},
			{label = "sublative", args[7]}
		}
	else
	    local positive = ""
	    local negative = ""
	    if (isFirst) then
	    	positive = "as"..stem
	    else 
	    	positive = "a"..stem
	    end
		if (isFirst) then 
			negative = "os"..stem
		else
			negative = "o"..stem
		end
		
		local comparative = ""
		local superlative = ""
		local contrastive = ""
		local sublative = ""
		
		if (isLast) 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 = "positive", stem },
			{label = "comparative", comparative},
			{label = "superlative", superlative},
			{label = "negative", negative},
			{label = "contrastitive", contrastitive},
			{label = "sublative", sublative}
		}
	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