Module:rad-IPA: Difference between revisions

Added u resolution function.
mNo edit summary
(Added u resolution function.)
Line 29: Line 29:
[false] = "ɛ",
[false] = "ɛ",
},
},
["é"] = "eː",
["f"] = "f",
["f"] = "f",
["g"] = "ɡ",
["g"] = "ɡ",
Line 57: Line 58:
[false] = "ɔ",
[false] = "ɔ",
},
},
["ó"] = "oː",
["ø"] = {
["ø"] = {
["a"] = "œa",
["a"] = "œa",
Line 76: Line 78:
[false] = "u",
[false] = "u",
},
},
["ù"] = "ù",
["û"] = "ɤ",
["û"] = "ɤ",
["ú"] = "uː",
["ú"] = "uː",
Line 103: Line 106:
data["!"] = data["."]
data["!"] = data["."]
data["?"] = data["."]
data["?"] = data["."]
local valid_phone = {
["a"] = true, ["aː"] = true, ["aːː"] = true, ["æː"] = true, ["ai"] = true, ["au"] = true, ["b"] = true,
["ç"] = true, ["d"] = true, ["ð"] = true, ["eː"] = true, ["ei"] = true, ["ɛ"] = true, ["ɤ"] = true,
["ɤi"] = true, ["f"] = true, ["ɡ"] = true, ["ɣ"] = true, ["h"] = true, ["i"] = true, ["iː"] = true,
["iːː"] = true, ["iːe"] = true, ["ia"] = true, ["ie"] = true, ["j"] = true, ["k"] = true, ["l"] = true,
["m"] = true, ["n"] = true, ["ŋ"] = true, ["oː"] = true, ["œ"] = true, ["œa"] = true, ["øi"] = true,
["ɔ"] = true, ["ɔː"] = true, ["ɔa"] = true, ["ɔi"] = true, ["p"] = true, ["r"] = true, ["s"] = true,
["ʃ"] = true, ["t"] = true, ["u"] = true, ["uː"] = true, ["uːː"] = true, ["uːo"] = true, ["ua"] = true,
["uo"] = true, ["v"] = true, ["w"] = true, ["y"] = true, ["z"] = true, ["ʒ"] = true, ["θ"] = true,
}
local consonant = {
["b"] = true, ["ç"] = true, ["d"] = true, ["ð"] = true, ["f"] = true,
["ɡ"] = true, ["ɣ"] = true, ["h"] = true, ["j"] = true, ["k"] = true,
["l"] = true, ["m"] = true, ["n"] = true, ["ŋ"] = true, ["p"] = true,
["r"] = true, ["s"] = true, ["ʃ"] = true, ["t"] = true, ["v"] = true,
["w"] = true, ["y"] = true, ["z"] = true, ["ʒ"] = true, ["θ"] = true,
}
local vowel = {
["a"] = true, ["aː"] = true, ["aːː"] = true, ["æː"] = true, ["ai"] = true, ["au"] = true,
["eː"] = true, ["ei"] = true, ["ɛ"] = true, ["ɤ"] = true, ["ɤi"] = true, ["i"] = true,
["iː"] = true, ["iːː"] = true, ["iːe"] = true, ["ia"] = true, ["ie"] = true, ["oː"] = true,
["œ"] = true, ["œa"] = true, ["øi"] = true, ["ɔ"] = true, ["ɔː"] = true, ["ɔa"] = true,
["ɔi"] = true, ["u"] = true, ["uː"] = true, ["uːː"] = true, ["uːo"] = true, ["ua"] = true,
["uo"] = true,
}
local glide = {
["j"] = true, ["w"] = true,
}
local boundary = {
[" "] = true, ["|"] = true, ["·"] = true,
}


local IPA = {}
local IPA = {}


function append_IPA (working_IPA)
function append_IPA(working_IPA)
local IPA_size = #IPA --This variable needs to be set before the function or it breaks.
local IPA_size = #IPA --This variable needs to be set before the function or it breaks.
-- generate_IPA: mw.log("————— REGISTERING PHONE —————")
-- generate_IPA: mw.log("————— REGISTERING PHONE —————")
Line 128: Line 167:
  split_s[i] = mw.ustring.sub(s, i,i)
  split_s[i] = mw.ustring.sub(s, i,i)
end
end
-- generate_IPA: mw.log("————— BEGINNING BASE GENERATION —————")


if s_len == 0 then
if s_len == 0 then
Line 223: Line 264:


-- generate_IPA: mw.log('————— STRING EXHAUSTED —————')
-- generate_IPA: mw.log('————— STRING EXHAUSTED —————')
mw.log("Base generation result: [" .. table.concat(IPA,"][") .. "]")
return IPA
return IPA
end
function resolve_u(phones)
local working_phones = phones
mw.log("————— BEGINNING U RESOLUTION —————")
for i = 1, #working_phones do
local p_current = working_phones[i]
local p_next = working_phones[i + 1]
local p_next2 = working_phones[i + 2]
local p_next3 = working_phones[i + 3]
local toResolve = false
if p_current == "a" and p_next == "ù" then
mw.log("<aù> recognised in position " .. i .. ". Converting to resolvable [u].")
working_phones[i + 1] = "u"
end
if p_current == "u" then
mw.log("[u] found in position " .. i .. ".")
if consonant[p_next] then
if glide[p_next2] then
if not vowel[p_next3] then
mw.log("ɤCj!V environment identified.")
toResolve = true
end
elseif not vowel[p_next2] and not glide[p_next2] then
mw.log("ɤC!V environment identified.")
toResolve = true
end
end
elseif p_current == "ù" or p_current == "ū" then
mw.log("Fixed [u] found in position " .. i .. ".")
working_phones[i] = "u"
end
if toResolve == true then
working_phones[i] = "ɤ"
mw.log("[u] → [ɤ] in position ".. i .. ".")
end
end
mw.log("[u] resolution result: [" .. table.concat(working_phones,"][") .. "]")
return working_phones
end
end


Line 229: Line 316:
local args = getArgs(frame)
local args = getArgs(frame)
local baseGen = generate_IPA(args[1])
local baseGen = generate_IPA(args[1])
local outputIPA = table.concat(baseGen,"][")
local outputIPA = resolve_u(baseGen)
outputIPA = table.concat(outputIPA,"][")
return "[" .. outputIPA .. "]"
return "[" .. outputIPA .. "]"