Module:anui-pron: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
Line 21: Line 21:
local front_vowel = "iea"
local front_vowel = "iea"
local vowel = "[" .. back_vowel .. front_vowel .. "]"
local vowel = "[" .. back_vowel .. front_vowel .. "]"
local oral_to_nasal = {["a"] = "ã", ["i"] = "ĩ", ["ɔ"] = "ṍ", ["u"] = "ᴍ"}
local oral_to_nasal = {["a"] = "ã", ["i"] = "ĩ", ["ɔ"] = "ṍ", ["u"] = "ᴍ"} -- ṍ = ɔ̃
local modal_to_glottal = {["a"] = "à", ["i"] = "ì", ["ɔ"] = "ò", ["u"] = "ù"} -- ṏ = ɔ̰
local nasalized = "[ãĩṍᴍ]"
local nasalized = "[ãĩṍᴍ]"
local glottalic = "[àèìòù]"


local function same(foo, bar)
local function same(foo, bar)
foo, bar = mw.ustring.toNFD(foo), mw.ustring.toNFD(bar)
foo, bar = mw.ustring.toNFD(foo), mw.ustring.toNFD(bar) -- decompose diacritics
foo, bar = match(foo, "^."), match(bar, "^.")
foo, bar = match(foo, "^."), match(bar, "^.") -- sort out the letter
return foo == bar and true or false
return foo == bar and true or false
end
end
Line 38: Line 40:
{"(" .. vowel .. ")(".. vowel .. ")", function(s1, s2) return same(s1, s2) and s1 .. "ː˧" or s1 .. s2 .. "˧" end},
{"(" .. vowel .. ")(".. vowel .. ")", function(s1, s2) return same(s1, s2) and s1 .. "ː˧" or s1 .. s2 .. "˧" end},
{"(" .. vowel .. ")(" .. nasalized .. ")", function(s1, s2) return same(s1, s2) and s2 .. "ː" .. HIGHFALL or oral_to_nasal[s1] .. s2 .. HIGHFALL end},
{"(" .. vowel .. ")(" .. nasalized .. ")", function(s1, s2) return same(s1, s2) and s2 .. "ː" .. HIGHFALL or oral_to_nasal[s1] .. s2 .. HIGHFALL end},
 
{"([" .. front_vowel .. "])(" .. glottalic .. ")", function(s1, s2) return same(s1, s2) and s2 .. "ː" .. HIGHFALL or modal_to_glottal[s1] .. s2 .. HIGHFALL end},
{"ṍ", "ɔ" .. NASAL},
{"ṍ", "ɔ" .. NASAL},
}
}

Revision as of 13:45, 2 July 2021



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

-- To avoid weird annoying cursor behavior
local TILDE, NASAL = u(0x0303), u(0x0303) -- COMBINING TILDE ̃◌
local TILDEBELOW, CREAKY = u(0x0330), u(0x0330) -- COMBINING TILDE BELOW ̰◌
local GRAVE = u(0x0300) -- COMBINING GRAVE ACCENT ̀◌
local HIGHFALL = "˥˦"
local SYLLABIC = u(0x0329) -- COMBINING VERTICAL LINE BELOW ̩◌
local SYLLABICA = u(0x030D) -- COMBINING VERTICAL LINE ABOVE ̍◌
local INTERDENTAL = u(0x032A) .. u(0x0346) -- COMBINING BRIDGE BELOW AND ABOVE ̪͆◌
local VOICELESS = u(0x0325) -- COMBINING RING BELOW ̥◌

local back_vowel = "uɯɔɑ"
local front_vowel = "iea"
local vowel = "[" .. back_vowel .. front_vowel .. "]"
local oral_to_nasal = {["a"] = "ã", ["i"] = "ĩ", ["ɔ"] = "ṍ", ["u"] = "ᴍ"} -- ṍ = ɔ̃
local modal_to_glottal = {["a"] = "à", ["i"] = "ì", ["ɔ"] = "ò", ["u"] = "ù"} -- ṏ = ɔ̰
local nasalized = "[ãĩṍᴍ]"
local glottalic = "[àèìòù]"

local function same(foo, bar)
	foo, bar = mw.ustring.toNFD(foo), mw.ustring.toNFD(bar) -- decompose diacritics
	foo, bar = match(foo, "^."), match(bar, "^.") -- sort out the letter
	return foo == bar and true or false
end

local export = {}

local rules = {
	{"ʇ", "ǀ"}, {"õ", "ṍ"}, {"o", "ɔ"}, {"ṭ", "ʈ"}, {"j", "ɟ"}, {"ñ", "ɲ"},
	{"([ḛḭṵ])", {["ḛ"] = "è", ["ḭ"] = "ì", ["ṵ"] = "ù"}}, {"([ao])" .. TILDEBELOW, mw.ustring.toNFC("%1" .. GRAVE)},
	{"([uùm]ʼ?)m", "%1ᴍ"}, {"m(ʼᴍ)", "ᴍ%1"}, -- tell apart between regular and syllabic <m>
	{"(" .. vowel .. ")(".. vowel .. ")", function(s1, s2) return same(s1, s2) and s1 .. "ː˧" or s1 .. s2 .. "˧" end},
	{"(" .. vowel .. ")(" .. nasalized .. ")", function(s1, s2) return same(s1, s2) and s2 .. "ː" .. HIGHFALL or oral_to_nasal[s1] .. s2 .. HIGHFALL end},
	{"([" .. front_vowel .. "])(" .. glottalic .. ")", function(s1, s2) return same(s1, s2) and s2 .. "ː" .. HIGHFALL or modal_to_glottal[s1] .. s2 .. HIGHFALL end},
	
	{"ṍ", "ɔ" .. NASAL},
}

function export.crux(term)
	term=mw.ustring.lower(term)
	
	for _, rule in ipairs(rules) do
		term = gsub(term, rule[1], rule[2])
	end
	
	return term
end

return export