Mô đun:ka-hyphen
Giao diện
local export = {}
local vowels = "აეიოუ"
local consonants = "ბგდვზთკლმნპჟრსტფქღყშჩცძწჭხჯჰ" .. "ABCDEF" .. "GHIJKL" --English letters are a hack for a harmonic group stuff
function export.main(frame)
local args = frame:getParent().args
term = args.term or mw.title.getCurrentTitle().text --debugmode or PAGENAME
return export.hyphenateTerm(term)
end
function export.hyphenateTerm(term) --for testing purposes only
local hyphenated = nil
term = mw.ustring.gsub(term, "ფხ", "A")
term = mw.ustring.gsub(term, "თხ", "B")
term = mw.ustring.gsub(term, "ცხ", "C")
term = mw.ustring.gsub(term, "ჩხ", "D")
term = mw.ustring.gsub(term, "ბღ", "E")
term = mw.ustring.gsub(term, "დღ", "F")
term = mw.ustring.gsub(term, "ზღ", "G")
term = mw.ustring.gsub(term, "ჯღ", "H")
term = mw.ustring.gsub(term, "პყ", "I")
term = mw.ustring.gsub(term, "ტყ", "J")
term = mw.ustring.gsub(term, "წყ", "K")
term = mw.ustring.gsub(term, "ჭყ", "L")
hyphenated = mw.ustring.gsub(term, "(["..vowels..consonants .."]+)", hyphenateWord)
hyphenated = mw.ustring.gsub(hyphenated, "A", "ფხ")
hyphenated = mw.ustring.gsub(hyphenated, "B", "თხ")
hyphenated = mw.ustring.gsub(hyphenated, "C", "ცხ")
hyphenated = mw.ustring.gsub(hyphenated, "D", "ჩხ")
hyphenated = mw.ustring.gsub(hyphenated, "E", "ბღ")
hyphenated = mw.ustring.gsub(hyphenated, "F", "დღ")
hyphenated = mw.ustring.gsub(hyphenated, "G", "ზღ")
hyphenated = mw.ustring.gsub(hyphenated, "H", "ჯღ")
hyphenated = mw.ustring.gsub(hyphenated, "I", "პყ")
hyphenated = mw.ustring.gsub(hyphenated, "J", "ტყ")
hyphenated = mw.ustring.gsub(hyphenated, "K", "წყ")
hyphenated = mw.ustring.gsub(hyphenated, "L", "ჭყ")
return hyphenated
end
function hyphenateWord(word)
word = mw.ustring.gsub(word, "(["..vowels.."])", "‧%1‧")
word = mw.ustring.gsub(word, "‧‧", "‧")
if mw.ustring.sub(word, 1, 1) == "‧" then word = mw.ustring.sub(word, 2) end
if mw.ustring.sub(word, -1, -1) == "‧" then word = mw.ustring.sub(word, 1, -2) end
--თ‧ა‧ვქ‧უ‧დმ‧ო‧გლ‧ე‧ჯ‧ი‧ლ‧ი
word = mw.ustring.gsub(word, "(["..vowels.."])‧(["..consonants.."])(["..consonants.."]+)‧(["..vowels.."])", "%1%2‧%3%4")
--თ‧ავ‧ქუ‧დმ‧ოგ‧ლე‧ჯ‧ი‧ლ‧ი
word = mw.ustring.gsub(word, "(["..vowels.."])‧(["..consonants.."])(["..consonants.."]+)‧(["..vowels.."])", "%1%2‧%3%4")
--თ‧ავ‧ქუდ‧მოგ‧ლე‧ჯ‧ი‧ლ‧ი
word = mw.ustring.gsub(word, "(["..consonants.."]+)‧(["..vowels.."])", "%1%2")
--თავ‧ქუდ‧მოგ‧ლე‧ჯი‧ლი
word = mw.ustring.gsub(word, "(["..vowels.."])‧(["..consonants.."]*)$", "%1%2")
--თავ‧ქუდ‧მოგ‧ლე‧ჯი‧ლი
--ე‧ნა to ენა
word = mw.ustring.gsub(word, "^(["..vowels.."])‧", "%1")
--აუ‧ღი‧ა to აუ‧ღია
word = mw.ustring.gsub(word, "‧(["..vowels.."])$", "%1")
return word
end
return export