Module:zm-pron: Difference between revisions
Jump to navigation
Jump to search
Aleisi Galan (talk | contribs) No edit summary |
Aleisi Galan (talk | contribs) No edit summary |
||
(85 intermediate revisions by 2 users 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 | ||
-- To avoid weird annoying cursor behavior | -- To avoid weird annoying cursor behavior | ||
local GRAVE = u(0x0300) -- COMBINING GRAVE ACCENT ̀◌ | local GRAVE = u(0x0300) -- COMBINING GRAVE ACCENT ̀◌ | ||
local | local ACUTE = u(0x0301) -- COMBINING ACUTE ACCENT | ||
local SYLL = u(0x0329) -- COMBINING VERTICAL LINE BELOW ̩◌ | |||
local | local VL = u(0x0325) -- COMBINING RING BELOW ̥◌ | ||
local | |||
local AFFR = u(0x0361) -- COMBINING DOUBLE INVERTED BREVE ͡ | local AFFR = u(0x0361) -- COMBINING DOUBLE INVERTED BREVE ͡ | ||
local back_vowel = " | local back_vowel = "aouɔǫō" | ||
local front_vowel = " | local front_vowel = "ieɛɪ" | ||
local | local vowels = "[" .. back_vowel .. front_vowel .. "]" | ||
local | local acuted = "[áéíóúýÉÓ]" | ||
local oral = "áéíóúýÉÓaouɔieɛ" | |||
local palatal = "[ʨjʎʃʒʥʤʧʦʣɕʑ]" | |||
local oral = " | |||
local palatal = "[ | |||
local sonorant = "[rl]" | local sonorant = "[rl]" | ||
local | local plosives = "[ptkbdg]" | ||
local | local velar = "[ɡkx]" | ||
local consonants = "[mnptkbdɡfvszxrljɲŋʋʎʨjʎʃʒʥʤʧʤʣʦɕʑ]" | |||
local | |||
local export = {} | local export = {} | ||
local rules = { | local rules = { | ||
{" | {"ai", "ɛ"}, {"aí", "É"}, {"au", "ɔ"}, {"aú", "Ó"}, {"è", "ɛ"}, {"ò", "ɔ"}, {"y", "ɪ"}, | ||
{"dź", "ʥ"}, {"dž", "ʤ"}, {"c", "ʦ"}, {"ć", "ʨ"}, {"nj", "ɲ"}, {"č", "ʧ"}, {"ž", "ʒ"}, {"š", "ʃ"}, {"lj", "ʎ"}, | |||
{"h", "x"}, {"g", "ɡ"}, {"ǫ", "o"}, {"ō", "o"}, {"sč", "ʃt͡ʃ"}, {"ou", "u"}, {"ś", "ɕ"}, {"ź", "ʑ"}, | |||
{" | |||
{"( | {"(" .. vowels .. ")[lv]$", "%1ʋ"}, {"(" .. acuted .. ")[lv]$", "%1ʋ"}, | ||
{"( | {"(" .. plosives .. ")[ptkbdg]$", "[ptkbdg]"}, | ||
{" | {"pt" , "t"}, {"pk" , "k"}, {"tp" , "p"}, {"tk" , "k"}, {"kp" , "p"}, {"kt" , "t"}, | ||
{"bd" , "d"}, {"bg" , "g"}, {"db" , "b"}, {"dg" , "g"}, {"gb" , "b"}, {"gd" , "d"}, | |||
{"(" .. consonants ..")([rŕ])(" .. consonants ..")", "%1ə%2" .. SYLL .. "%3"}, {"(" .. consonants ..")r$", "%1ər"}, | |||
{"n(" .. velar .. ")", "ŋ%1"}, | |||
{"p(" .. vowels .. ")", "pʰ%1"}, {"t(" .. vowels .. ")", "tʰ%1"}, {"k(" .. vowels .. ")", "kʰ%1"}, | |||
{"p(" .. acuted .. ")", "pʰ%1"}, {"t(" .. acuted .. ")", "tʰ%1"}, {"k(" .. acuted .. ")", "kʰ%1"}, | |||
{"(" .. palatal .. ")e", "%1ɛ"}, {"(" .. palatal .. ")é", "%1É"}, | |||
{"(" .. palatal .. ")o", "%1ɔ"}, {"(" .. palatal .. ")ó", "%1Ó"}, | |||
{"É", "ɛ" .. ACUTE}, {"Ó", "ɔ" .. ACUTE}, {"ý", "ɪ" .. ACUTE}, | |||
} | |||
local affricates = { | |||
{"ʥ", "d͡ʑ"}, {"ʤ", "d͡ʒ"}, {"ʦ", "t͡s"}, {"ʨ", "t͡ɕ"}, {"ʧ", "t͡ʃ"}, {"ʣ", "d͡z"}, | |||
} | } | ||
function export.crux(term | function export.crux(term, d) | ||
term = mw.ustring.lower(term) | term = mw.ustring.lower(term) | ||
for _, rule in ipairs(rules) do | for _, rule in ipairs(rules) do | ||
term = gsub(term, rule[1], rule[2]) | term = gsub(term, rule[1], rule[2]) | ||
end | |||
if d == "c" then term = gsub(term, "ʨ", "ʧ"); term = gsub(term, "ʥ", "ʤ") end | |||
if d == "s" then term = gsub(term, "ʨ", "ʦ"); term = gsub(term, "ʥ", "ʣ"); term = gsub(term, "ʰ", "") end | |||
if d == "s" then term = gsub(term, "aj", "ɛː"); term =gsub(term, "ej", "ɛː") end | |||
if d == "c" then term = gsub(term, "aj", "ɛː"); term =gsub(term, "ej", "ɛː") end | |||
if d == "c" then term = gsub(term, "a", "ɐ"); term = gsub(term, "e", "ɪ"); term = gsub(term, "i", "ɪ"); term = gsub(term, "o", "ɔ"); term = gsub(term, "u", "ʊ") end | |||
if d == "s" then term = gsub(term, "a", "ɐ"); term = gsub(term, "e", "ɛ"); term = gsub(term, "i", "e"); term = gsub(term, "o", "ɔ"); term = gsub(term, "u", "o"); term = gsub(term, "ɪ", "i"); term = gsub(term, "ɪ́", "í"); term = gsub(term, "ų", "u") end | |||
if d == "n" then term = gsub(term, "a", "ə"); term = gsub(term, "e", "ə"); term = gsub(term, "i", "y"); term = gsub(term, "o", "ɔ"); term = gsub(term, "u", "ʊ"); term = gsub(term, "ɪ", "ɨ"); term = gsub(term, "ɪ́", "ɨ́"); term = gsub(term, "y", "ɪ") end | |||
for _, aff in ipairs(affricates) do | |||
term = gsub(term, aff[1], aff[2]) | |||
end | end | ||
return term | return term | ||
end | end | ||
function IPA_span(items) | function IPA_span(items) | ||
Line 117: | Line 90: | ||
function format_IPA(items) | function format_IPA(items) | ||
return "[[w:IPA chart|IPA]]<sup>([[IPA for | return "[[w:IPA chart|IPA]]<sup>([[IPA for Zemljask|key]])</sup>: " .. IPA_span(items) | ||
end | end | ||
function line_format(pronunciation) | function line_format(pronunciation, dialect) | ||
local full_pronunciations = {} | local full_pronunciations = {} | ||
local IPA_args = {{pron = '[' .. pronunciation .. ']'}} | local IPA_args = {{pron = '[' .. pronunciation .. ']'}} | ||
table.insert(full_pronunciations, format_IPA(IPA_args)) | table.insert(full_pronunciations, format_IPA(IPA_args)) | ||
return table.concat(full_pronunciations) | return "(''" .. table.concat(dialect, ", ") .. "'')" .. ' ' .. table.concat(full_pronunciations, ' or ') | ||
end | end | ||
function separate_word(term) | function separate_word(term, d) | ||
local result = {} | local result = {} | ||
for word in gsplit(term, " ") do | for word in gsplit(term, " ") do | ||
table.insert(result, export.crux(word)) | table.insert(result, export.crux(word, d)) | ||
end | end | ||
Line 139: | Line 112: | ||
function export.show(frame) | function export.show(frame) | ||
local params = { | local params = { | ||
[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and " | [1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "dźélo" or mw.title.getCurrentTitle().text }, | ||
} | } | ||
local args = require("Module:parameters").process(frame:getParent().args, params) | local args = require("Module:parameters").process(frame:getParent().args, params) | ||
Line 145: | Line 118: | ||
local ipa = "* " | local ipa = "* " | ||
ipa = ipa .. line_format(separate_word(term)) | ipa = ipa .. line_format(separate_word(term), {'Standard'}) | ||
if export.crux(term, "c") ~= export.crux(term) then | |||
ipa = ipa .. "\n* " | |||
ipa = ipa .. line_format(separate_word(term, "n"), {'Northern'}) | |||
end | |||
if export.crux(term, "s") ~= export.crux(term) then | |||
ipa = ipa .. "\n* " | |||
ipa = ipa .. line_format(separate_word(term, "c"), {'Central'}) | |||
end | |||
if export.crux(term, "n") ~= export.crux(term) then | |||
ipa = ipa .. "\n* " | |||
ipa = ipa .. line_format(separate_word(term, "s"), {'Southern'}) | |||
end | |||
return ipa | return ipa |
Latest revision as of 02:48, 20 July 2022
- The following documentation is located at Module:zm-pron/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local sub = mw.ustring.sub
local find = mw.ustring.find
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit
-- To avoid weird annoying cursor behavior
local GRAVE = u(0x0300) -- COMBINING GRAVE ACCENT ̀◌
local ACUTE = u(0x0301) -- COMBINING ACUTE ACCENT
local SYLL = u(0x0329) -- COMBINING VERTICAL LINE BELOW ̩◌
local VL = u(0x0325) -- COMBINING RING BELOW ̥◌
local AFFR = u(0x0361) -- COMBINING DOUBLE INVERTED BREVE ͡
local back_vowel = "aouɔǫō"
local front_vowel = "ieɛɪ"
local vowels = "[" .. back_vowel .. front_vowel .. "]"
local acuted = "[áéíóúýÉÓ]"
local oral = "áéíóúýÉÓaouɔieɛ"
local palatal = "[ʨjʎʃʒʥʤʧʦʣɕʑ]"
local sonorant = "[rl]"
local plosives = "[ptkbdg]"
local velar = "[ɡkx]"
local consonants = "[mnptkbdɡfvszxrljɲŋʋʎʨjʎʃʒʥʤʧʤʣʦɕʑ]"
local export = {}
local rules = {
{"ai", "ɛ"}, {"aí", "É"}, {"au", "ɔ"}, {"aú", "Ó"}, {"è", "ɛ"}, {"ò", "ɔ"}, {"y", "ɪ"},
{"dź", "ʥ"}, {"dž", "ʤ"}, {"c", "ʦ"}, {"ć", "ʨ"}, {"nj", "ɲ"}, {"č", "ʧ"}, {"ž", "ʒ"}, {"š", "ʃ"}, {"lj", "ʎ"},
{"h", "x"}, {"g", "ɡ"}, {"ǫ", "o"}, {"ō", "o"}, {"sč", "ʃt͡ʃ"}, {"ou", "u"}, {"ś", "ɕ"}, {"ź", "ʑ"},
{"(" .. vowels .. ")[lv]$", "%1ʋ"}, {"(" .. acuted .. ")[lv]$", "%1ʋ"},
{"(" .. plosives .. ")[ptkbdg]$", "[ptkbdg]"},
{"pt" , "t"}, {"pk" , "k"}, {"tp" , "p"}, {"tk" , "k"}, {"kp" , "p"}, {"kt" , "t"},
{"bd" , "d"}, {"bg" , "g"}, {"db" , "b"}, {"dg" , "g"}, {"gb" , "b"}, {"gd" , "d"},
{"(" .. consonants ..")([rŕ])(" .. consonants ..")", "%1ə%2" .. SYLL .. "%3"}, {"(" .. consonants ..")r$", "%1ər"},
{"n(" .. velar .. ")", "ŋ%1"},
{"p(" .. vowels .. ")", "pʰ%1"}, {"t(" .. vowels .. ")", "tʰ%1"}, {"k(" .. vowels .. ")", "kʰ%1"},
{"p(" .. acuted .. ")", "pʰ%1"}, {"t(" .. acuted .. ")", "tʰ%1"}, {"k(" .. acuted .. ")", "kʰ%1"},
{"(" .. palatal .. ")e", "%1ɛ"}, {"(" .. palatal .. ")é", "%1É"},
{"(" .. palatal .. ")o", "%1ɔ"}, {"(" .. palatal .. ")ó", "%1Ó"},
{"É", "ɛ" .. ACUTE}, {"Ó", "ɔ" .. ACUTE}, {"ý", "ɪ" .. ACUTE},
}
local affricates = {
{"ʥ", "d͡ʑ"}, {"ʤ", "d͡ʒ"}, {"ʦ", "t͡s"}, {"ʨ", "t͡ɕ"}, {"ʧ", "t͡ʃ"}, {"ʣ", "d͡z"},
}
function export.crux(term, d)
term = mw.ustring.lower(term)
for _, rule in ipairs(rules) do
term = gsub(term, rule[1], rule[2])
end
if d == "c" then term = gsub(term, "ʨ", "ʧ"); term = gsub(term, "ʥ", "ʤ") end
if d == "s" then term = gsub(term, "ʨ", "ʦ"); term = gsub(term, "ʥ", "ʣ"); term = gsub(term, "ʰ", "") end
if d == "s" then term = gsub(term, "aj", "ɛː"); term =gsub(term, "ej", "ɛː") end
if d == "c" then term = gsub(term, "aj", "ɛː"); term =gsub(term, "ej", "ɛː") end
if d == "c" then term = gsub(term, "a", "ɐ"); term = gsub(term, "e", "ɪ"); term = gsub(term, "i", "ɪ"); term = gsub(term, "o", "ɔ"); term = gsub(term, "u", "ʊ") end
if d == "s" then term = gsub(term, "a", "ɐ"); term = gsub(term, "e", "ɛ"); term = gsub(term, "i", "e"); term = gsub(term, "o", "ɔ"); term = gsub(term, "u", "o"); term = gsub(term, "ɪ", "i"); term = gsub(term, "ɪ́", "í"); term = gsub(term, "ų", "u") end
if d == "n" then term = gsub(term, "a", "ə"); term = gsub(term, "e", "ə"); term = gsub(term, "i", "y"); term = gsub(term, "o", "ɔ"); term = gsub(term, "u", "ʊ"); term = gsub(term, "ɪ", "ɨ"); term = gsub(term, "ɪ́", "ɨ́"); term = gsub(term, "y", "ɪ") end
for _, aff in ipairs(affricates) do
term = gsub(term, aff[1], aff[2])
end
return term
end
function IPA_span(items)
local bits = {}
for _, item in ipairs(items) do
local bit = "<span style=\"font-size:110%;font-family:'Gentium','DejaVu Sans','Segoe UI',sans-serif>" .. item.pron .. "</span>"
table.insert(bits, bit)
end
return table.concat(bits)
end
function format_IPA(items)
return "[[w:IPA chart|IPA]]<sup>([[IPA for Zemljask|key]])</sup>: " .. IPA_span(items)
end
function line_format(pronunciation, dialect)
local full_pronunciations = {}
local IPA_args = {{pron = '[' .. pronunciation .. ']'}}
table.insert(full_pronunciations, format_IPA(IPA_args))
return "(''" .. table.concat(dialect, ", ") .. "'')" .. ' ' .. table.concat(full_pronunciations, ' or ')
end
function separate_word(term, d)
local result = {}
for word in gsplit(term, " ") do
table.insert(result, export.crux(word, d))
end
return table.concat(result, " ")
end
function export.show(frame)
local params = {
[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "dźélo" or mw.title.getCurrentTitle().text },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local term = args[1]
local ipa = "* "
ipa = ipa .. line_format(separate_word(term), {'Standard'})
if export.crux(term, "c") ~= export.crux(term) then
ipa = ipa .. "\n* "
ipa = ipa .. line_format(separate_word(term, "n"), {'Northern'})
end
if export.crux(term, "s") ~= export.crux(term) then
ipa = ipa .. "\n* "
ipa = ipa .. line_format(separate_word(term, "c"), {'Central'})
end
if export.crux(term, "n") ~= export.crux(term) then
ipa = ipa .. "\n* "
ipa = ipa .. line_format(separate_word(term, "s"), {'Southern'})
end
return ipa
end
return export