Module:Doth-head: Difference between revisions

From The Languages of David J. Peterson
Jump to navigation Jump to search
mNo edit summary
No edit summary
 
(20 intermediate revisions by 2 users not shown)
Line 5: Line 5:
local lang = require("Module:languages").getByCode("doth")
local lang = require("Module:languages").getByCode("doth")


local vowels = "aeio"
local vowels = "aeioAEIO"


local consonants = "chdfghijkkhlmnqrsshtthvwyzzh"
local consonants = "chdfghijkkhlmnqrsshtthvwyzzhCHDFGHIJKKHLMNQRSSHTTHVWYZZH"


function export.isVowelFirst(term)
function export.isVowelFirst(term)
Line 37: Line 37:
[4] = {},
[4] = {},
[5] = {},
[5] = {},
[6] = {},
[7] = {},
["head"] = {},
["head"] = {},
Line 46: Line 48:
local args = require("Module:parameters").process(frame:getParent().args, params)
local args = require("Module:parameters").process(frame:getParent().args, params)
local data = {lang = lang, pos_category = "adjectives", categories = {}, sort_key = args["sort"], inflections = {}}
local data = {lang = lang, pos_category = "adjectives", categories = {}, sort_key = args["sort"], inflections = {}, heads = args["head"]}
local stem = ""
local stem = ""
if (args[1] == nil) then
if (args[1] == nil or args[1] == "~") then
stem = string.lower(PAGENAME)
stem = string.lower(PAGENAME)
else
else
Line 62: Line 64:
if not stem then -- all specified
if not stem then -- all specified
-- data.heads = args[2]
data.heads = args[2]
data.inflections = {
data.inflections = {
{label = "positive", args[2]},
{label = "positive", args[3]},
{label = "comparative", args[3]},
{label = "comparative", args[4]},
{label = "superlative", args[4]},
{label = "superlative", args[5]},
{label = "negative", args[5]},
{label = "negative", args[6]},
{label = "contrastitive", args[6]},
{label = "contrastitive", args[7]},
{label = "sublative", args[7]}
{label = "sublative", args[8]}
}
}
else
else
    local positive = ""
if (args["head"] == nil) then
    local negative = ""
data.heads = {stem}
    if (isFirst == true) then
    positive = "as"..stem
    else
    positive = "a"..stem
    end
if (isFirst == true) then  
negative = "os"..stem
else
else
negative = "o"..stem
data.heads = {args["head"]}
end
end
if (args[1] ~= "~") then
local positive = ""
    local negative = ""
    if (isFirst == true) then
    positive = "as"..string.lower(stem)
    else
    positive = "a"..string.lower(stem)
    end
if (isFirst == true) then
negative = "os"..string.lower(stem)
else
negative = "o"..string.lower(stem)
end
local comparative = ""
local comparative = ""
local superlative = ""
local superlative = ""
local contrastive = ""
local contrastive = ""
local sublative = ""
local sublative = ""
if (isLast == true) then  
if (isLast == true) then  
comparative = positive.."n"
comparative = positive.."n"
superlative = positive.."naz"
superlative = positive.."naz"
contrastive = negative.."n"
contrastive = negative.."n"
sublative = positive.."noz"
sublative = positive.."noz"
else
else
comparative = positive.."an"
comparative = positive.."an"
superlative = positive.."anaz"
superlative = positive.."anaz"
contrastive = negative.."an"
contrastive = negative.."an"
sublative = positive.."onoz"
sublative = positive.."anoz"
end
data.inflections = {
{label = "comparative", comparative},
{label = "superlative", superlative},
{label = "negative", negative},
{label = "contrastive", contrastive},
{label = "sublative", sublative}
}
end
end
data.inflections = {
{label = "positive", stem.." - "..tostring(isLast).." - "..string.sub(stem,-1)},
{label = "comparative", comparative},
{label = "superlative", superlative},
{label = "negative", negative},
{label = "contrastive", contrastive},
{label = "sublative", sublative}
}
end
end
Line 131: Line 139:
local data = {lang = lang, pos_category = "nouns", categories = {}, sort_key = args["sort"], heads = {args["head"]}, genders = {}, inflections = {}}
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
-- Plural
local plural = args[2][1]
local plural = args[2][1]
Line 165: Line 162:
args[2].label = "plural"
args[2].label = "plural"
table.insert(data.inflections, args[2])
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
end
Line 212: Line 191:
end
end
return word
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
end


Line 246: Line 216:
break
break
end
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
end

Latest revision as of 23:44, 8 January 2020

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 = "aeioAEIO"

local consonants = "chdfghijkkhlmnqrsshtthvwyzzhCHDFGHIJKKHLMNQRSSHTTHVWYZZH"

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"..string.lower(stem)
	    	else 
	    		positive = "a"..string.lower(stem)
	    	end
			if (isFirst == true) then 
				negative = "os"..string.lower(stem)
			else
				negative = "o"..string.lower(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.."anoz"
			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 = {}}

	-- 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
	
	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

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
	
	return require("Module:headword").full_headword(data)
end

return export