Module:siwa-pron: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
Line 37: Line 37:
local stressed_rules = {["h"] = "ʔ", ["ɡį"] = "jː", ["hh"] = "hː",}
local stressed_rules = {["h"] = "ʔ", ["ɡį"] = "jː", ["hh"] = "hː",}


for r in gmatch(s2, ".") do
xx= gsub(s2, s2, stressed_rules[s2])
end
return gsub(s2, s2, stressed_rules[s2])
return r
end
end



Revision as of 23:30, 5 January 2021



local export = {}
	
local m_IPA = require("Module:IPA")
local m_su = require("Module:string utilities")
local m_table = require("Module:table")
local m_sm = mw.loadData('Module:siwa-pron/data')

local sub = mw.ustring.sub
local find = mw.ustring.find
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split

local UNRELEASED = u(0x031A) -- COMBINING LEFT ANGLE ABOVE. ̚
local NASALIZED = u(0x0303) -- COMBINING TILDE. ̃

--obsolete ligatures and L with stroke used to remove two-character hassle. will replace later
local consonant = "[mnɲŋpbtdcɟkɡʔvðsɕxɣhʨʥrlɬłʣjwʦʔ]" .. UNRELEASED .. "?"
local front_vowel = "iɪyeøɛœæa"
local back_vowel = "uɔ" .. NASALIZED .. "?ɑʊ"
local vowel = "[" .. front_vowel .. back_vowel .. "]"
local stpattern = "(·?ˈ[mnɲŋpbtdcɟkɡʔvðsɕxɣhʨʥrlɬłʣjwʦ⁽ʰ⁾ʔː]*"..UNRELEASED.."?[iɪyeøɛœæauɔɑʊ])([mnɲŋpbtdcɟkɡʔvðsɕxɣhʨʥrlɬłʣjwʦʔː]*"..UNRELEASED.."?)"

local function open_to_closed(v)
	local otc = {}
	local switch = {["ɑ"] = "a", ["e"] = "ɛ", ["i"] = "ɪ", ["ɔ"] = "ɔ", ["u"] = "ʊ", ["y"] = "œ", ["ø"] = "œ",}
	
	for vc in gmatch(v, ".") do
		vc = gsub(vc, vc, switch[vc])
		table.insert(otc, vc)
	end
	return table.concat(otc)
end

local function stressed(s2)
	local stressed_rules = {["h"] = "ʔ", ["ɡį"] = "jː", ["hh"] = "hː",}

	for r in gmatch(s2, ".") do
		xx= gsub(s2, s2, stressed_rules[s2])
	end
	
	return r
end

local rules = {
	{	--long consonants
		["mm"] = "mː", ["bb"] = "pː", ["vv"] = "wː", ["nn"] = "nː",
		["dd"] = "tː", ["ḍḍ"] = "ðː", ["ss"] = "sː", ["ṡṡ"] = "ɕː",
		["ddį"] = "ʥː", ["rr"] = "rː", ["ll"] = "lː", ["gg"] = "kː",
		["ġġ"] = "xː", ["ng"] = "ŋː", ["hh"] = "hː", ["ḥḥ"] = "ʔː",
		["nnį"] = "ɲː", ["hl"] = "ɬː", ["ggį"] = "ɟː",
	},
	{	--consonants not affected by stress
		["ṡ"] = "ɕ", ["tṡ"] = "ʨ", ["dį"] = "ʥ",
		["ḍ"] = "ð", ["dl"] = "ł", ["kį"] = "c",
		["nį"] = "ɲ", ["ġ"] = "x", ["ts"] = "ʦ", ["g"] = "ɡ" -- IPA g
	},
	{	--all vowels as open (open-closed distinctions are computed later)
		["a"] = "ɑ", ["ả"] = "æː",
		["ę"] = "æ",
		["ẻ"] = "eː",
		["ỉ"] = "iː",
		["o"] = "ɔ", ["ỏ"] = "ʊː",
		["ủ"] = "uː",
		["ỷ"] = "yː",
		["ů"] = "ø", ["ẻu"] = "øː",
		["õ"] = "ɔ̃", ["õu"] = "ɔ̃ː̃",
	},
	{
		["^(ˈ)k([" .. front_vowel .. "])"] = "%1c%2", --word-initial [k] palatalizes before front-vowels
		["^(ˈ[ptkc])"] = "%1ʰ", --voiceless stops word-initially become aspirated
		["^(.*·ˈ[ptkc])"] = "%1⁽ʰ⁾",
		["^(ˈ)ɡį([" .. front_vowel .. "])"] = "%1ʣ%2", --<gį> word-initially and before front vowels is pronounced [d͡z]
		["^(ˈ)ɡį([" .. back_vowel .. "])"] = "%1ɟ%2",
		["^(ˈ)ɡ([" .. front_vowel .. "])"] = "%1ɟ%2",
	},
	{
		["(" .. vowel .. "*)(" .. consonant .. consonant .. ")"] = function(s1, s2) return open_to_closed(s1) .. s2 end,
		["(" .. vowel .. "*)(" .. consonant .. ")$"] = function(s1, s2) return open_to_closed(s1) .. s2 end,
		["ɑ$"] = "a",
	},
	{
		["(" .. vowel .. ")t$"] = "%1ʔ%1", -- -Vt becomes -VʔV (or -Vht, not considered)
		["pp"] = "ʔp", ["tt"] = "ʔt", ["kk"] = "ʔk",
		["bm"] = "ʔp̚m", ["dn"] = "ʔt̚n", ["kn"] = "ʔk̚ŋ",
		["mn"] = "mnː", ["mʔk"] = "m̥kː", ["mkː"] = "m̥kː",
		["ġl"] = "xɬ",
	},
	{
		[stpattern] = function(s1, s2) return s1 .. stressed(s2) end,
	},
}



local unstressed_rules = {
	{	--undo ligatures
		["ʨ"] = "t͡ɕ", ["ʥ"] = "d͡ʑ", ["ł"] = "tɬ", ["ʣ"] = "d͡z", ["ʦ"] = "t͡s",
	},
	{
		["·"] = "", --remove morpheme separator	
	},
}

function export.morphemes(word)
	local pss = {}

	if gmatch(word,"·") then
		pss = split(word,"·")
	end
	
	for i, m in ipairs(pss) do
		if m_sm.suffix[m] and gmatch(table.concat(pss),"[ˈˌ]") then
		elseif m_sm.prefix[m] then
			pss[i] = "ˌ" .. pss[i]
		else
			pss[i] = "ˈ" .. pss[i]
		end
	end
	
	return table.concat(pss,"·")
end

function export.crux(term)
	local IPA = {}
	
	term=mw.ustring.lower(term)
	term=export.morphemes(term)
	
	for _, rule in ipairs(rules) do
		for regex, replacement in pairs(rule) do
			term = gsub(term, regex, replacement)
		end
	end
	
	table.insert(IPA, term)
	return table.concat(IPA)
end

function export.show(frame)
	local parent_args = frame:getParent().args
	local params = {
		[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "uįo·sauṡṡi" or mw.title.getCurrentTitle().text },
	}
	local args = require("Module:parameters").process(parent_args, params)
	local term = args[1]
	
	local ipa = export.crux(term)
	
	local IPA_key = "IPA for Siwa"
	local key_link = "[[".. IPA_key .."|key]]"

	local prefix = "[[w:IPA chart|IPA]]<sup>(" .. key_link .. ")</sup>:&#32;"
	local accent="(\''Aingo\'') "
	
	ipa = "<span style=\"font-size:110%;font-family:Gentium,'DejaVu Sans','Segoe UI',sans-serif>[" .. ipa .. "]</span>"
	ipa = accent..prefix..ipa
	
	return ipa
end

return export