Module:ka-hyphen
Dehra
Documentation for this module may be created at Module:ka-hyphen/doc
local export = {}
local gsub = mw.ustring.gsub
local gsplit = mw.text.gsplit
local format_hyphens = require('Module:hyphenation').format_hyphenations
local lang = require('Module:languages').getByCode('ka')
local scr = require('Module:scripts').getByCode('Geor')
local V = "აეიოუ"
local C = "ბგდვზთკლმნპჟრსტფქღყშჩცძწჭხჯჰ" .. "ABCDEFGHIJKL" -- Latin letters represent harmonic clusters
local harmonic = {
["ფხ"] = "A",
["თხ"] = "B",
["ცხ"] = "C",
["ჩხ"] = "D",
["ბღ"] = "E",
["დღ"] = "F",
["ზღ"] = "G",
["ჯღ"] = "H",
["პყ"] = "I",
["ტყ"] = "J",
["წყ"] = "K",
["ჭყ"] = "L"
}
local harmonic_inv = {}
for k, v in pairs(harmonic) do
harmonic_inv[v] = k
end
function export.main(frame)
local parent_args = frame:getParent().args
local term = parent_args[1] or mw.title.getCurrentTitle().text -- unnamed parameter or PAGENAME
local syllables = {}
-- check if there's numbered parameters (for custom syllables)
for k, v in pairs(parent_args) do
local num = tonumber(k)
if num and v ~= '' then
syllables[num] = v
end
end
-- otherwise automatically process and syllabify term
if next(syllables) == nil then
local processed_term = export.hyphenateTerm(term)
for syllable in gsplit(processed_term, "‧") do
table.insert(syllables, syllable)
end
else
-- convert numbered table to sequence
local temp = {}
for i = 1, #syllables do
if syllables[i] then
table.insert(temp, syllables[i])
end
end
syllables = temp
end
-- data structure for displaying hyphenation
local data = {
lang = lang,
hyphs = {
{
hyph = syllables,
sc = scr
}
},
sc = scr,
nocaption = parent_args.nocaption,
caption = parent_args.caption
}
return format_hyphens(data)
end
function export.hyphenateTerm(term)
-- convert harmonic clusters
for k, v in pairs(harmonic) do
term = gsub(term, k, v)
end
-- only process actual Georgian text segments
local hyphenated = gsub(term, "([" .. V .. C .. "]+)", hyphenateWord)
-- restore harmonic clusters
for k, v in pairs(harmonic_inv) do
hyphenated = gsub(hyphenated, k, v)
end
return hyphenated
end
function hyphenateWord(word)
-- თ‧ა‧ვქ‧უ‧დმ‧ო‧გლ‧ე‧ჯ‧ი‧ლ‧ი‧
word = gsub(word, "([" .. V .. "])", "‧%1‧")
-- remove leading and trailing hyphens
word = gsub(word, "^‧+", "")
word = gsub(word, "‧+$", "")
word = gsub(word, "‧‧+", "‧")
-- shift hyphens to the right of consonants
word = gsub(word, "([" .. V .. "])‧([" .. C .. "])([" .. C .. "]+)‧([" .. V .. "])", "%1%2‧%3%4") -- თ‧ა‧ვქ‧უ‧დმ‧ო‧გლ‧ე‧ჯ‧ი‧ლ‧ი
word = gsub(word, "([" .. V .. "])‧([" .. C .. "])([" .. C .. "]+)‧([" .. V .. "])", "%1%2‧%3%4") -- თ‧ავ‧ქუ‧დმ‧ოგ‧ლე‧ჯ‧ი‧ლ‧ი
-- remove hyphens before and after consonants
word = gsub(word, "([" .. C .. "]+)‧([" .. V .. "])", "%1%2") -- თ‧ავ‧ქუდ‧მოგ‧ლე‧ჯ‧ი‧ლ‧ი
word = gsub(word, "([" .. V .. "])‧([" .. C .. "]*)$", "%1%2") -- თავ‧ქუდ‧მოგ‧ლე‧ჯი‧ლი
-- remove hyphens before and after vowels
word = gsub(word, "^([" .. V .. "])‧", "%1") -- ე‧ნა -> ენა
word = gsub(word, "‧([" .. V .. "])$", "%1") -- აუ‧ღი‧ა -> აუ‧ღია
return word
end
return export