---Lexicographic tools for Jarai language text.
local lang = require("Module:languages").getByCode("jra")
local p = {}
---Converts the given text to traditional tone marks.
function p.toTraditionalTones(text)
if type(text) == "table" then
text = text.args
end
return (mw.ustring.gsub(text, "%a+", function (word)
if mw.ustring.match(word, "^qu$") then return word end
return (mw.ustring.gsub(word, "%a%a$", {
= "óa", = "òa", = "ỏa", = "õa", = "ọa",
= "óe", = "òe", = "ỏe", = "õe", = "ọe",
= "úy", = "ùy", = "ủy", = "ũy", = "ụy"
}))
end))
end
---Converts the given text to reformed tone marks.
function p.toReformedTones(text)
if type(text) == "table" then
text = text.args
end
return (mw.ustring.gsub(text, "%a+", function (word)
return (mw.ustring.gsub(word, "%a%a$", {
= "oá", = "oà", = "oả", = "oã", = "oạ",
= "oé", = "oè", = "oẻ", = "oẽ", = "oẹ",
= "uý", = "uỳ", = "uỷ", = "uỹ", = "uỵ"
}))
end))
end
function p.allSpellings(main_spelling, makeLinks)
local frame = nil
if type(main_spelling) == "table" then
frame = main_spelling
main_spelling, makeLinks = frame.args, frame.args.link
end
local xformers = {
p.toTraditionalTones, p.toReformedTones,
}
local spellings = {}
for i, xformer in ipairs(xformers) do
local alt_spelling = xformer(main_spelling)
if not spellings then
table.insert(spellings, alt_spelling)
spellings = true
end
end
if makeLinks then
local m_links = require("Module:links") -- ]
for k, link in ipairs(spellings) do
spellings = m_links.full_link(link, nil, lang, nil, nil, nil, {}, false)
end
end
return frame and table.concat(spellings, "/") or spellings
end
---Unicode codepoints for combining Jarai tone marks.
p.combiningToneMarks = mw.ustring.char(
0x300, -- à
0x301, -- á
0x303, -- ã
0x309, -- ả
0x323 -- ạ
)
---Unicode codepoints for combining Jarai accent marks.
p.combiningAccentMarks = mw.ustring.char(
0x302, -- â
0x306, -- ă
0x31b -- ơ
)
---Strips Jarai diacritical marks from the given text.
-- @param tones Set to “0” to leave tone marks intact.
-- @param accents Set to “0” to leave accent marks intact.
-- @param đ Set to “0” to leave “Đ” and “đ” intact.
function p.removeDiacritics(text, toneMarks, accentMarks, stroke)
if type(text) == "table" then
text, toneMarks, accentMarks, stroke = text.args,
not text.args.tones or tonumber(text.args.tones) == 1,
not text.args.accents or tonumber(text.args.accents) == 1,
not text.args or tonumber(text.args) == 1
end
text = mw.ustring.toNFD(text)
if toneMarks then
text = mw.ustring.gsub(text, "", "")
end
if accentMarks then
text = mw.ustring.gsub(text, "", "")
end
if stroke then
text = mw.ustring.gsub(text, "", { = "D", = "d"})
end
return mw.ustring.toNFC(text)
end
---Jarai letters for use in comp().
p.letters = "aAăĂâÂbBƀɃcCčČdDđĐeEĕĔêÊê̆Ê̆gGhHiIĭĬjJkKlLmMnNñÑŏŎôÔô̆Ô̆ơƠơ̆Ơ̆pPrRsStTuUŭŬưƯư̆Ư̆wWyY"
---Compare two syllables according to Jarai dictionary sorting order.
function p.compWord(word1, word2)
if mw.ustring.find(word1, word2, 1, true) == 1 then return false end
if mw.ustring.find(word2, word1, 1, true) == 1 then return true end
do
local func1, static1, var1 = mw.ustring.gmatch(word1, "")
local func2, static2, var2 = mw.ustring.gmatch(word2, "")
while true do
local c1 = func1(static1, var1)
local c2 = func2(static2, var2)
if c1 == nil or c2 == nil then break end
local idx1 = mw.ustring.find(p.letters, c1, 1, true)
local idx2 = mw.ustring.find(p.letters, c2, 1, true)
if idx1 and idx2 then
if idx1 < idx2 then return true end
if idx1 > idx2 then return false end
end
end
end
return word1 < word2
end
---Compare two strings according to Jarai dictionary sorting order.
function p.comp(text1, text2)
if text1 == text2 then return false end
do
local func1, static1, var1 = mw.ustring.gmatch(text1, "%a+")
local func2, static2, var2 = mw.ustring.gmatch(text2, "%a+")
while true do
local word1 = func1(static1, var1)
local word2 = func2(static2, var2)
if word1 == nil then return true end
if word2 == nil then return false end
if word1 ~= word2 then
local lower1 = mw.ustring.lower(word1)
local lower2 = mw.ustring.lower(word2)
local noTones1 = p.removeDiacritics(lower1, true, false, false)
local noTones2 = p.removeDiacritics(lower2, true, false, false)
-- Compare base letters.
if noTones1 ~= noTones2 then
return p.compWord(noTones1, noTones2)
end
-- Compare letters case-insensitively.
if lower1 ~= lower2 then
return p.compWord(lower1, lower2)
end
-- Compare letters including tones.
assert(word1 ~= word2)
return p.compWord(word1, word2)
end
end
end
return text1 < text2
end
---Returns the categories indicated by the given wikitext.
function p.classifierCategories(frame)
local src = frame.args
local classifiers = {}
for classifier in mw.ustring.gmatch(mw.ustring.gsub(src, "<->", ""), "+") do
if classifier ~= "l" and classifier ~= "jra" and classifier ~= "jra-l" and
classifier ~= "Jarai" then
local cat = mw.ustring.format("]",
classifier)
table.insert(classifiers, cat)
end
end
return table.concat(classifiers)
end
return p