Module:siwa-noun/common

From Linguifex
< Module:siwa-noun
Revision as of 23:05, 30 July 2021 by Sware (talk | contribs)
Jump to navigation Jump to search


local gsub = mw.ustring.gsub

local export = {}

function export.lenition(word)
	--local word = frame:getParent().args[1] -- for testing
	local lenited = ""
	local v = "([aeiouyůõảẻỉỏủỷę])"
	local lenition_patterns = {
	--geminated voiced stops
	["bb"] = "b", ["dd"] = "d", ["gg"] = "g", ["ġġ"] = "ġ",
	--long sonorants
	["gį"] = "į", ["mm"] = "m", ["ll"] = "l", ["nn"] = "n", ["rr"] = "r",
	--uvular stops
	["bġ"] = "p", ["pr"] = "p", ["dġ"] = "t", ["tr"] = "t",
	--glottalized stops
	["bm"] = "m", ["dn"] = "n", ["kn"] = "ng",
	--consonant clusters
	["dl"] = "l", ["([lr])pp"] = "%1p", ["([lr])tt"] = "%1t", ["([lrms])kk"] = "%1k",["ps"] = "bs", ["k([lvs])"] = "g%1",
	--voiced consonants (▫, arbitrary character to compute diphthongs further down)
	["vv"] = "ų", [v.."[vųbhḥg]"..v] = "%1▫%2", ["d[aou]"] = "l", [v.."[dġ]([ieůy])"] = "%1▫%1", [v.."ġ[aou]"] = "%1vv",
	--Ci#
	["[rġ]i"] = "ṡi", ["nįi"] = "gįi", 	["hhį"] = "ṡ",
	--long voiceless consonants
	["ḍb"] = "p", ["ḍḍ"] = "hh", ["ḍg"] = "k",
	--semi-vowels
	["[ou]ų"] = "ů",
	}
	for regex, repl in pairs(lenition_patterns) do
		lenited = gsub(word, regex, repl, 1)
		if lenited ~= word then return lenited end
	end
	
	return word
end

function export.coalescence(word, stress)
	local diphthongs = {
		["[aę]▫[aę]"] = "ả", ["e▫e"] = "ẻ", ["i▫i"] = "ỉ", ["u▫[yuů]"] = "ủ", ["[yů]▫u"] = "ủ",
		["a▫e"] = "ai", ["a▫o"] = "au", ["ę▫[uů]"] = "ay",
		["ę▫[ei]"] = "ei", ["ę▫o"] = "eu", 
		["e▫[aę]"] = "ia", ["e▫o"] = "io", ["i▫y"] = "iů",
		["[uo]▫e"] = "oi", ["o▫ů"] = "ou",
		["[yůo]▫o"] = "uo",
		["y▫y"] = "ỷ", ["ů▫ů"] = "ẻu",
		["([ae])▫ů"] = "%1y", ["([iou])▫ę"] = "%1a", 
		["[yů]▫[aę]"] = "ůa", ["[yů]▫[ei]"] = "ůi", -- to screen out stressed vs. unstressed
	}
	
	local triphthongs = {
		["([aoe])i([aoue])"] = "%1į%2", ["([aoe])ii"] = "%1gįi", ["([aoe])ỉ"] = "%1gįi",
		["ai[yů]"] = "ey", ["([eo])i[yů]"] = "%1įů",
		["u[ie]([aoue])"] = "uį%1", ["u[ie]i"] = "ugįi", ["uỉ"] = "ugįi", ["[uů][ie][yů]"] = "ůgįů",
		["ie([aouy])"] = "igį%1", ["ieů"] = "igįy", ["iee"] = "iẻ",
		["ůi([aoe])"] = "ůį%1", ["ůii"] = "ůgįi", ["ůỉ"] = "ůgįi", ["ůiu"] = "ůgįů",
		["ay([ae])"] = "ęm%1", ["ay([oiů])"] = "ęb%1", ["ay[uy]"] = "ębů",
		["uo([aue])"] = "um%1", ["uo([oi])"] = "ub%1", ["uo[yů]"] = "ůbů",
		["au([aue])"] = "am%1", ["au([oi])"] = "ab%1", ["au[yů]"] = "amů",
		["o[ua]([aue])"] = "om%1", ["o[ua]([oi])"] = "ob%1", ["o[ua][yů]"] = "omů",
		["[eẻ][uy]([ae])"] = "ům%1", ["[eẻ][uy]([oi])"] = "ůb%1", ["[eẻ][ua][yůu]"] = "ůbů",
		["iu([ae])"] = "ivv%1", ["iu([oui])"] = "ib%1", ["iu[yů]"] = "ivvů",
		["ả([aoue])"] = "ęį%1", ["ải"] = "ęgįi", ["[ảẻ][yů]"] = "ey",
		["ỏ([aue])"] = "om%1", ["([ỏỷ])([oi])"] = "%1b%2", ["ỏ[yů]"] = "omů",
		["([ủỷ])([ae])"] = "%1m%2", ["ủ([oui])"] = "ub%1", ["ủ[yů]"] = "ůbů",
		["([ẻỉ])([aou])"] = "%1vv%2", ["ẻ([ie])"] = "egį%1",
		["ỉi"] = "iddįi", ["ỷ[yů]"] = "yby",
		
	}
	
	for regex, repl in pairs(diphthongs) do
		word = gsub(word, regex, repl)
	end
	
	if stress then
		word = gsub(word, "[ůy][aęei]", "ỷ")
	end
	
	word = gsub(word, "▫", "")
	
	for regex, repl in pairs(triphthongs) do
		word = gsub(word, regex, repl)
	end
	
	return word
end

export.stressed_vowels = {
	["a"] = "a", ["ả"] = "a", ["au"] = "a",  ["ai"] = "a", ["oa"] = "a",
	["e"] = "e", ["ẻ"] = "e", ["ę"] = "e", ["ei"] = "e", ["ay"] = "e", ["eu"] = "e",
	["i"] = "i", ["ỉ"] = "i", ["ia"] = "i", ["ie"] = "i", ["io"] = "i", ["iu"] = "i",
	["o"] = "o", ["ỏ"] = "o", ["õ"] = "o", ["õu"] = "o", ["oi"] = "o", ["ou"] = "o",
	["u"] = "u", ["ủ"] = "u", ["uo"] = "u", ["ui"] = "u",
	["y"] = "y", ["ỷ"] = "y", ["ů"] = "y", ["ẻu"] = "y", ["ey"] = "y", ["ůa"] = "y", ["ůi"] = "y",
}

export.digraphs_to_single = {
	["ts"] = "ʦ", ["tṡ"] = "ʨ", ["dį"] = "ʥ", ["ng"] = "ŋ", ["nį"] = "ɲ",
	["kį"] = "c", ["gį"] = "ɟ", ["hh"] = "ħ", ["ḍḍ"] = "ð", ["dl"] = "ɬ", ["o̊"] = "ȯ",
	["õu"] = "ở", ["ẻu"] = "ử",
}

return export