Module:kilta-pron: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
 
(80 intermediate revisions by the same user not shown)
Line 1: Line 1:
local sub = mw.ustring.sub
local sub = mw.ustring.sub
local find = mw.ustring.find
local find = mw.ustring.find
local gmatch = string.gmatch
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local match = mw.ustring.match
Line 14: Line 14:
local m_IPA = require("Module:IPA")
local m_IPA = require("Module:IPA")


local consonants = "[pβmtsnɾlʧkxʷqhyʤɡbvdː]"
local consonants = "[pβmtsnɾlʧkxqhyʤɡbvdƕ]"
local vowels = "[aeiouáéíóúəïüʔ]"
local vowels = "[aeiouáéíóúəïüëæ]"


local export = {}
local export = {}
Line 27: Line 27:
local phonemic_rules = {
local phonemic_rules = {
{"%-$", ""}, {"%-", " "},
{"%-$", ""}, {"%-", " "},
{"h", "x"}, {"hw", "h"}, {"kw", "q"}, {"ch", "ʧ"}, {"au", "ü"}, {"ai", "ï"},
{"hw", "ƕ"}, {"kw", "q"}, {"ch", "ʧ"}, {"au", "ü"}, {"ai", "ï"}, {"h", "x"},  
{"v", "β"}, {"r", "ɾ"},  
{"v", "β"}, {"r", "ɾ"},  
{"ë", "ə"}, {"ëë+", "əː"}, --
{"ë", "ə"}, {"əə+", "əː"},
{"kq", "qː"}, {"(" .. consonants .. ")(" .. consonants .. ")",
{"kq", "qː"}, {"cʧ", "ʧː"}, {"(" .. consonants .. ")(" .. consonants .. ")",
function(c1,c2) return same(c1,c2) and c1 .. "ː" or c1 .. c2 end},
function(c1,c2) return same(c1,c2) and c1 .. "ː" or c1 .. c2 end},
}
}


local phonetic_rules = {
local phonetic_rules = {
{"a(ː?·?ˈ?)([nm])", "æ%1%2"},
{"a(·?ˈ?)([nm])", "æ%1%2"}, {"á(·?ˈ?)([nm])", "æː%1%2"},
{"n(ː?·?ˈ?)([kxqƕ])", "ŋ%1%2"},
{"n(ː?·?ˈ?)([kxqƕ])", "ŋ%1%2"},
{"([nm])·k", "%1·ɡ"}, {"([nm])·q", "%1·y"}, {"([nm])·p", "%1·b"}, {"([nm])·ʧ", "%1·ʤ"},
{"([nŋm]·?)k", "%"}, {"([nŋm]·?)q", "%1y"}, {"([nŋm]·?)p", "%1b"}, {"([nŋm]·?)ʧ", "%"},
{"([nm])·t", "%1·d"},  
{"([nŋm]·?)t", "%1d"},  
{"([nm])(ː?·?ˈ?)β", "%1%2b"},
{"([nŋm])(ː?·?ˈ?)β", "%1%2b"},
{"β([ie])", "v%1"},
{"β([iíeé])", "v%1"},
{"^(ˈ?)(" .. vowels .. ")", "%1ʔ%2"},
{"^(ˈ?)(" .. vowels .. ")", "%1ʔ%2"},
{"ü", "aʊ̯"},
{"ï", "aɪ̯"},
}
local deacuter = {
["á"] = "a", ["é"] = "e", ["í"] = "i", ["ó"] = "o", ["ú"] = "u",
}
}


local last_rules = {
local last_rules = {
{"q", "kʷ"}, {"h", "xʷ"}, {"y", "ɡʷ"},
{"q", "kʷ"}, {"ƕ", "xʷ"}, {"y", "ɡʷ"},
{"ʧ", "t͡ʃ"},
{"ʧ", "t͡ʃ"},
{"ʤ", "d͡ʒ"},
{"ʤ", "d͡ʒ"},
{"ü", "au̯"},
{"ü", "au̯"},
{"ï", "ai̯"},
{"ï", "ai̯"},
{"[·%.]ˈ", "ˈ"}, {"·", "."}, {"([áéíóú])", function(v) return mw.ustring.toNFD(v):gsub(A, "ː") end},
{"[·%.]ˈ", "ˈ"}, {"·", "."}, {"([áéíóú])", function(v) return deacuter[v] .. "ː" end},
}
 
local sandhi_rules = {
{"(" .. consonants .. ")u%sˈ?ʔ?(" .. vowels .. ")", "%1w%2"},
{"(" .. consonants .. ")i%sˈ?ʔ?(" .. vowels .. ")", "%1j%2"},
{"([mnŋ])(%sˈ?)βə", "%1%2bə"},
{"[mnŋ]%s(ˈ?[mpbβ])", "m %1"}, {"[mnŋ]%s(ˈ?v)", "ɱ %1"},
{"[mnŋ]%s(ˈ?[tdɾlsn])", "n %1"}, {"[mnŋ]%s(ˈ?[ʧʤ])", "n̠ %1"},
{"[mnŋ]%s(ˈ?[ŋkɡqƕy])", "ŋ %1"},
}
}


local function syllabify(term)
local function syllabify(term)
local iskolan = term == "kolaːn"
local first = term == "áxəpːi"
local syllable = "(" .. consonants .. "*" .. vowels .. consonants .. "-)"
local last = (term == "kolán" or term == "türá")
term = term:gsub("(" .. consonants .. ")ː", "%1·%1")
local syllable = "(" .. consonants .. "*)(" .. vowels .. "ː?)(" .. consonants .. "-)"
term = term:gsub("q·q", "k·q")
term = term:gsub(syllable, "·%")
term = gsub(term, syllable, "·%1%2%3·")
term = term:gsub("^·", "")
term = gsub(term, "^·", "")
term = term:gsub("·$", "")
term = gsub(term, "·$", "")
term = term:gsub("·+", "·")
term = gsub(term, "··+", "·")
term = term:gsub("·([nlɾs])([pβmtʧkxʷqƕː])", "%1·%2")
term = gsub(term, "·(" .. consonants .. ")ː·", "%1·%1")
term = term:gsub("·([tmnlɾs])$", "%1")
term = gsub(term, "q·q", "k·q")
term = term:gsub("·(" .. consonants .. ")·", "%")
term = gsub(term, "·(" .. consonants .. ")·", "%1·")
term = gsub(term, "·(" .. consonants .. ")(" .. consonants .. ")", "%1·%2")
term = gsub(term, "·([nslɾmt])$", "%1")
term = gsub(term, "·(" .. consonants .. ")ː·", "·%1")
--local syllables = split(term, "·")
local syllables = split(term, "·")
local syllables = {}
if first then
for m in term:gmatch("[^·]+") do
syllables[1] = "ˈ" .. syllables[1]
table.insert(syllables, m)
elseif last then
end
syllables[#syllables] = "ˈ" .. syllables[#syllables]
if iskolan then
syllables[#syllables] = "ˈ" .. syllables[#syllables] -- ultimate stress
elseif #syllables > 1 then
elseif #syllables > 1 then
syllables[#syllables - 1] = "ˈ" .. syllables[#syllables - 1] -- penultimate stress
syllables[#syllables - 1] = "ˈ" .. syllables[#syllables - 1] -- penultimate stress
else
error("debug: " .. #syllables)
end
end
Line 98: Line 112:
for _, rule in ipairs(phonetic_rules) do
for _, rule in ipairs(phonetic_rules) do
phonetic = gsub(phonetic, rule[1], rule[2])
end
for _, rule in ipairs(last_rules) do
phonemic = gsub(phonemic, rule[1], rule[2])
phonetic = gsub(phonetic, rule[1], rule[2])
phonetic = gsub(phonetic, rule[1], rule[2])
end
end
Line 118: Line 127:
end
end
return table.concat(phonemic, " "), table.concat(phonetic, " ")
local phonemicAll = table.concat(phonemic, " ")
local phoneticAll = table.concat(phonetic, " ")
for _, rule in ipairs(sandhi_rules) do
phoneticAll = gsub(phoneticAll, rule[1], rule[2])
end
for _, rule in ipairs(last_rules) do
phonemicAll = gsub(phonemicAll, rule[1], rule[2])
phoneticAll = gsub(phoneticAll, rule[1], rule[2])
end
return phonemicAll, phoneticAll
end
end


Line 130: Line 151:


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


return "* " .. m_IPA.format_IPA_full(lang, IPA_args)
return "* " .. m_IPA.format_IPA_full({lang = lang, items = IPA_args})
end
end


return export
return export

Latest revision as of 18:07, 12 August 2024

Documentation for this module may be created at Module:kilta-pron/doc

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 gsplit = mw.text.gsplit
local split = mw.text.split

local A = u(0x0301) -- COMBINING ACUTE
local D = u(0x0308) -- COMBINING DIAERESIS

local lang = require("Module:languages").getByCode("kilta")
local m_IPA = require("Module:IPA")

local consonants = "[pβmtsnɾlʧkxqhyʤɡbvdƕ]"
local vowels = "[aeiouáéíóúəïüëæ]"

local export = {}

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 phonemic_rules = {
	{"%-$", ""}, {"%-", " "},
	{"hw", "ƕ"}, {"kw", "q"}, {"ch", "ʧ"}, {"au", "ü"}, {"ai", "ï"}, {"h", "x"}, 
	
	{"v", "β"}, {"r", "ɾ"}, 
	{"ë", "ə"}, {"əə+", "əː"},
	
	{"kq", "qː"}, {"cʧ", "ʧː"}, {"(" .. consonants .. ")(" .. consonants .. ")",
		function(c1,c2) return same(c1,c2) and c1 .. "ː" or c1 .. c2 end},
}

local phonetic_rules = {
	{"a(·?ˈ?)([nm])", "æ%1%2"}, {"á(·?ˈ?)([nm])", "æː%1%2"},
	{"n(ː?·?ˈ?)([kxqƕ])", "ŋ%1%2"},
	{"([nŋm]·?)k", "%1ɡ"}, {"([nŋm]·?)q", "%1y"}, {"([nŋm]·?)p", "%1b"}, {"([nŋm]·?)ʧ", "%1ʤ"},
	{"([nŋm]·?)t", "%1d"}, 
	{"([nŋm])(ː?·?ˈ?)β", "%1%2b"},
	{"β([iíeé])", "v%1"},
	{"^(ˈ?)(" .. vowels .. ")", "%1ʔ%2"},
	{"ü", "aʊ̯"},
	{"ï", "aɪ̯"},
}

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

local last_rules = {
	{"q", "kʷ"}, {"ƕ", "xʷ"}, {"y", "ɡʷ"},
	{"ʧ", "t͡ʃ"},
	{"ʤ", "d͡ʒ"},
	{"ü", "au̯"},
	{"ï", "ai̯"},
	{"[·%.]ˈ", "ˈ"}, {"·", "."}, {"([áéíóú])", function(v) return deacuter[v] .. "ː" end},
}

local sandhi_rules = {
	{"(" .. consonants .. ")u%sˈ?ʔ?(" .. vowels .. ")", "%1w%2"},
	{"(" .. consonants .. ")i%sˈ?ʔ?(" .. vowels .. ")", "%1j%2"},
	{"([mnŋ])(%sˈ?)βə", "%1%2bə"},
	{"[mnŋ]%s(ˈ?[mpbβ])", "m %1"}, {"[mnŋ]%s(ˈ?v)", "ɱ %1"},
	{"[mnŋ]%s(ˈ?[tdɾlsn])", "n %1"}, {"[mnŋ]%s(ˈ?[ʧʤ])", "n̠ %1"},
	{"[mnŋ]%s(ˈ?[ŋkɡqƕy])", "ŋ %1"},
}

local function syllabify(term)
	local first = term == "áxəpːi"
	local last = (term == "kolán" or term == "türá")
	local syllable = "(" .. consonants .. "*)(" .. vowels .. "ː?)(" .. consonants .. "-)"
	
	term = gsub(term, syllable, "·%1%2%3·")
	term = gsub(term, "^·", "")
	term = gsub(term, "·$", "")
	term = gsub(term, "··+", "·")
	
	term = gsub(term, "·(" .. consonants .. ")ː·", "%1·%1")
	term = gsub(term, "q·q", "k·q")
	term = gsub(term, "·(" .. consonants .. ")·", "%1·")
	term = gsub(term, "·(" .. consonants .. ")(" .. consonants .. ")", "%1·%2")
	term = gsub(term, "·([nslɾmt])$", "%1")
	term = gsub(term, "·(" .. consonants .. ")ː·", "·%1")
	
	local syllables = split(term, "·")
	
	if first then
		syllables[1] = "ˈ" .. syllables[1]
	elseif last then
		syllables[#syllables] = "ˈ" .. syllables[#syllables]
	elseif #syllables > 1 then
		syllables[#syllables - 1] = "ˈ" .. syllables[#syllables - 1] -- penultimate stress
	end
	
	return table.concat(syllables, "·")
end

function export.crux(term)
	term = mw.ustring.lower(term)
	local phonemic = term
	
	for _, rule in ipairs(phonemic_rules) do
		phonemic = gsub(phonemic, rule[1], rule[2])
	end
	
	phonemic = syllabify(phonemic)
	local phonetic = phonemic
	
	for _, rule in ipairs(phonetic_rules) do
		phonetic = gsub(phonetic, rule[1], rule[2])
	end
	
	return phonemic, phonetic
end

function separate_word(term)
	local phonemic, phonetic = {}, {}
	
	for word in gsplit(term, " ") do
		local phonemicEach, phoneticEach = export.crux(word)
		table.insert(phonemic, phonemicEach)
		table.insert(phonetic, phoneticEach)
	end
	
	local phonemicAll = table.concat(phonemic, " ")
	local phoneticAll = table.concat(phonetic, " ")
	
	for _, rule in ipairs(sandhi_rules) do
		phoneticAll = gsub(phoneticAll, rule[1], rule[2])
	end
	
	for _, rule in ipairs(last_rules) do
		phonemicAll = gsub(phonemicAll, rule[1], rule[2])
		phoneticAll = gsub(phoneticAll, rule[1], rule[2])
	end
	
	return phonemicAll, phoneticAll
end

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

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

	return "* " .. m_IPA.format_IPA_full({lang = lang, items = IPA_args})
end

return export