--Adapted from ]
local export = {}
local lang = require("Module:languages").getByCode("rsk")
local m_links = require("Module:links")
local m_table = require("Module:table")
local m_string_utilities = require("Module:string utilities")
local m_uk_translit = require("Module:rue-translit")
local u = mw.ustring.char
local rsplit = mw.text.split
local rfind = mw.ustring.find
local rmatch = mw.ustring.match
local rsubn = mw.ustring.gsub
local ulen = mw.ustring.len
local ulower = mw.ustring.lower
-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
local retval = rsubn(term, foo, bar)
return retval
end
export.VAR1 = u(0xFFF0)
export.VAR2 = u(0xFFF1)
export.VAR3 = u(0xFFF2)
export.var_code_c = ""
export.vowel = "аеиоуяєїюАЕИОУЯЄЇЮ"
export.vowel_c = ""
export.cons_c = ""
function export.translit_no_links(text)
return m_uk_translit.tr(m_links.remove_links(text))
end
function export.remove_variant_codes(word)
return rsub(word, export.var_code_c, "")
end
-- Check if word is monosyllabic (also includes words without vowels).
function export.is_monosyllabic(word)
local num_syl = ulen(rsub(word, export.cons_c, ""))
return num_syl <= 1
end
-- Check if word ends in a vowel.
function export.ends_in_vowel(stem)
return rfind(stem, export.vowel_c .. "$")
end
-- Given a list of forms (each of which is a table of the form {form=FORM, footnotes=FOOTNOTES}),
-- concatenate into a SLOT=FORM,FORM,... string, replacing embedded | signs with <!>. (unused for now)
function export.concat_forms_in_slot(forms)
if forms then
local new_vals = {}
for _, v in ipairs(forms) do
table.insert(new_vals, rsub(v.form, "|", "<!>"))
end
return table.concat(new_vals, ",")
else
return nil
end
end
function export.combine_stem_ending(stem, ending)
if stem == "?" then
return "?"
else
return rsub(stem .. ending, "(" .. export.vowel_c .. ")ь", "%1й")
end
end
function export.generate_form(form, footnotes)
if type(footnotes) == "string" then
footnotes = {footnotes}
end
if footnotes then
return {form = form, footnotes = footnotes}
else
return form
end
end
function export.apply_palatalization(stem)
local palat_pairs = { = "дз", = "ц", = "ж", = "ш"}
return rsub(stem, "()$", function(letter) return palat_pairs end)
end
function export.apply_vowel_alternation(alt, stem)
local modstem, origvowel
if alt == "quant" or alt == "quant-ě" then
-- ] "snow", gen sg. ]
-- ] "snow", gen pl. ]
-- ] "cane", gen sg. ]
-- ] "work", ins sg. ]
modstem = rsub(stem, "(.)()(" .. export.cons_c .. "*)$",
function(pre, vowel, post)
origvowel = vowel
if vowel == "í" then
if alt == "quant-ě" then
if rfind(pre, "$") then
return pre .. "ě" .. post
else
return pre .. "e" .. post
end
else
return pre .. "i" .. post
end
elseif vowel == "ů" then
return pre .. "o" .. post
elseif vowel == "é" then
return pre .. "e" .. post
else
return pre .. "a" .. post
end
end
)
-- ] "mushroom", gen pl. ]
modstem = rsub(modstem, "ou(" .. export.cons_c .. "*)$", "u%1")
if modstem == stem then
error("Indicator '" .. alt .. "' can't be applied because stem '" .. stem .. "' doesn't have an í, ů, ou, á or é as its last vowel")
end
else
return stem, nil
end
return modstem, origvowel
end
return export