Module:Declension

Si Wikipedia, tasanayt tilellit.

La documentation pour ce module peut être créée à Module:Declension/doc

local p = {}

local invariant_words = { ["tala"] = true, ["taddart"] = true, }

function isVowel(character)
    for _, c in pairs({ 'a', 'i', 'u'}) do
        if c == character then
            return true
        end
    end

    return false
end

function isConsonant(c)
    return not isVowel(c) and c ~= 'e'
end

function p.annexed(full_word)
    if type(full_word) == "table" then full_word = full_word.args[1] end
    if full_word == nil or full_word == '' then return end

    if mw.ustring.len(full_word) < 2 then return full_word end
    
    local tb = mw.text.split(full_word, " ")
    local word = tb[1];
    
    word = mw.ustring.lower(word)

    if invariant_words[word] then return full_word end

    local result = nil

    c0 = mw.ustring.sub(word, 1, 1)
    c1 = mw.ustring.sub(word, 2, 2)
    c2 = mw.ustring.sub(word, 3, 3)
    c3 = mw.ustring.sub(word, 4, 4)
    
    wordSubstring1 =  mw.ustring.sub(word, 2, mw.ustring.len(word))
    wordSubstring2 = mw.ustring.sub(word, 3, mw.ustring.len(word))

    if c0 == 'a' and isConsonant(c1) then
        if mw.ustring.len(word) == 2 then
            result = "wa" .. wordSubstring1
        elseif isConsonant(c2) then
            result = "we" .. wordSubstring1
        elseif isVowel(c2) then
            result = "wa" .. wordSubstring1
        elseif c2 == 'e' then
            result = "u" .. wordSubstring1
        end
    elseif c0 == 'u' and isConsonant(c1) then
        result = "wu" .. wordSubstring1
    elseif c0 == 'i' and isConsonant(c1) then
        if mw.ustring.len(word) == 2 then
            result = "yi" .. wordSubstring1
        elseif isConsonant(c2) then
            result = "ye" .. wordSubstring1
        else
            result = "yi" .. wordSubstring1
        end
    end

    if result == nil and mw.ustring.len(word) < 4 then
        return full_word
    end

    if c0 == 't' and (c1 == 'a' or c1 == 'i') then
        if c3 == 'e' then
            result = "t" .. wordSubstring2
        else
            result = "te" .. wordSubstring2
        end

        if isConsonant(c3) then
            result = "te" .. wordSubstring2
        else
            result = "t" .. wordSubstring2
        end
    end
    
    tb[1]= result or word

    return mw.text.listToText(tb, " ", " ")
end

function p.feminine(full_word)
    if type(full_word) == "table" then full_word = full_word.args[1] end
    if full_word == nil or full_word == '' then return end

    if mw.ustring.len(full_word) < 2 then return full_word end
    
    local tb = mw.text.split(full_word, " ")
    local word = tb[1];
    
    word = mw.ustring.lower(word)

    local result = nil

    c0 = mw.ustring.sub(word, 1, 1)

    if isVowel(c0) then
        result = "t" .. word.. "t"
    end
    
    tb[1]= result or word

    return mw.text.listToText(tb, " ", " ")
end

function p.annexed_feminine(word)
	return p.annexed(p.feminine(word)) 
end

function p.main(word)
	mw.log(p.annexed_feminine(word)) 
end

return p