Module:qay-pron: Difference between revisions

From Linguifex
Jump to navigation Jump to search
Created page with "local sub = mw.ustring.sub local find = mw.ustring.find local gmatch = mw.ustring.gmatch local gsub = mw.ustring.gsub local match = mw.ustring.match local u = mw.ustring.char..."
 
No edit summary
Line 21: Line 21:
local vowels = "[aeiouyáéíóúýàèìòùỳː" .. NONSYLLABIC .. DIPHTHONG .. "]"
local vowels = "[aeiouyáéíóúýàèìòùỳː" .. NONSYLLABIC .. DIPHTHONG .. "]"


local rules = {
local phonemic_rules = {
{"rh", ""}, {"mh", "m"}, {"th", "θ"}, {"lj", "ʎ"}, {"ñ", "ɲ"}, {"kh", "x"}, {"[gɡ]h", "ɣ"}, {"g", "ɡ"},
{"mh", "m"},
}
{"([aāáà][eo])", "%1" .. NONSYLLABIC}, {"([iíuú])([aāeēoōáéóàèò])", "%1" .. DIPHTHONG .. "%2"},
 
{"ā", "aː"}, {"ē", "eː"}, {"ī", "iː"}, {"ō", "oː"}, {"ū", "uː"}, {"ȳ", "yː"},
local phonetic_rules = {
{"à", "áː"}, {"è", "éː"}, {"ì", "íː"}, {"ò", "óː"}, {"ù", "úː"}, {"ỳ", "ýː"},
{"mh", "m"}, {"th", "θ"}, {"lj", "ʎ"}, {"ñ", "ɲ"}, {"kh", "x"}, {"[gɡ]h", "ɣ"}, {"g", "ɡ"},
{"n([" .. palatal .. "])", "ɲ%1"}, {"n([" .. velar .. "])", "ŋ%1"}, {"n([" .. uvular .. "])", "ɴ%1"},
{"(" .. vowels .. ")r(" .. vowels .. ")", "%1ɾ%2"}, {"ɲi", "ni"}, {"ʎi", "li"},
}
}


Line 36: Line 33:
}
}


function export.write_stress(term, from_module)
local function write_stress(term)
local pattern = "(" .. consonants .. "*".. vowels .. "*" .. consonants .. "-)"
--[=[local pattern = "(" .. consonants .. "*".. vowels .. "*" .. consonants .. "-)"
local weight = {}
local weight = {}
term = gsub(term, pattern, "·%1")
term = gsub(term, pattern, "·%1")
Line 71: Line 68:
else table.insert(syllables, #syllables-1, "ˈ") end
else table.insert(syllables, #syllables-1, "ˈ") end
return table.concat(syllables)
return table.concat(syllables)]=]
return term
end
end


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


function export.antique_crux(term)
function export.phonetic(term)
local oldrules = {
term = mw.ustring.lower(term)
{"v([ou])", "w%1"}, {"v([ay])", "ɥ%1"}, {"(" .. vowels .. ")v(ˈ?" .. consonants .. ")", "%1u%2"},
{"j([iy])", "ɟ%1"}, {"sˈ?ri(".. vowels .. ")", "ˈɟ%1"}, {"sr", "ɟ"}, {"sˈ?r", "ˈɟ"},
}
term = export.crux(term)
for _, oldrule in ipairs(oldrules) do
for _, ticrule in ipairs(phonetic_rules) do
term = gsub(term, oldrule[1], oldrule[2])
term = gsub(term, ticrule[1], ticrule[2])
end
end
return term
return write_stress(term)
end
end



Revision as of 10:13, 20 June 2022



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

local lang = require("Module:languages").getByCode("qay")
local m_table = require("Module:table")

local export = {}

local palatal = "ɲʎɟj"
local velar = "kɡxɣ"
local uvular = "q"
local consonants = "[mpbvwθntdszlrɾŋɴhɥṛ" .. palatal .. velar .. uvular .. "]"
local NONSYLLABIC = u(0x032F) -- non-syllabic, combining inverted breve below
local DIPHTHONG = u(0x035C) -- double articulation, combining double breve below
local vowels = "[aeiouyáéíóúýàèìòùỳː" .. NONSYLLABIC .. DIPHTHONG .. "]"

local phonemic_rules = {
	{"mh", "m"},
}

local phonetic_rules = {
	{"mh", "m"}, {"th", "θ"}, {"lj", "ʎ"}, {"ñ", "ɲ"}, {"kh", "x"}, {"[gɡ]h", "ɣ"}, {"g", "ɡ"},
}

local deacuter = {
	["á"] = "a", ["é"] = "e", ["í"] = "i", ["ó"] = "o", ["ú"] = "u", ["ý"] = "y",
}

local function write_stress(term)
	--[=[local pattern = "(" .. consonants .. "*".. vowels .. "*" .. consonants .. "-)"
	local weight = {}
	term = gsub(term, pattern, "·%1")
	term = gsub(term, "^·", "")
	term = gsub(term, "·$", "")
	term = gsub(term, "·(" .. consonants .. ")·", "·%1")
	term = gsub(term, "·(" .. consonants .. ")$", "%1")
	term = gsub(term, "·(" .. consonants .. ")(" .. consonants .. ")", "%1·%2")  
	term = gsub(term, "([ptkbdɡ])·([rlṛsz])", "·%1%2")
	term = gsub(term, "·(" .. consonants .. "?" .. consonants .. ")$", "%1")
	
	local syllables = split(term, "·")
	
	if from_module then return #syllables end -- allow other modules to know the number of syllables
	
	if #syllables == 1 then return table.concat(syllables) end -- account for monosyllables
	for i, syllable in ipairs(syllables) do
		if match(syllable, "[áéíóúý]") then -- if the user inputted manual stress, ignore all the rest
			table.insert(syllables, i, "ˈ")
			return table.concat(syllables)
		end	
		if match(syllable, consonants .. "$") or match(syllable, "ː$") then weight[i] = "h"
		elseif match(syllable, NONSYLLABIC .. "$") then weight[i] = "h"
		else weight[i] = "l"
		end
	end
	
	local a, p = weight[#weight-2], weight[#weight-1]
	if p == nil then table.insert(syllables, #syllables, "ˈ")
	elseif a == nil then table.insert(syllables, #syllables-1, "ˈ")
	elseif p == "l" and a == "h" then table.insert(syllables, #syllables-2, "ˈ")
	elseif (p == "l" and a == "l") or (p == "h") then table.insert(syllables, #syllables-1, "ˈ")
	else table.insert(syllables, #syllables-1, "ˈ") end
	
	return table.concat(syllables)]=]
	return term
end

function export.phonemic(term)
	term = mw.ustring.lower(term)
	
	for _, micrule in ipairs(phonemic_rules) do
		term = gsub(term, micrule[1], micrule[2])
	end
	
	return write_stress(term)
end

function export.phonetic(term)
	term = mw.ustring.lower(term)
	
	for _, ticrule in ipairs(phonetic_rules) do
		term = gsub(term, ticrule[1], ticrule[2])	
	end
	
	return write_stress(term)
end

--[=[
local function IPA_span(items)
	local bits = {}
	for _, item in ipairs(items) do
		local bit = "<span style=\"font-size:110%;font-family:Gentium,'DejaVu Sans','Segoe UI',sans-serif>" .. item.pron .. "</span>"
		table.insert(bits, bit)
	end
	return table.concat(bits)
end

local function format_IPA(items)
	return "[[w:IPA chart|IPA]]<sup>([[IPA for High Valyrian|key]])</sup>:&#32;" .. IPA_span(items)
end

function line_format(pronunciation, register)
	local IPA_args = {}
	for _, arg in ipairs(args[1]) do
		local phonemic = export.phonemic(arg)
		local phonetic = export.phonetic(arg)
		table.insert(IPA_args, {pron = '/' .. phonemic .. '/'})
		if phonemic ~= phonetic then
			table.insert(IPA_args, {pron = '[' .. phonetic .. ']'})
		end
	end
end

function separate_word(term, b)
	local result = {}
	
	for word in gsplit(term, " ") do
		if b then table.insert(result, export.antique_crux(word))
		else table.insert(result, export.crux(word)) end
	end
	
	return table.concat(result, " ")
end
]=]

function export.show(frame)
	local parent_args = frame:getParent().args
	local params = {
		[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "ankyu" or mw.title.getCurrentTitle().text },
	}
	local args = require("Module:parameters").process(parent_args, params)
	local term = args[1]

	local IPA_args = {}
	local phonemic = export.phonemic(term)
	local phonetic = export.phonetic(term)
	table.insert(IPA_args, {pron = '/' .. phonemic .. '/'})
	if phonemic ~= phonetic then
		table.insert(IPA_args, {pron = '[' .. phonetic .. ']'})
	end

	return m_IPA.format_IPA_full(lang, IPA_args)
end

return export