local export = {}
local headword_data_module = "Module:headword/data"
local IPA_module = "Module:IPA"
local languages_module = "Module:languages"
local parameters_module = "Module:parameters"
local string_utilities_module = "Module:string utilities"
local load_data = mw.loadData
local function gsub(...)
gsub = require(string_utilities_module).gsub
return gsub(...)
end
local function lower(...)
lower = require(string_utilities_module).lower
return lower(...)
end
local function match(...)
match = require(string_utilities_module).match
return match(...)
end
local BACK = "\204\160" -- back vowel
local CART = "\205\161" -- coarticulation
local FRNT = "\204\159" -- front vowel
local HIGH = "\204\157" -- high vowel
local LENG = "\203\144" -- length
local LOWV = "\204\158" -- low vowel
local NASL = "\204\131" -- nasal
local NSYL = "\204\175" -- nonsyllabic
--[=[
Author: saph (User:Saph668)
Implements {{Template:srn-IPA}}.
]=]
local C = "bdfghklmnprstwjzŋTDɲʃcɟɡɾ"
local V = "aɑeɛiɪoɔuʊãẽĩõũ@" .. NASL .. BACK .. LOWV .. HIGH .. FRNT
local VL = {
= "a",
= "e",
= "i",
= "o",
= "u"
}
local di_s = {
-- digraphs, standard
= "ɔ",
= "ɛ",
= "T",
= "ʃ",
= "D",
= "ɲ"
}
local di_d = {
-- digraphs, 'Dutch'
= "ɔ",
= "ɛ",
= "i",
= "u",
"] = "ai" .. NSYL,
= "ei" .. NSYL,
= "ei" .. NSYL,
= "ɛi" .. NSYL,
= "ɛi" .. NSYL,
"] = "oi" .. NSYL,
= "au" .. NSYL,
= "ou" .. NSYL,
-- o for ow dealt with later
= "T",
= "T",
= "D",
= "ɲ",
= "ʃ"
}
local function pron(text, system)
local results = {}
text = lower(text)
local function sub(...)
text = gsub(text, ...)
end
for h, i in pairs(VL) do
sub(h, i .. LENG)
end
sub("ng", "ŋ")
if system == 0 then
for b, a in pairs(di_s) do
sub(b, a)
end
sub("y", "j")
if not match(text, "" .. LENG .. "?(%(?)(%)?)") then
sub("()(" .. LENG .. "?)(%(?)(%)?)", "%1%2%3i" .. NSYL .. "%4")
sub("()w", "%1u" .. NSYL)
end
end
if system == 1 then
for b, a in pairs(di_d) do
sub(b, a)
sub("()i()", "%1j%2")
sub("ɛj" .. NSYL, "ij")
sub("()u()", "%1w%2")
end
sub("()%1", ".%1")
sub("o()?(?)()", "ou" .. NSYL .. "%1%2%3") -- o for ow in open syl; normalise to ô for ô
end
sub("u" .. NSYL .. "'?()", "w%1")
sub("i" .. NSYL .. "'?()", "j%1")
sub("()?%1", "%1" .. LENG)
sub("g", "ɡ")
sub("r", "ɾ")
sub("ü", "y")
results = gsub(text, "n$", "ŋ")
results = gsub(text, "T", "c")
results = gsub(results, "D", "ɟ")
results = gsub(results, "x", "ɣ")
results = gsub(results, "^ju$", "i")
results = gsub(results, "^wi$", "un")
return results
end
local function phon(text)
local results = {}
results = gsub(text, "()" .. NASL .. "?$", "%1" .. NASL .. "ŋ")
results = gsub(results, "ɡ()", "ɟ%1")
results = gsub(results, "k()", "c%1")
results = gsub(results, "a", "a" .. BACK)
results = gsub(results, "e", "ɪ" .. LOWV)
results = gsub(results, "o", "ʊ" .. LOWV)
results = gsub(text, "ɡ()", "j%1")
results = gsub(results, "k()", "T%1")
results = gsub(results, "a", "ɑ" .. FRNT)
results = gsub(results, "e", "e" .. HIGH)
results = gsub(results, "o", "ɔ" .. HIGH)
for i = 1, 2 do
results = gsub(results, "n?()", "m%1")
results = gsub(results, "n?()", "ŋ%1")
end
return results
end
function export.make_IPAs(term, system)
local results = {}
local prons = pron(term, system)
local phons = phon(prons)
results, results = prons, prons
results, results = phons, phons
local function toIPA(text)
text = gsub(text, "T", "t" .. CART .. "ʃ")
text = gsub(text, "D", "d" .. CART .. "ʒ")
text = gsub(text, "", " |") -- remove punctuation
text = gsub(text, "", "")
text = gsub(text, "@", "ə")
return text
end
for i = 1, 4 do
results = toIPA(results)
end
return results
end
function export.make(frame)
local args =
require(parameters_module).process(
frame:getParent().args,
{
= {default = load_data(headword_data_module).page.pagename},
= {type = "number", set = {0, 1}, default = 0}
}
)
local results = {}
local n = 1
local function ins(arg)
results = arg
n = n + 1
end
args = args:gsub("_", "ˈ")
local IPAs = export.make_IPAs(args, args)
ins {pron = "/" .. IPAs .. "/"}
if IPAs ~= IPAs then
ins {pron = "/" .. IPAs .. "/"}
end
if IPAs ~= IPAs then
ins {pron = " .. "]"}
if IPAs ~= IPAs then
ins {pron = " .. "]"}
end
end
return require(IPA_module).format_IPA_full {
lang = require(languages_module).getByCode("srn"),
items = results
}
end
return export