Module:xchc-pron: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(15 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
local m_IPA = require("Module:IPA") | local m_IPA = require("Module:IPA") | ||
local consonants = "[ | local nb_cons = "mnŋɲptbdkɡfvszʃʒxɣhʧʦʤʣlrɾʎ" | ||
local consonants = "[" .. nb_cons .. "]" | |||
local export = {} | local export = {} | ||
Line 37: | Line 38: | ||
local first_rules = { | local first_rules = { | ||
{M, "ː"}, {"ː([" .. M .. D .. B .. "])", "%1ː"}, | {"%-", ""}, {M, "ː"}, {"ː([" .. M .. D .. B .. "])", "%1ː"}, | ||
{"е" .. D, "ьo"}, {"о" .. B, "ɔ"}, {"э" .. B, "ɛ"}, | {"е" .. D, "ьo"}, {"о" .. B, "ɔ"}, {"э" .. B, "ɛ"}, {"и" .. B, "j"}, | ||
{"а", "a"}, | {"а", "a"}, | ||
Line 65: | Line 66: | ||
{"ү", "y"}, | {"ү", "y"}, | ||
{"ф", "f"}, | {"ф", "f"}, | ||
{" | {"[хx]ӏ", "h"}, {"х", "x"}, | ||
{"ц", "ʦ"}, | {"ц", "ʦ"}, | ||
{"ч", "ʧ"}, | {"ч", "ʧ"}, | ||
Line 76: | Line 77: | ||
{"l[ьі]", "ʎ"}, {"n[ьі]", "ɲ"}, {"[ьі]", "j"}, | {"l[ьі]", "ʎ"}, {"n[ьі]", "ɲ"}, {"[ьі]", "j"}, | ||
{"(" .. consonants .. ")(" .. consonants .. ")", function(c1,c2) return same(c1, c2) and c1 .. "ː" or c1 .. c2 end} | {"(" .. consonants .. ")(" .. consonants .. ")", function(c1,c2) return same(c1, c2) and c1 .. "ː" or c1 .. c2 end}, | ||
{"r$", "ɾ"}, {"([ŋkɡxɣh])a", "%1ɑ"}, {"a(ː?[ŋkɡxɣh])", "ɑ%1"} | |||
} | } | ||
Line 84: | Line 86: | ||
{"ʦ", "t͡s"}, | {"ʦ", "t͡s"}, | ||
{"ʧ", "t͡ʃ"}, | {"ʧ", "t͡ʃ"}, | ||
} | |||
local wnc = "([iyueøoɛɔœʌ]ː?)" | |||
local western_rules = { | |||
{wnc .. "f$", "%1p̪͡f"}, | |||
{wnc .. "v$", "%1b̪͡v"}, | |||
{wnc .. "s$", "%1t͡s"}, | |||
{wnc .. "z$", "%1d͡z"}, | |||
{wnc .. "ʃ$", "%1t͡ʃ"}, | |||
{wnc .. "ʒ$", "%1d͡ʒ"}, | |||
{wnc .. "x$", "%1k͡x"}, | |||
{wnc .. "ɣ$", "%1ɡ͡ɣ"}, | |||
{wnc .. "h$", "%1ʔ͡h"}, | |||
{wnc .. "p$", "%1ɸ"}, {wnc .. "b$", "%1β"}, {wnc .. "t$", "%1s"}, | |||
{wnc .. "d$", "%1z"}, {wnc .. "k$", "%1x"}, {wnc .. "ɡ$", "%1ɣ"}, | |||
} | |||
local surgut_rules = { | |||
{"ɲ", "nʲ"}, {"ʎ", "lʲ"}, | |||
{"(" .. consonants .. ")([iyeø])", "%1ʲ%2"}, | |||
} | } | ||
Line 98: | Line 120: | ||
return term | return term | ||
end | |||
function export.harmony(term) | |||
local ipa = export.crux(term) | |||
local ret = { | |||
["roundness"] = ipa:match("[yuøo]") and "r" or ipa:match("[ie]") and "u" or "ar", | |||
["backness"] = ipa:match("ɜ") and "f" or ipa:match("ɔ") and "b" or "ab", | |||
} | |||
return ret | |||
end | end | ||
Line 104: | Line 135: | ||
for word in gsplit(term, " ") do | for word in gsplit(term, " ") do | ||
local ipa = export.crux(term) | |||
if export.harmony(ipa).backness == "b" then ipa = ipa:gsub("a", "ɑ") end | |||
if export.harmony(ipa).roundness == "r" then ipa = ipa:gsub("ɛ", "œ") end | |||
if export.harmony(ipa).roundness == "u" then ipa = ipa:gsub("ɔ", "ʌ") end | |||
table.insert(result, ipa) | |||
end | end | ||
Line 120: | Line 157: | ||
local IPA_args = {} | local IPA_args = {} | ||
local phonetic = separate_word(term) | local phonetic = separate_word(term) | ||
local western = phonetic | |||
for _, rule in ipairs(western_rules) do | |||
western = gsub(western, rule[1], rule[2]) | |||
end | |||
local ipa1 = (western ~= phonetic) and "\n** " .. m_IPA.format_IPA_multiple(lang, {{pron='[' .. western .. ']', q={"Western"}}}) or "" | |||
local surgut = phonetic | |||
for _, rule in ipairs(surgut_rules) do | |||
surgut = gsub(surgut, rule[1], rule[2]) | |||
end | |||
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 |
Latest revision as of 14:47, 7 August 2024
- The following documentation is located at Module:xchc-pron/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
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 M = u(0x0304) -- COMBINING MACRON
local B = u(0x0306) -- COMBINING BREVE
local D = u(0x0308) -- COMBINING DIAERESIS
local lang = require("Module:languages").getByCode("xchc")
local m_IPA = require("Module:IPA")
local nb_cons = "mnŋɲptbdkɡfvszʃʒxɣhʧʦʤʣlrɾʎ"
local consonants = "[" .. nb_cons .. "]"
local export = {}
local function laxen(v)
local otc = {}
local switch = {["e"] = "ɛ", ["i"] = "ɪ", ["o"] = "ɔ", ["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 = {
{"%-", ""}, {M, "ː"}, {"ː([" .. M .. D .. B .. "])", "%1ː"},
{"е" .. D, "ьo"}, {"о" .. B, "ɔ"}, {"э" .. B, "ɛ"}, {"и" .. B, "j"},
{"а", "a"},
{"б", "b"},
{"в", "v"},
{"г", "ɡ"},
{"ғ", "ɣ"},
{"дз", "ʣ"}, {"дж", "ʤ"}, {"д", "d"},
{"е", "ьe"},
{"ж", "ʒ"},
{"з", "z"},
{"и", "ьi"},
{"к", "k"},
{"л", "l"},
{"м", "m"},
{"н", "n"},
{"ӈ", "ŋ"},
{"о", "o"},
{"ө", "ø"},
{"п", "p"},
{"р", "r"},
{"т", "t"},
{"с", "s"},
{"у", "u"},
{"ү", "y"},
{"ф", "f"},
{"[хx]ӏ", "h"}, {"х", "x"},
{"ц", "ʦ"},
{"ч", "ʧ"},
{"ш", "ʃ"},
{"ы", "i"},
{"э", "e"},
{"ю", "ьu"},
{"я", "ьa"},
{"l[ьі]", "ʎ"}, {"n[ьі]", "ɲ"}, {"[ьі]", "j"},
{"(" .. consonants .. ")(" .. consonants .. ")", function(c1,c2) return same(c1, c2) and c1 .. "ː" or c1 .. c2 end},
{"r$", "ɾ"}, {"([ŋkɡxɣh])a", "%1ɑ"}, {"a(ː?[ŋkɡxɣh])", "ɑ%1"}
}
local last_rules = {
{"ʣ", "d͡z"},
{"ʤ", "d͡ʒ"},
{"ʦ", "t͡s"},
{"ʧ", "t͡ʃ"},
}
local wnc = "([iyueøoɛɔœʌ]ː?)"
local western_rules = {
{wnc .. "f$", "%1p̪͡f"},
{wnc .. "v$", "%1b̪͡v"},
{wnc .. "s$", "%1t͡s"},
{wnc .. "z$", "%1d͡z"},
{wnc .. "ʃ$", "%1t͡ʃ"},
{wnc .. "ʒ$", "%1d͡ʒ"},
{wnc .. "x$", "%1k͡x"},
{wnc .. "ɣ$", "%1ɡ͡ɣ"},
{wnc .. "h$", "%1ʔ͡h"},
{wnc .. "p$", "%1ɸ"}, {wnc .. "b$", "%1β"}, {wnc .. "t$", "%1s"},
{wnc .. "d$", "%1z"}, {wnc .. "k$", "%1x"}, {wnc .. "ɡ$", "%1ɣ"},
}
local surgut_rules = {
{"ɲ", "nʲ"}, {"ʎ", "lʲ"},
{"(" .. consonants .. ")([iyeø])", "%1ʲ%2"},
}
function export.crux(term)
term = mw.ustring.lower(mw.ustring.toNFD(term))
for _, rule in ipairs(first_rules) do
term = gsub(term, rule[1], rule[2])
end
for _, rule in ipairs(last_rules) do
term = gsub(term, rule[1], rule[2])
end
return term
end
function export.harmony(term)
local ipa = export.crux(term)
local ret = {
["roundness"] = ipa:match("[yuøo]") and "r" or ipa:match("[ie]") and "u" or "ar",
["backness"] = ipa:match("ɜ") and "f" or ipa:match("ɔ") and "b" or "ab",
}
return ret
end
function separate_word(term)
local result = {}
for word in gsplit(term, " ") do
local ipa = export.crux(term)
if export.harmony(ipa).backness == "b" then ipa = ipa:gsub("a", "ɑ") end
if export.harmony(ipa).roundness == "r" then ipa = ipa:gsub("ɛ", "œ") end
if export.harmony(ipa).roundness == "u" then ipa = ipa:gsub("ɔ", "ʌ") end
table.insert(result, ipa)
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 "чы̄ӈымэ̆ц" 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)
local western = phonetic
for _, rule in ipairs(western_rules) do
western = gsub(western, rule[1], rule[2])
end
local ipa1 = (western ~= phonetic) and "\n** " .. m_IPA.format_IPA_multiple(lang, {{pron='[' .. western .. ']', q={"Western"}}}) or ""
local surgut = phonetic
for _, rule in ipairs(surgut_rules) do
surgut = gsub(surgut, rule[1], rule[2])
end
local ipa2 = (surgut ~= phonetic) and "\n** " .. m_IPA.format_IPA_multiple(lang, {{pron='[' .. surgut .. ']', q={"Surgut"}}}) or ""
return "* " .. m_IPA.format_IPA_full{lang = lang, items = {{pron='[' .. phonetic .. ']'}}} .. ipa1 .. ipa2
end
return export