Module:rad-IPA: Difference between revisions
Jump to navigation
Jump to search
TheNightAvl (talk | contribs) mNo edit summary |
TheNightAvl (talk | contribs) mNo edit summary |
||
Line 103: | Line 103: | ||
data["!"] = data["."] | data["!"] = data["."] | ||
data["?"] = data["."] | data["?"] = data["."] | ||
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. | ||
mw.log("————— REGISTERING PHONE —————") | |||
if IPA_size > 0 then | if IPA_size > 0 then | ||
for i=1, IPA_size do | for i=1, IPA_size do | ||
Line 113: | Line 115: | ||
end | end | ||
IPA[1] = working_IPA | IPA[1] = working_IPA | ||
mw.log("[" .. working_IPA .. "] registered.") | |||
mw.log("Current IPA: [" .. table.concat(IPA, "][") .. "]") | |||
end | end | ||
-- BEGIN BASE GENERATION -- | -- BEGIN BASE GENERATION -- | ||
function generate_IPA(word) | function generate_IPA(word) | ||
Line 140: | Line 140: | ||
local i_iteration = -2 | local i_iteration = -2 | ||
mw.log("\n=========================\n\nCURRENT TEST STRING: <".. mw.ustring.upper(s) .. ">") | |||
if s_len < 3 then | if s_len < 3 then | ||
Line 147: | Line 147: | ||
for i = i_iteration, 0 do | for i = i_iteration, 0 do | ||
mw.log("————— <" .. split_s[s_len + i] .. "> selected. (i = " .. i .. ") —————") | |||
getData = data[split_s[s_len + i]] | getData = data[split_s[s_len + i]] | ||
local deadEnd = false | local deadEnd = false | ||
Line 158: | Line 158: | ||
if i == 0 then | if i == 0 then | ||
if getData[false] then | if getData[false] then | ||
mw.log("Singular index recognised.") | |||
getData = getData[false] | getData = getData[false] | ||
mw.log("Index acquired: " .. getData) | |||
else | else | ||
error(split_s[s_len] .. " is an invalid character.") | error(split_s[s_len] .. " is an invalid character.") | ||
end | end | ||
else | else | ||
mw.log("Tabular index recognised.") | |||
for j = 1, 0 - i do | for j = 1, 0 - i do | ||
-- DEBUG PRINT ONLY | -- DEBUG PRINT ONLY | ||
Line 175: | Line 175: | ||
end | end | ||
-- END OF DEBUG PRINT | -- END OF DEBUG PRINT | ||
mw.log("Testing " .. currentCombo) | |||
if getData[split_s[s_len + i + j]] then | if getData[split_s[s_len + i + j]] then | ||
getData = getData[split_s[s_len + i + j]] | getData = getData[split_s[s_len + i + j]] | ||
mw.log("Combination recognised: " .. currentCombo .. " (j = " .. j .. ")") | |||
if type(getData) == "string" then | if type(getData) == "string" then | ||
if j + i == 0 then | if j + i == 0 then | ||
mw.log("Index acquired: " .. getData) | |||
multiMatch = true | multiMatch = true | ||
break | break | ||
else | else | ||
mw.log('Non-final index: dead end.') | |||
getData = {} | getData = {} | ||
deadEnd = true | deadEnd = true | ||
Line 194: | Line 194: | ||
elseif j + i == 0 and getData[false] then | elseif j + i == 0 and getData[false] then | ||
getData = getData[false] | getData = getData[false] | ||
mw.log("Index acquired: " .. getData) | |||
multiMatch = true | multiMatch = true | ||
break | break | ||
Line 200: | Line 200: | ||
error("data[" .. table.concat(getData, "][") .. "][false] is missing." ) | error("data[" .. table.concat(getData, "][") .. "][false] is missing." ) | ||
else | else | ||
mw.log("Target still tabular: reiterating.") | |||
end | end | ||
else | else | ||
mw.log('Dead end.') | |||
getData = {} | getData = {} | ||
deadEnd = true | deadEnd = true | ||
Line 213: | Line 213: | ||
end | end | ||
if type(getData) == "string" and (i == 0 or multiMatch == true) then | if type(getData) == "string" and (i == 0 or multiMatch == true) then | ||
mw.log("Target acquired of length " .. 1 - i .. ", converting to [" .. getData .. "].") | |||
append_IPA(getData) | append_IPA(getData) | ||
s = mw.ustring.sub(s, 1, s_len + i - 1) | s = mw.ustring.sub(s, 1, s_len + i - 1) | ||
Line 219: | Line 219: | ||
break | break | ||
elseif deadEnd == false then | elseif deadEnd == false then | ||
mw.log('Non-final index: dead end.') | |||
end | end | ||
end | end | ||
end | end | ||
mw.log('\n————— STRING EXHAUSTED —————') | |||
return table.concat(IPA) | return table.concat(IPA) | ||
Revision as of 16:57, 17 August 2023
See {{rad-IPA}}
.
local getArgs = require('Module:Arguments').getArgs
local p = {}
local data = {
["a"] = {
["i"] = "ai",
["o"] = {
["i"] = "ɔi",
[false] = "ɔː",
},
["u"] = "au",
[false] = "a",
},
["á"] = "aː",
["ả"] = "aːː",
["â"] = "ɤ",
["âi"] = "ɤi",
["b"] = "b",
["c"] = "ts",
["d"] = {
["x"] = "dʒ",
["z"] = "dz",
[false] = "d",
},
["ð"] = "ð",
["e"] = {
["a"] = "æː",
["i"] = "ei",
[false] = "ɛ",
},
["f"] = "f",
["g"] = "ɡ",
["h"] = "h",
["ħ"] = "ɣ",
["i"] = {
["e"] = {
["a"] = "ia",
[false] = "ie",
},
[false] = "i",
},
["í"] = "iː",
["ỉ"] = {
["e"] = "iːe",
[false] = "iːː",
},
["j"] = "j",
["ĵ"] = "ĵ",
["k"] = "k",
["ķ"] = "tʃ",
["l"] = "l",
["m"] = "m",
["n"] = "n",
["ņ"] = "ŋ",
["o"] = {
["a"] = "ɔa",
[false] = "ɔ",
},
["ø"] = {
["a"] = "œa",
["i"] = "ei",
[false] = "œ",
},
["p"] = "p",
["q"] = "k",
["r"] = "r",
["s"] = "s",
["ș"] = "ʃ",
["t"] = "t",
["u"] = {
["i"] = "ɤi",
["o"] = {
["a"] = "ua",
[false] = "uo",
},
[false] = "u",
},
["û"] = "ɤ",
["ú"] = "uː",
["ủ"] = {
["o"] = "uːo",
[false] = "uːː",
},
["ū"] = "ū",
["v"] = "v",
["w"] = "w",
["x"] = "ʒ",
["ỳ"] = "ỳ",
["z"] = "z",
["þ"] = "θ",
["·"] = "·",
[" "] = " ",
["."] = "|",
}
data["à"] = data["a"]
data["è"] = data["e"]
data["ì"] = data["i"]
data["ò"] = data["o"]
data["y"] = data["i"]
data["ý"] = data["í"]
data["ỷ"] = data["ỉ"]
data[","] = data["."]
data["!"] = data["."]
data["?"] = data["."]
local IPA = {}
function append_IPA (working_IPA)
local IPA_size = #IPA --This variable needs to be set before the function or it breaks.
mw.log("————— REGISTERING PHONE —————")
if IPA_size > 0 then
for i=1, IPA_size do
IPA[IPA_size - i + 2] = IPA[IPA_size - i + 1]
end
end
IPA[1] = working_IPA
mw.log("[" .. working_IPA .. "] registered.")
mw.log("Current IPA: [" .. table.concat(IPA, "][") .. "]")
end
-- BEGIN BASE GENERATION --
function generate_IPA(word)
local s = word
local s_len = mw.ustring.len(s)
IPA = {}
local split_s = {}
for i = 1, s_len do
split_s[i] = mw.ustring.sub(s, i,i)
end
if s_len == 0 then
error("Empty input.")
end
while s_len > 0 do
local getData = {}
local multiMatch = false
local i_iteration = -2
mw.log("\n=========================\n\nCURRENT TEST STRING: <".. mw.ustring.upper(s) .. ">")
if s_len < 3 then
i_iteration = 1 - s_len
end
for i = i_iteration, 0 do
mw.log("————— <" .. split_s[s_len + i] .. "> selected. (i = " .. i .. ") —————")
getData = data[split_s[s_len + i]]
local deadEnd = false
if data[split_s[s_len + i]] == nil then
error("'" .. split_s[s_len + i] .. "' is an invalid character.")
end
while type(getData) == "table" do
if i == 0 then
if getData[false] then
mw.log("Singular index recognised.")
getData = getData[false]
mw.log("Index acquired: " .. getData)
else
error(split_s[s_len] .. " is an invalid character.")
end
else
mw.log("Tabular index recognised.")
for j = 1, 0 - i do
-- DEBUG PRINT ONLY
local currentCombo = ""
if i == -2 and j == 2 then
currentCombo = split_s[s_len + i + j - 2] .. " + " .. split_s[s_len + i + j - 1] .. " + " .. split_s[s_len + i + j]
else
currentCombo = split_s[s_len + i + j - 1] .. " + " .. split_s[s_len + i + j]
end
-- END OF DEBUG PRINT
mw.log("Testing " .. currentCombo)
if getData[split_s[s_len + i + j]] then
getData = getData[split_s[s_len + i + j]]
mw.log("Combination recognised: " .. currentCombo .. " (j = " .. j .. ")")
if type(getData) == "string" then
if j + i == 0 then
mw.log("Index acquired: " .. getData)
multiMatch = true
break
else
mw.log('Non-final index: dead end.')
getData = {}
deadEnd = true
break
end
elseif j + i == 0 and getData[false] then
getData = getData[false]
mw.log("Index acquired: " .. getData)
multiMatch = true
break
elseif j + i == 0 and not getData[false] then
error("data[" .. table.concat(getData, "][") .. "][false] is missing." )
else
mw.log("Target still tabular: reiterating.")
end
else
mw.log('Dead end.')
getData = {}
deadEnd = true
break
end
end
if type(getData) == "table" then break end
end
end
if type(getData) == "string" and (i == 0 or multiMatch == true) then
mw.log("Target acquired of length " .. 1 - i .. ", converting to [" .. getData .. "].")
append_IPA(getData)
s = mw.ustring.sub(s, 1, s_len + i - 1)
s_len = mw.ustring.len(s)
break
elseif deadEnd == false then
mw.log('Non-final index: dead end.')
end
end
end
mw.log('\n————— STRING EXHAUSTED —————')
return table.concat(IPA)
-- END OF BASE GENERATION --
end
function p.generate(frame)
local args = getArgs(frame)
return generate_IPA(args[1])
end
return p