Module:xchc-pron: Difference between revisions
No edit summary |
No edit summary |
||
| (13 intermediate revisions by the same user not shown) | |||
| Line 7: | Line 7: | ||
local split = mw.text.split | local split = mw.text.split | ||
local gsplit = mw.text.gsplit | local gsplit = mw.text.gsplit | ||
local lang = require("Module:languages").getByCode("xchc") | local lang = require("Module:languages").getByCode("xchc") | ||
local c = require("Module:languages/data").chars | |||
local m_IPA = require("Module:IPA") | local m_IPA = require("Module:IPA") | ||
local M = c.macron | |||
local B = c.breve | |||
local D = c.diaer | |||
local nb_cons = "mnŋɲptbdkɡfvszʃʒxɣhʧʦʤʣlrɾʎ" | local nb_cons = "mnŋɲptbdkɡfvszʃʒxɣhʧʦʤʣlrɾʎ" | ||
local consonants = "[" .. nb_cons .. "]" | local consonants = "[" .. nb_cons .. "]" | ||
local consonantsAsIs = "[мньӈбдгвзжғлрйпткфсшӀчц]" | |||
local vowels = "[ыиэеаяүөуюоёӯӣɜɔ]" | |||
local export = {} | local export = {} | ||
local first_rules = { | local first_rules = { | ||
| Line 77: | Line 63: | ||
{"l[ьі]", "ʎ"}, {"n[ьі]", "ɲ"}, {"[ьі]", "j"}, | {"l[ьі]", "ʎ"}, {"n[ьі]", "ɲ"}, {"[ьі]", "j"}, | ||
{"(" .. consonants .. ") | {"(" .. consonants .. ")%1", "%1ː"}, | ||
{"r$", "ɾ"}, {"([ŋkɡxɣh])a", "%1ɑ"}, {"a(ː?[ŋkɡxɣh])", "ɑ%1"} | {"r$", "ɾ"}, {"([ŋkɡxɣh])a", "%1ɑ"}, {"a(ː?[ŋkɡxɣh])", "ɑ%1"} | ||
} | } | ||
| Line 107: | Line 93: | ||
{"(" .. consonants .. ")([iyeø])", "%1ʲ%2"}, | {"(" .. consonants .. ")([iyeø])", "%1ʲ%2"}, | ||
} | } | ||
-- Remove diacritics for module calculations based on vowels | |||
function export.simplify(term) | |||
term = mw.ustring.toNFD(term):gsub(c.macron, "") -- vowel length | |||
term = term:gsub("э" .. c.breve, "ɛ"); term = term:gsub("о" .. c.breve, "ɔ") | |||
term = mw.ustring.toNFC(term):gsub("ё", "о"); term = term:gsub("е" .. c.diaer, "о") | |||
return term | |||
end | |||
function export.crux(term) | function export.crux(term) | ||
for _, rule in ipairs(first_rules) do | for _, rule in ipairs(first_rules) do | ||
term = gsub(term, rule[1], rule[2]) | term = gsub(term, rule[1], rule[2]) | ||
| Line 123: | Line 116: | ||
function export.harmony(term) | function export.harmony(term) | ||
term = export.simplify(term) | |||
local termR, termB = term, term | |||
local unrounded = "[ыиӣеэ]"; local rounded = "[үөуӯюоё]"; local neutralR = "[ɛɔая]" | |||
local front = "ɛ"; local back = "ɔ"; local neutralB = "[ыиӣеэүөуӯюоёая]" | |||
-- for words that violate vowel harmony (compounds and loanwords) | |||
local exception = (term:match(unrounded) and term:match(rounded)) or (term:match(front) and term:match(back)) | |||
if exception then | |||
termR = term:gsub(neutralR, ""); termB = term:gsub(neutralB, "") | |||
termR = termR:match("(".. vowels .. consonantsAsIs .. "*)$") or termR; termB = termB:match("(" .. vowels .. consonants .. "*)$") or termB | |||
end | |||
local ret = { | local ret = { | ||
["roundness"] = | ["roundness"] = termR:match(unrounded) and "u" or termR:match(rounded) and "r" or "ar", | ||
["backness"] = | ["backness"] = termB:match(front) and "f" or termB:match(back) and "b" or "ab", | ||
} | } | ||
return ret | return ret | ||
end | end | ||
function separate_word(term) | function separate_word(term) | ||
| Line 135: | Line 141: | ||
for word in gsplit(term, " ") do | for word in gsplit(term, " ") do | ||
local ipa = export.crux( | local ipa = export.crux(word) | ||
if export.harmony( | if export.harmony(word).backness == "b" then ipa = ipa:gsub("a", "ɑ") end | ||
if export.harmony( | if export.harmony(word).roundness == "r" then ipa = ipa:gsub("ɛ", "œ") end | ||
if export.harmony( | if export.harmony(word).roundness == "u" then ipa = ipa:gsub("ɔ", "ʌ") end | ||
table.insert(result, ipa) | table.insert(result, ipa) | ||
| Line 153: | Line 159: | ||
} | } | ||
local args = require("Module:parameters").process(parent_args, params) | local args = require("Module:parameters").process(parent_args, params) | ||
local term = args[1] | local term = mw.ustring.lower(mw.ustring.toNFD(args[1])) | ||
local IPA_args = {} | local IPA_args = {} | ||
local phonetic = separate_word(term) | local phonetic = separate_word(term) | ||
| Line 162: | Line 169: | ||
western = gsub(western, rule[1], rule[2]) | western = gsub(western, rule[1], rule[2]) | ||
end | end | ||
local ipa1 = (western ~= phonetic) and "\n** " .. m_IPA.format_IPA_multiple({{pron='[' .. western .. ']', q="Western"}}) or "" | local ipa1 = (western ~= phonetic) and "\n** " .. m_IPA.format_IPA_multiple(lang, {{pron='[' .. western .. ']', q={"Western"}}}) or "" | ||
local surgut = phonetic | local surgut = phonetic | ||
| Line 168: | Line 175: | ||
surgut = gsub(surgut, rule[1], rule[2]) | surgut = gsub(surgut, rule[1], rule[2]) | ||
end | end | ||
local ipa2 = (surgut ~= phonetic) and "\n** " .. m_IPA.format_IPA_multiple(lang,{{pron='[' .. surgut .. ']', q="Surgut"}}) or "" | local ipa2 = (surgut ~= phonetic) and "\n** " .. m_IPA.format_IPA_multiple(lang, {{pron='[' .. surgut .. ']', q={"Surgut"}}}) or "" | ||
return "* " .. m_IPA.format_IPA_full | return "* " .. m_IPA.format_IPA_full{lang = lang, items = {{pron='[' .. phonetic .. ']'}}} .. ipa1 .. ipa2 | ||
end | end | ||
return export | return export | ||