모듈:ru-common

위키낱말사전, 말과 글의 누리

이 모듈에 대한 설명문서는 모듈:ru-common/설명문서에서 만들 수 있습니다

--[[
This module holds some commonly used functions for Russian language. It's for use from other modules, not #invoke.
]]

local export = {}

-- this function enables the module to be called from a template
function export.main(frame)
    if type(export[frame.args[1]]) == 'function' then
        return export[frame.args[1]](frame.args[2], frame.args[3])
    else
        return export[frame.args[1]][frame.args[2]]
    end
end

function export.obo(phr) -- selects preposition о, об or обо for next phrase, which can start from punctuation
    --Algorithm design is mainly inherited from w:ru:template:Обо
    local w = mw.ustring.match(phr,"[%p%s%c]*(.-)[%p%s%c]") or mw.ustring.match(phr,"[%p%s%c]*(.-)$")
    if not w then return nil end
    if string.find(" всей всём всех мне ",' '..mw.ustring.lower(w)..' ',1,true) then return 'обо' end
    local ws=mw.ustring.sub(w,1,2)
    if ws==mw.ustring.upper(ws) then -- abbrev
        if mw.ustring.match(ws,"^[ЙУНФЫАРОЛЭСМИRYUIOASFHLXNMÖÜÄΑΕΟΥΩ]") then return 'об' else return 'о' end
    elseif mw.ustring.match(mw.ustring.upper(w),"^[АОЭИУЫAOIEÖÜÄΑΕΟΥΩ]") then
        return 'об'
    else
        return 'о'
    end
end

-- Apply Proto-Slavic iotation. This is the change that is affected by a Slavic -j- after a consonant.
function export.iotation(stem, shch)
    stem = mw.ustring.gsub(stem, "[сх]$", "ш")
    stem = mw.ustring.gsub(stem, "ск$", "щ")
    stem = mw.ustring.gsub(stem, "ст$", "щ")
    stem = mw.ustring.gsub(stem, "[кц]$", "ч")
    
    -- normally "т" is iotated as "ч" but there are many verbs that are iotated with "щ"
    if shch == "щ" then
        stem = mw.ustring.gsub(stem, "т$", "щ")
    else
        stem = mw.ustring.gsub(stem, "т$", "ч")
    end
 
    stem = mw.ustring.gsub(stem, "[гдз]$", "ж")
    
    stem = mw.ustring.gsub(stem, "([бвмпф])$", "%1л")
    
    return stem
end

function export.needs_accents(word)
	-- A word that has ё in it doesn't need an accent, as this vowel is inherently accented.
	if mw.ustring.find(word, "\204\129") or mw.ustring.find(word, "ё") then
		return false
	-- A word needs accents if it contains more than one vowel
	elseif mw.ustring.find(mw.ustring.lower(word), "[аоуыэяёюиеіѣѵ].*[аоуыэяёюиеіѣѵ]") then
		return true
	else
		return false
	end
end

function export.remove_accents(word)
    -- Remove acute accent
    word = mw.ustring.gsub(word, "́", "")
            
    return word
end

local destresser = {
    ["́"] = "",
    ["̀"] = "",
    ["̈"] = "",
    ["ё"] = "е",
}

function export.make_unstressed(word)
    return mw.ustring.gsub(word, "[̀́̈ё]", destresser)
end

function export.make_unstressed_once(word)
    return mw.ustring.gsub(word, "([̀́̈ё])([^́̀̈ё]*)$", function(x, rest) return destresser[x] .. rest; end, 1)
end

return export