Module:qay-pron: Difference between revisions
No edit summary |
No edit summary |
||
| Line 14: | Line 14: | ||
local export = {} | local export = {} | ||
local consonants = "[ | local consonants = "[pbmvstdnrɾljkɡŋhxçʤʧ]" | ||
local front = "ie" | local front = "ie" | ||
local back = "ou" | local back = "ou" | ||
local vowels = "[a" .. front .. back .. "]" | local vowels = "[a" .. front .. back .. "ː]" | ||
local function open_to_closed(v) | local function open_to_closed(v) | ||
| Line 32: | Line 29: | ||
return table.concat(otc) | return table.concat(otc) | ||
end | 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 shared_rules = { | |||
{"n[kg]", {["nk"] = "ŋk", ["ng"] = "ŋ"}}, {"c", "ʧ"}, {"j", "ʤ"}, {"y", "j"}, {"g", "ɡ"}, | |||
-- Long vowels | |||
{"ā", "aː"}, {"ē", "eː"}, {"ī", "iː"}, {"ō", "oː"}, {"ū", "uː"}, | |||
} | |||
local phonemic_rules = { | local phonemic_rules = { | ||
{"([tkdɡ])j", "%1ʲ"}, {"(" .. consonants .. consonants .. ")", function(c1, c2) return same(c1,c2) and c1 or c1 .. c2 end}, | |||
} | } | ||
local phonetic_rules = { | local phonetic_rules = { | ||
{"([^nŋ])[tk]j", "%1ʧ"}, {"([^nŋ])[dɡ]j", "%1ʤ"}, {"r", "ɾ"}, | |||
{"h([" .. front .. "])", "ç%1"}, {"h([" .. back .. "])", "x%1"}, | |||
--{"(" consonants .. vowel)", ""}, | |||
} | } | ||
local function | local function syllabify(term, pos) | ||
term = gsub(term, "(" .. consonants .. "*)(" .. vowels .. "*)", "%1%2·") | |||
term = gsub(term, "··", "·"); term = gsub(term, "·$", "") | |||
term = gsub(term, "·(" .. consonants .. ")(" .. consonants .. ")(" .. vowels .. "*)", "%1·%2%3") | |||
term = gsub(term, " | |||
term = gsub(term, "·(" .. consonants .. ") | |||
term = gsub(term, "·(" .. consonants .. ")$", "%1") | term = gsub(term, "·(" .. consonants .. ")$", "%1") | ||
term = gsub(term, "·(" .. consonants .. ") | term = gsub(term, "·(" .. consonants .. ")·", "%1·") | ||
local | local syll = split(term, "·"); local noa = {} | ||
local monosyll = {["n"] = "ˈ", ["pron"] = "", ["particle"] = "(ˈ)", ["prep"] = "(ˈ)", ["conj"] = "(ˈ)"} | |||
if # | if #syll ~= 1 then | ||
if match(term, "[áéíóúĄ]") then | |||
for _, s in ipairs(syll) do | |||
s = remove_acute(s, match(s, "[áéíóúĄ]") and true or false) | |||
table.insert(noa, s) | |||
end | |||
else | |||
syll[#syll - 1] = "ˈ" .. syll[#syll - 1] | |||
end | end | ||
end | end | ||
return table.concat(#noa > 1 and noa or syll, "·") | |||
end | end | ||
function export.phonemic(term) | function export.phonemic(term) | ||
term = mw.ustring.lower(term) | term = mw.ustring.lower(term) | ||
for _, rule in ipairs(shared_rules) do | |||
term = gsub(term, rule[1], rule[2]) | |||
end | |||
for _, micrule in ipairs(phonemic_rules) do | for _, micrule in ipairs(phonemic_rules) do | ||
| Line 93: | Line 97: | ||
function export.phonetic(term) | function export.phonetic(term) | ||
term = mw.ustring.lower(term) | term = mw.ustring.lower(term) | ||
for _, rule in ipairs(shared_rules) do | |||
term = gsub(term, rule[1], rule[2]) | |||
end | |||
for _, ticrule in ipairs(phonetic_rules) do | for _, ticrule in ipairs(phonetic_rules) do | ||
term = gsub(term, ticrule[1], ticrule[2]) | term = gsub(term, ticrule[1], ticrule[2]) | ||
end | end | ||
term = gsub(term, "a", "ä") | |||
return write_stress(term) | return write_stress(term) | ||