Module:kilta-pron: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
Line 79: Line 79:
phonetic = gsub(phonetic, rule[1], rule[2])
phonetic = gsub(phonetic, rule[1], rule[2])
end
end
phonemic, phonetic = syllabicize(phonemic), syllabicize(phonetic)
return phonemic, phonetic
return phonemic, phonetic

Revision as of 18:29, 20 April 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 split = mw.text.split
local gsplit = mw.text.gsplit

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ʧkxʷʞƕː]"
local vowels = "[aeiouəꜷꜽ" .. A .. D .. "ː]"

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 function syllabicize(term)
	local syllable = "(" .. consonants .. "*" .. vowels .. "ː" .. consonants .. "-)"
	term = term:gsub(syllable, ".%1.")
	
	term = term:gsub("^%.", "")
	term = term:gsub("%.$", "")
	term = term:gsub("%.+", ".")
	
	return term
end

local phonemic_rules = {
	{"%-", ""}, {"hw", "ƕ"}, {"kw", "ʞ"}, {"ch", "ʧ"}, {"au", "ꜷ"}, {"ai", "ꜽ"},
	
	{"v", "β"}, {"r", "ɾ"}, {"h", "x"},
	{"ë", "ə"}, {"e" .. D, "ə"}, {"ëë+", "əː"}, {"e" .. D .. "e" .. D, "əː"},
	{"(" .. vowels .. ")".. A, "%1ː"},
}

local phonetic_rules = {
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, 
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, 
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, 
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, 
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, 
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, 
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, 
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, 
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, 
	{"", ""}, {"", ""}, {"", ""}, {"", ""}, {"", ""}, 
}

local last_rules = {
	{"ʞ", "kʷ"},
	{"ƕ", "xʷ"},
	{"ʧ", "t͡ʃ"},
}

function export.crux(term)
	term = mw.ustring.lower(mw.ustring.toNFD(term))
	local phonemic, phonetic = "", ""
	
	for _, rule in ipairs(phonemic_rules) do
		phonemic = gsub(term, rule[1], rule[2])
	end
	
	for _, rule in ipairs(phonetic_rules) do
		phonetic = gsub(phonemic, 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])
	end
	
	phonemic, phonetic = syllabicize(phonemic), syllabicize(phonetic)
	
	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
	
	return table.concat(phonemic, " "), table.concat(phonetic, " ")
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 = '/' .. phonemic .. '/'}, {pron = '[' .. phonetic .. ']'}}

	return "* " .. m_IPA.format_IPA_full(lang, IPA_args)
end

return export