Módulo:generar-pron/sh
La documentación para este módulo puede ser creada en Módulo:generar-pron/sh/doc
-- Basado en la versión de en.wikt
local export = {}
local m_str = require("Módulo:String")
local strlower = m_str.lower
local strsubn = m_str.gsub
local strsubrep = m_str.gsub_rep
local strstrip = m_str.strip
local strhtml = m_str.encode_html
local PUNTUACION = "[%(%)%[%]%{%}¡!¿?.,;:–—]"
local PUNTUACION_EXTRA = "[%(%)%[%]%{%}¡!¿?.,;:–—\"“”„‟‘’«»»«‹››‹'´]"
-- single characters that map to IPA sounds
local phonetic_chars_map = {
["a"] = "a", ["а"] = "a",
["e"] = "e", ["е"] = "e",
["i"] = "i", ["и"] = "i",
["o"] = "o", ["о"] = "o",
["u"] = "u", ["у"] = "u",
["b"] = "b", ["б"] = "b",
["v"] = "ʋ", ["в"] = "ʋ",
["g"] = "ɡ", ["г"] = "ɡ",
["d"] = "d", ["д"] = "d",
["đ"] = "d͡ʑ", ["ђ"] = "d͡ʑ",
["ž"] = "ʒ", ["ж"] = "ʒ",
["z"] = "z", ["з"] = "z",
["j"] = "j", ["ј"] = "j",
["k"] = "k", ["к"] = "k",
["l"] = "l", ["л"] = "l",
["љ"] = "ʎ",
["m"] = "m", ["м"] = "m",
["n"] = "n", ["н"] = "n",
["њ"] = "ɲ",
["p"] = "p", ["п"] = "p",
["r"] = "r", ["р"] = "r",
["s"] = "s", ["с"] = "s",
["t"] = "t", ["т"] = "t",
["ć"] = "t͡ɕ", ["ћ"] = "t͡ɕ",
["f"] = "f", ["ф"] = "f",
["h"] = "x", ["х"] = "x",
["c"] = "t͡s", ["ц"] = "t͡s",
["č"] = "t͡ʃ", ["ч"] = "t͡ʃ",
["џ"] = "d͡ʒ",
["š"] = "ʃ", ["ш"] = "ʃ",
["ś"] = "ɕ",
["ź"] = "ʑ",
["ă"] = "ə", ["ь"] = "ə",
["ѕ"] = "dz",
["."] = "",
["¯"] = "ː",
["`"] = "ˇ",
["á"] = "ǎː", ["à"] = "ǎ", ["ā"] = "aː", ["ȁ"] = "â", ["ȃ"] = "âː",
["é"] = "ěː", ["è"] = "ě", ["ē"] = "eː", ["ȅ"] = "ê", ["ȇ"] = "êː",
["í"] = "ǐː", ["ì"] = "ǐ", ["ī"] = "iː", ["ȉ"] = "î", ["ȋ"] = "îː",
["ó"] = "ǒː", ["ò"] = "ǒ", ["ō"] = "oː", ["ȍ"] = "ô", ["ȏ"] = "ôː",
["ú"] = "ǔː", ["ù"] = "ǔ", ["ū"] = "uː", ["ȕ"] = "û", ["ȗ"] = "ûː",
["ŕ"] = "ř̩ː", ["ȑ"] = "r̩̂", ["ȓ"] = "r̩̂ː",
["̏"] = "ˆ",
["̑"] = "ˆː",
}
-- character sequences of two that map to IPA sounds
local phonetic_2chars_map = {
["lj"] = "ʎ",
["nj"] = "ɲ",
["dž"] = "d͡ʒ",
["с́"] = "ɕ",
["з́"] = "ʑ",
["а́"] = "ǎː", ["а̀"] = "ǎ", ["а̄"] = "aː", ["а̏"] = "â", ["а̑"] = "âː",
["е́"] = "ěː", ["ѐ"] = "ě", ["е̄"] = "eː", ["е̏"] = "ê", ["е̑"] = "êː",
["и́"] = "ǐː", ["ѝ"] = "ǐ", ["ӣ"] = "iː", ["и̏"] = "î", ["и̑"] = "îː",
["о́"] = "ǒː", ["о̀"] = "ǒ", ["о̄"] = "oː", ["о̏"] = "ô", ["о̑"] = "ôː",
["у́"] = "ǔː", ["у̀"] = "ǔ", ["ӯ"] = "uː", ["у̏"] = "û", ["у̑"] = "ûː",
["r̀"] = "ř̩", ["r̩̄"] = "r̩ː",
["р́"] = "ř̩ː", ["р̀"] = "ř̩", ["р̄"] = "r̩ː", ["р̏"] = "r̩̂", ["р̑"] = "r̩̂ː",
}
local abc = {
["А"] = true,
["а"] = true,
["A"] = true,
["a"] = true,
["Б"] = true,
["б"] = true,
["B"] = true,
["b"] = true,
["В"] = true,
["в"] = true,
["V"] = true,
["v"] = true,
["Г"] = true,
["г"] = true,
["G"] = true,
["g"] = true,
["Д"] = true,
["д"] = true,
["D"] = true,
["d"] = true,
["Ђ"] = true,
["ђ"] = true,
["Đ"] = true,
["đ"] = true,
["Е"] = true,
["е"] = true,
["E"] = true,
["e"] = true,
["Ж"] = true,
["ж"] = true,
["Ž"] = true,
["ž"] = true,
["З"] = true,
["з"] = true,
["Z"] = true,
["z"] = true,
["И"] = true,
["и"] = true,
["I"] = true,
["i"] = true,
["Ј"] = true,
["ј"] = true,
["J"] = true,
["j"] = true,
["К"] = true,
["к"] = true,
["K"] = true,
["k"] = true,
["Л"] = true,
["л"] = true,
["L"] = true,
["l"] = true,
["Љ"] = true,
["љ"] = true,
["Lj"] = true,
["lj"] = true,
["М"] = true,
["м"] = true,
["M"] = true,
["m"] = true,
["Н"] = true,
["н"] = true,
["N"] = true,
["n"] = true,
["Њ"] = true,
["њ"] = true,
["Nj"] = true,
["nj"] = true,
["О"] = true,
["о"] = true,
["O"] = true,
["o"] = true,
["П"] = true,
["п"] = true,
["P"] = true,
["p"] = true,
["Р"] = true,
["р"] = true,
["R"] = true,
["r"] = true,
["С"] = true,
["с"] = true,
["S"] = true,
["s"] = true,
["Т"] = true,
["т"] = true,
["T"] = true,
["t"] = true,
["Ћ"] = true,
["ћ"] = true,
["Ć"] = true,
["ć"] = true,
["У"] = true,
["у"] = true,
["U"] = true,
["u"] = true,
["Ф"] = true,
["ф"] = true,
["F"] = true,
["f"] = true,
["Х"] = true,
["х"] = true,
["H"] = true,
["h"] = true,
["Ц"] = true,
["ц"] = true,
["C"] = true,
["c"] = true,
["Ч"] = true,
["ч"] = true,
["Č"] = true,
["č"] = true,
["Џ"] = true,
["џ"] = true,
["Dž"] = true,
["dž"] = true,
["Ш"] = true,
["ш"] = true,
["Š"] = true,
["š"] = true,
}
local function normalizar(texto)
texto = strlower(texto)
texto = strsubrep(texto, PUNTUACION, " | ") -- convierto lo que delimite fragmentos a los IPA foot boundaries |
texto = strsubrep(texto, PUNTUACION_EXTRA, "") -- elimino la puntuación restante que haya quedado
texto = strsubrep(texto, "[%-‐]", " ") --los guiones pasan a ser espacios (austro-húngaro, franco-italiano)
texto = strsubrep(texto, "%s*|%s*|%s*", " | ") --finalmente, elimino las barras y espacios de más
texto = strsubrep(texto, "%s+", " ")
texto = strstrip(texto, "[%s|]+")
return texto
end
local function generar_pron(word)
word = normalizar(word)
local phonetic = word
for pat, repl in pairs(phonetic_2chars_map) do
phonetic = phonetic:gsub(pat, repl)
end
phonetic = strsubn(phonetic, '.', phonetic_chars_map)
-- handle unstressed syllabic sonorants in loanwords
phonetic = strsubn(phonetic, "%f[%a%-]([rlʎmnɲ])([bʋgdʒzkmnɲpstfxʃɕʑ])", "%1̩%2")
phonetic = strsubn(phonetic, "([bʋgdʒzkmnɲpstfxʃɕʑ])([rlʎmnɲ])([bʋgdʒzkmnɲpstfxʃɕʑ])", "%1%2̩%3")
phonetic = strsubn(phonetic, "([bʋgdʒzkmnɲpstfxʃɕʑ])([rlʎmnɲ])%f[%A]", "%1%2̩")
phonetic = strsubn(phonetic, "̩̩", "̩")
-- enable use of an apostrophe to keep letters from forming digraphs, e.g. nad'žívjeti
phonetic = strsubn(phonetic, "'", "")
return {{strhtml(phonetic)}}
end
-- Punto de entrada externo, recibe el título de página y los argumentos de plantilla
function export.procesar_pron_args(titulo, args)
if #args["ayuda"] < 1 then
args["ayuda"][1] = titulo
end
if #args["fone"] < 1 and #args["fono"] < 1 then
local x = abc[args["ayuda"][1]]
if x then
args["tl"] = x
args["tlnota"] = "En el serbocroata las letras no tienen nombre. Se pronuncian tal cual su sonido y opcionalmente se agrega un schwa al final."
end
local A = #args["ayuda"]
local j = 1 -- indice de la ayuda
local k = 1 -- cantidad de pronunciaciones insertadas (máximo 9)
while k <= 9 and j <= A do
local fono = generar_pron(args["ayuda"][j])
for i,_ in ipairs(fono) do
table.insert(args["fono"], fono[i])
k = k + 1
if k > 9 then
break
end
end
j = j + 1
end
end
return args
end
return export