モジュール:smi-pro-common
ナビゲーションに移動
検索に移動
このモジュールについての説明文ページを モジュール:smi-pro-common/doc に作成できます
local export = {}
-- Split the word into syllables of C(C)V(V) shape
function export.split_syllables(word)
local syllables = {}
local remainder = word
while remainder ~= "" do
local syll = ""
if mw.ustring.find(remainder, "^([^aeiouāēōë%-]+)") then
syll = syll .. mw.ustring.match(remainder, "^([^aeiouāēōë%-]+)")
remainder = mw.ustring.gsub(remainder, "^([^aeiouāēōë%-]+)", "")
end
if mw.ustring.find(remainder, "^([aeiouāēōë%-]+)") then
syll = syll .. mw.ustring.match(remainder, "^([aeiouāēōë%-]+)")
remainder = mw.ustring.gsub(remainder, "^([aeiouāēōë%-]+)", "")
end
table.insert(syllables, syll)
end
-- Assume that suffixes are attached to words of at least two syllables.
if mw.ustring.find(word, "^%-") then
table.insert(syllables, 1, "")
end
return syllables
end
-- Apply gradation to a word
function export.apply_gradation(word)
local syllables = export.split_syllables(word)
for i, syll in ipairs(syllables) do
-- The first and last consonant do not gradate
if i > 1 then
-- Does the next syllable begin with more than one consonant, or does it contain no vowels (final consonant)?
if i < #syllables and (mw.ustring.find(syllables[i+1], "^[^aeiouāēōë][^aeiouāēōë]") or not mw.ustring.find(syllables[i+1], "[aeiouāēōë]")) then
syll = mw.ustring.gsub(syll, "([^aeiouāēōë])", "%1" .. mw.ustring.char(0x032F))
end
end
syllables[i] = syll
end
return table.concat(syllables, "")
end
return export