Module:qlu-pron: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 55: | Line 55: | ||
{"gli?", "ʎ"}, {"gni?", "ɲ"}, | {"gli?", "ʎ"}, {"gni?", "ɲ"}, | ||
{"(" .. vowels .. ")([ʣʎɲ])(" .. vowels .. ")", "%1%2%2%3"}, | {"(" .. vowels .. ")([ʣʎɲ])(" .. vowels .. ")", "%1%2%2%3"}, | ||
{"([ʧʤ])i(" .. vowels .. ")", "%1%2"}, | |||
{"ts", "ʦ"}, {"ph", "ɸ"}, {"th", "ʈ"}, --{"h", ""}, | {"ts", "ʦ"}, {"ph", "ɸ"}, {"th", "ʈ"}, --{"h", ""}, | ||
Revision as of 21:10, 25 January 2025
- The following documentation is located at Module:qlu-pron/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module generates IPA pronunciation for Luthic words. Backend to {{qlu-IPA}}.
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("qlu")
local m_table = require("Module:table")
local m_IPA = require("Module:IPA")
local c = require("Module:languages/data").chars
local export = {}
local voiced = "mnɲŋbdgβvzðɣʣʤlʎrɹɾʁʒʥǵ"
local voiceless = "ptʈkɸfsθʃxʦʧʨḱ"
local consonants = "[" .. voiced .. voiceless .. "ʷː]"
local front = "eêĕéiïíîɛɪæyʏøœ"
local back = "uúûüoóôɔʊʌɑɒ"
local vowels = "[aáâăɐ" .. front .. back .. c.acute .. c.breve .. c.circ .. c.diaer .. "jw]"
local function dediacv(str, diacritic)
return gsub(mw.ustring.toNFD(str), diacritic, "")
end
local function laxen(v)
local otc = {}
local switch = {["e"] = "i", ["i"] = "ɪ", ["u"] = "ʊ"}
for vc in gmatch(v, ".") do
if switch[vc] then vc = gsub(vc, vc, switch[vc]) end
table.insert(otc, vc)
end
return table.concat(otc)
end
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 first_rules = {
-- Greco-Roman digraphs
{"^mn", "n"}, {"^tm", "m"}, {"^ps", "s"},
{"ch", "k"}, {"g([ckqg])", "ŋ%1"},
{"sc([eêĕéiïíî])", "ʃ%1"}, {"c([eêĕéiïíî])", "ʧ%1"},
{"g([eêĕéiïíî])", "ʤ%1"}, {"gh", "g"},
{"c", "k"}, {"ŋʤ", "dʤ"}, {"ŋʧ", "ŋk"}, {"dz", "ʣ"},
{"ŋgü", "gǵ"}, {"gu(" .. vowels .. ")", "ǵ%1"},
{"gli?", "ʎ"}, {"gni?", "ɲ"},
{"(" .. vowels .. ")([ʣʎɲ])(" .. vowels .. ")", "%1%2%2%3"},
{"([ʧʤ])i(" .. vowels .. ")", "%1%2"},
{"ts", "ʦ"}, {"ph", "ɸ"}, {"th", "ʈ"}, --{"h", ""},
{"qu?", "ḱ"}, {"þ", "θ"},
{"%-", ""},
}
local phonemic_rules = {
{"a", "ɐ"}, {"([ˈˌ])([^ɐ·a]*)ɐ", "%1%2a"},
}
local phonetic_rules = {
}
local last_rules = {
-- Escaped characters
{"ʤ", "d͡ʒ"}, {"ʧ", "t͡ʃ"}, {"ʦ", "t͡s"}, {"ʣ", "d͡z"},
{"ḱ", "kʷ"}, {"ǵ", "ɡʷ"}, {"ʈ", "t"}, {"g", "ɡ"},
-- vowel digraphs
{"[ăa]e", "ɛ"}, {"[ăa]u", "ɔ"}, {"[ĕe]i", "i"},
{"·", "."},
}
local function syllabify(word)
local clusters = require("Module:table").listToSet({
"s[ptʈkfɸ]", "z[bdgβʤmnlr]",
"[fɸvβpbtʈdkgθð]r", "[fɸvβpbkg]l",
"[fɸvβszpbtʈdkgmnŋɲ][jw]",
"s[ptʈkfɸ]r", "z[bdg]r",
"s[pk]l", "zbl",
"[fɸvβpbtʈdkg]r[jw]",
"gn", "[θð]vβr",
})
if not match(word, "·") then
for cluster, _ in pairs(clusters) do
word = gsub(word, "(" .. cluster .. vowels .. "+" .. consonants .. "?)", "·%1·")
end
word = gsub(word, "(" .. consonants .. vowels .. "+" .. consonants .. "?)", "·%1·")
word = gsub(word, "··", "·"); word = gsub(word, "·$", ""); word = gsub(word, "^·", "")
word = gsub(word, "(" .. consonants .. ")·(" .. vowels .. ")", "·%1%2")
word = gsub(word, "·?(" .. consonants .. ")%1(" .. vowels .. "*)", "%1·%1%2")
word = gsub(word, "·(" .. consonants .. ")$", "%1"); word = gsub(word, "^(" .. consonants .. ")·", "%1")
word = gsub(word, "·(.)·", "%1·")
--word = gsub(word, "·s(" .. voiceless .. ")", "s·%1")
--word = gsub(word, "(" .. consonants .. ")s·(" .. voiceless .. ")", "%1·s%2")
word = gsub(word, "ï(" .. vowels .. ")", "i·%1")
word = gsub(word, "·?d([ʤʣ])", "d·%1"); word = gsub(word, "·tʦ", "t·ʦ")
word = gsub(word, "·?ŋg", "ŋ·g"); word = gsub(word, "··", "·")
end
local syllables = split(word, "·");
if #syllables == 1 then return table.concat(syllables) end -- account for monosyllables
local first_stress = "[âêîôû]"
local second_stress = "[áéíóú]"
local unstressed = "[ăĕ]"
for i, _ in ipairs(syllables) do
if match(word, first_stress) then
if match(syllables[i], first_stress) then
syllables[i] = "ˈ" .. dediacv(syllables[i], c.circ)
end
elseif match(syllables[i], second_stress) then
syllables[i] = "ˌ" .. dediacv(syllables[i], c.acute)
end
if match(word, "a[eu]") or match(word, "ei") then
if match(syllables[i], "a[eu]") or match(syllables[i], "ei") then
syllables[i] = "ˈ" .. syllables[i]
end
end
end
local ret = syllables
if not match(table.concat(ret, "·"), "ˈ") then
ret[#ret-1] = "ˈ" .. ret[#ret-1]
end
return table.concat(ret, "·")
end
function export.crux(term, outputs)
term = mw.ustring.lower(term)
for _, rule in ipairs(first_rules) do
term = gsub(term, rule[1], rule[2])
end
term = syllabify(term)
term = term:gsub("·([ˈˌ])", "%1")
term = term:gsub("ˌˌ", "ˌ")
local phonemic = term
for _, rule in ipairs(phonemic_rules) do
phonemic = gsub(phonemic, rule[1], rule[2])
end
local phonetic = phonemic
--[[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])
end
if outputs == "phonemic" then
return phonemic
elseif not outputs or outputs == "phonetic" then
return phonetic
elseif outputs == "test" then
return "/" .. phonemic .. "/ [" .. phonetic .. "]"
end
return phonetic
end
function separate_word(term)
local result = {}
for word in gsplit(term, " ") do
table.insert(result, export.crux(word))
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 "aggiu" or mw.title.getCurrentTitle().text },
}
local args = require("Module:parameters").process(parent_args, params)
local term = args[1]
local IPA_args = {}
local phonetic = separate_word(term)
table.insert(IPA_args, {pron = '[' .. phonetic .. ']'})
return "* " .. m_IPA.format_IPA_full({lang = lang, items = IPA_args})
end
return export