Module:akk-IPA/sandbox
Appearance
- This module sandbox lacks a documentation subpage. Please create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • sandbox of (diff)
local export = {}
local rsub = mw.ustring.gsub
local rmatch = mw.ustring.match
local consonants = "[ʔbdɡxklmnpqrsSʃtwjz]"
local vowels = "[aeiuāēīūâêîû]"
local c = {
{"zz", "dz"},
{"ss", "tS"},
{"s", "S"},
{"ṣṣ", "tS’"},
{"ṣ", "S’"},
{"š", "s"},
{"ṭ", "t’"},
{"q", "k’"},
{"y", "j"},
{"g", "ɡ"},
{"ḫ", "x"},
{"'", "ʔ"},
{"(" .. vowels .. consonants .. "?’?)(" .. consonants .. "’?)%f" .. vowels, "%1.%2"}
}
local d = {
{"[āâ]", "aː"},
{"[ēê]", "eː"},
{"[īî]", "iː"},
{"[ūû]", "uː"},
{"z", "d͡z"},
{"S", "t͡s"}
}
function export.pronunciation_phonemic(word)
word = mw.ustring.lower(word)
for a = 1, #c do word = rsub(word, c[a][1], c[a][2]) end
local N = {}
local i = 0
for a in string.gmatch(word, "%S+") do
i = i + 1
N[i] = a
end
for a = 1, #N do
if rmatch(N[a], consonants .. "?’?[âêîû]$") ~= nil then -- last syllable is ultraheavy (circumflex)
N[a] = rsub(N[a], "%.?(" .. consonants .. "?’?[âêîû])$", "ˈ%1") -- final stress
elseif rmatch(N[a], consonants .. "?’?[āēīūâêîû]" .. consonants .. "’?$") ~= nil then -- again (any long vowels, + consonants)
N[a] = rsub(N[a],
"%.?(" .. consonants .. "?’?[āēīūâêîû]" .. consonants .. "’?)$",
"ˈ%1") -- final stress
elseif rmatch(rsub(N[a], consonants .. "’?" .. vowels .. consonants .. "?’?$", ""),
consonants .. "?’?" .. "[āēīūâêîû]%.") ~= nil or
rmatch(rsub(N[a], consonants .. "’?" .. vowels .. consonants .. "?’?$", ""),
consonants .. "?’?" .. "[aeiuāēīū]" .. consonants .. "’?%.") ~= nil then -- otherwise, detects if there is (not where it is) a non-final heavy or ultraheavy syllable (long vowels, or any non-circumflex + consonants)
local n = ""
for _ = 1, 5 do -- arbitrary, find how to count syllables
N[a] = rsub(N[a],
"%.?(" .. consonants .. "?’?" .. "[āēīūâêîû]%." .. n ..
consonants .. "’?" .. vowels .. consonants .. "?’?)$", "ˈ%1") -- long vowels
N[a] = rsub(rsub(N[a],
"%.?(" .. consonants .. "?’?" .. "[aeiuāēīū]" .. consonants ..
"’?%." .. n .. consonants .. "’?" .. vowels .. consonants ..
"?’?)$", "ˈ%1"), "ˈˈ", "ˈ") -- non-circumflex + consonants
n = n .. consonants .. "’?[aeiu]%." -- +1 light syllable
end
else -- no non-final heavy nor ultraheavy syllable detected, ie. there are only non-final light ones
N[a] = rsub(N[a], "^( ?)(" .. consonants .. "?’?[aeiu]%.)", "%1ˈ%2") -- initial stress
end
end
word = table.concat(N, " ")
for a = 1, #d do word = rsub(word, d[a][1], d[a][2]) end
return word
end
function export.show(frame)
local results = {}
table.insert(results, { pron = "/" ..export.pronunciation_phonemic(mw.title.getCurrentTitle().text) .. "/"})
return "* " .. require("Module:IPA").format_IPA_full { lang = require("Module:languages").getByCode("akk"), items = results }
end
return export