local export = {}
local toNFC = mw.ustring.toNFC
local toNFD = mw.ustring.toNFD
local u = mw.ustring.char
local ulower = mw.ustring.lower
local letters = {
= "a", = "b", = "g", = "d", = "e", = "v",
= "#2", = "z", = "h", = "q", = "i", = "k",
= "l", = "m", = "n", = "c", = "o", = "p",
= "#1", = "#3", = "r", = "s", = "s", = "s3",
= "t", = "u", = "f", = "x", = "y", = "w",
= "#5",
= ")", = ")", = ")", = ")", = ")", -- psili
= "(", = "(", = "(", --
= "/", = "/", = "/", = "/", = "/", -- acute
= "=", = "=", -- perispomeni
= "\\", = "\\", = "\\", = "\\", -- grave
= "+", = "+", -- dialytika
= "|", = "|", -- ypogegrammeni
= "?",
= ":", = ":", -- ano teleia
= ";", -- erotimatiko
= "", -- macron
= "", -- breve
= "", = "", -- hyphen
= "'" -- apostrophe
}
local function convert(ch)
local ret = letters
if ret then
return ret
end
local ch_lower = ulower(ch)
if ch_lower ~= ch then
ret = letters
if ret then
ret = "*" .. ret
end
end
return ret
end
local function handle_char(base, diacritics, pre)
local set = ")(/\\=|+"
if pre then
set = set:reverse()
end
for ch in (set):gmatch(".") do
if diacritics:find(ch, nil, true) then
if pre then
base = ch .. base
else
base = base .. ch
end
end
end
return (pre and "*" or "") .. base
end
function export.polytonic_to_perseus_betacode(polytonic)
return toNFC(toNFD(polytonic):gsub(".*", convert)
:gsub("%*(%l)(+)()", handle_char)
:gsub("%*(#%d+)(+)()", handle_char)
:gsub("(%l)(+)", handle_char)
:gsub("(#%d+)(+)", handle_char)
)
end
return export