Module:qhv-pron: Difference between revisions

Jump to navigation Jump to search
Thanks Juelos!
No edit summary
(Thanks Juelos!)
 
(41 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 m_table = require("Module:table")


local export = {}
local export = {}


local palatal = "ɲʎɟj"
local velar = "kɡxɣ"
local velar = "kɡxɣ"
local uvular = "q"
local uvular = "q"
local consonants = "[mpbvwθntdszlrɾɲŋɴʎhɥjɟṛ" .. velar .. uvular .. "]"
local consonants = "[mpbvwθntdszlrɾŋɴhɥṛ" .. palatal .. velar .. uvular .. "]"
local NONSYLLABIC = u(0x032F) -- non-syllabic, combining inverted breve below
local NONSYLLABIC = u(0x032F) -- non-syllabic, combining inverted breve below
local DIPHTHONG = u(0x035C) -- double articulation, combining double breve below
local DIPHTHONG = u(0x035C) -- double articulation, combining double breve below
local vowels = "[aeiouyː" .. NONSYLLABIC .. DIPHTHONG .. "]"
local vowels = "[aeiouyáéíóúýàèìòùỳː" .. NONSYLLABIC .. DIPHTHONG .. "]"


local rules = {
local rules = {
{"rh", "ṛ"}, {"th", "θ"}, {"lj", "ʎ"}, {"ñ", "ɲ"}, {"kh", "x"}, {"[gɡ]h", "ɣ"}, {"g", "ɡ"},
{"rh", "ṛ"}, {"mh", "m"}, {"th", "θ"}, {"lj", "ʎ"}, {"ñ", "ɲ"}, {"kh", "x"}, {"[gɡ]h", "ɣ"}, {"g", "ɡ"},
{"([][eo])", "%1" .. NONSYLLABIC}, {"([iu])([aāeēoō])", "%1" .. DIPHTHONG .. "%2"},  
{"([aāáà][eo])", "%1" .. NONSYLLABIC}, {"([iíuú])([aāeēoōáéóàèò])", "%1" .. DIPHTHONG .. "%2"},  
{"ā", "aː"}, {"ē", "eː"}, {"ī", "iː"}, {"ō", "oː"}, {"ū", "uː"}, {"ȳ", "yː"},
{"ā", "aː"}, {"ē", "eː"}, {"ī", "iː"}, {"ō", "oː"}, {"ū", "uː"}, {"ȳ", "yː"},
{"à", "áː"}, {"è", "éː"}, {"ì", "íː"}, {"ò", "óː"}, {"ù", "úː"}, {"ỳ", "ýː"},
{"n([" .. velar .. "])", "ŋ%1"}, {"n([" .. uvular .. "])", "ɴ%1"}, {"(" .. vowels .. ")r(" .. vowels .. ")", "%1ɾ%2"},  
{"n([" .. palatal .. "])", "ɲ%1"}, {"n([" .. velar .. "])", "ŋ%1"}, {"n([" .. uvular .. "])", "ɴ%1"},
{"(" .. vowels .. ")r(" .. vowels .. ")", "%1ɾ%2"}, {"ɲi", "ni"}, {"ʎi", "li"},
}
 
local deacuter = {
["á"] = "a", ["é"] = "e", ["í"] = "i", ["ó"] = "o", ["ú"] = "u", ["ý"] = "y",
}
}


local function write_stress(term)
function export.write_stress(term, from_module)
local pattern = "(" .. consonants .. "*".. vowels .. "*" .. consonants .. "-)"
local pattern = "(" .. consonants .. "*".. vowels .. "*" .. consonants .. "-)"
local syllables, weight = {}, {}
local weight = {}
term = gsub(term, pattern, "·%1")
term = gsub(term, pattern, "·%1")
term = gsub(term, "^·", "")
term = gsub(term, "^·", "")
term = gsub(term, "·$", "")
term = gsub(term, "·(" .. consonants .. ")·", "·%1")
term = gsub(term, "·(" .. consonants .. ")·", "·%1")
term = gsub(term, "·(" .. consonants .. ")$", "%1")
term = gsub(term, "·(" .. consonants .. ")$", "%1")
term = gsub(term, "·(" .. consonants .. ")(" .. consonants .. ")", "%1·%2")   
term = gsub(term, "·(" .. consonants .. ")(" .. consonants .. ")", "%1·%2")   
term = gsub(term, "([ptkbdɡ])·([rlṛsz])", "·%1%2")
term = gsub(term, "([ptkbdɡ])·([rlṛsz])", "·%1%2")
term = gsub(term, "·$", "")
term = gsub(term, "·(" .. consonants .. "?" .. consonants .. ")$", "%1")
local syllables = split(term, "·")
if from_module then return #syllables end -- allow other modules to know the number of syllables
syllables = split(term, "·")
if #syllables == 1 then return table.concat(syllables) end -- account for monosyllables
for i, syllable in ipairs(syllables) do
for i, syllable in ipairs(syllables) do
weight[i] = match(syllable, "[aeiouy" .. NONSYLLABIC .. "]$") and "l" or "h"
if match(syllable, "[áéíóúý]") then -- if the user inputted manual stress, ignore all the rest
table.insert(syllables, i, "ˈ")
return table.concat(syllables)
end
if match(syllable, consonants .. "$") or match(syllable, "ː$") then weight[i] = "h"
elseif match(syllable, NONSYLLABIC .. "$") then weight[i] = "h"
else weight[i] = "l"
end
end
end
local a, p = weight[#weight-2], weight[#weight-1]
local a, p = weight[#weight-2], weight[#weight-1]
if p == nil then table.insert(syllables, #syllables, "ˈ")
if p == "l" and a == "h" then table.insert(syllables, #syllables-2, "ˈ")
elseif a == nil then table.insert(syllables, #syllables-1, "ˈ")
elseif (p == "l" and a == "l") or (p == "h") or (a == nil) then table.insert(syllables, #syllables-1, "ˈ")
elseif p == "l" and a == "h" then table.insert(syllables, #syllables-2, "ˈ")
elseif p == nil then table.insert(syllables, #syllables, "ˈ")
elseif (p == "l" and a == "l") or (p == "h") then table.insert(syllables, #syllables-1, "ˈ")
else table.insert(syllables, #syllables-1, "ˈ") end
else table.insert(syllables, #syllables-1, "ˈ") end
Line 59: Line 80:
end
end
return write_stress(term)
return export.write_stress(term, false)
end
end


function export.antique_crux(term)
function export.antique_crux(term)
local oldrules = {
local oldrules = {
{"v([ou])", "w%1"}, {"v([ay])", "ɥ%1"}, {"(" .. vowels .. ")v(" .. consonants .. ")", "u"},
{"v([ou])", "w%1"}, {"v([ay])", "ɥ%1"}, {"(" .. vowels .. ")v(ˈ?" .. consonants .. ")", "%1u%2"},
{"j([iy])", "ɟ%1"},
{"j([iy])", "ɟ%1"}, {"sˈ?ri(".. vowels .. ")", "ˈɟ%1"}, {"sr", "ɟ"}, {"sˈ?r", "ˈɟ"},
}
}
Line 116: Line 137:
local ipa = "* "
local ipa = "* "
ipa = ipa .. line_format(separate_word(term, false), {'Modern'})
ipa = ipa .. line_format(separate_word(term, false), {'Post-Classical'})
if export.crux(term) ~= export.antique_crux(term) then
if export.crux(term) ~= export.antique_crux(term) then
ipa = ipa .. "\n* " .. line_format(separate_word(term, true), {'Antique'})
ipa = ipa .. "\n* " .. line_format(separate_word(term, true), {'Classical'})
end
end
ipa = gsub(ipa, "ṛ", "r̥")
ipa = gsub(ipa, "ṛ", "r̥")
ipa = gsub(ipa, "([áéíóú])", function(v) return deacuter[v] end)
return ipa
return ipa

Navigation menu