Module:tln-conj: Difference between revisions

From Linguifex
Jump to navigation Jump to search
Nehster9 (talk | contribs)
mNo edit summary
Nehster9 (talk | contribs)
mNo edit summary
 
(14 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
----------------------------------------------------------------
-- ENDINGS
----------------------------------------------------------------


local endings = {
local endings = {
     are = {
     are = {
         pres_1s = "§1S_ARE§",
         pres_1s = "",
         pres_2s = "§2S_ARE§",
         pres_2s = "ᠠᠰ",
         pres_3s = "§3S_ARE§",
         pres_3s = "ᠠᠲ",
         pres_1p = "§1P_ARE§",
         pres_1p = "ᠠᠨᠤᠰ",
         pres_2p = "§2P_ARE§",
         pres_2p = "ᠠᠵᠢᠰ",
         pres_3p = "§3P_ARE§"
         pres_3p = "ᠠᠨ",
 
        imperf_1s = "ᠠᠨ",
        imperf_2s = "ᠠᠰ",
        imperf_3s = "ᠠᠲ",
        imperf_1p = "ᠠᠨᠤᠰ",
        imperf_2p = "ᠠᠵᠢᠰ",
        imperf_3p = "ᠠᠨ",
 
        past_1s = "ᠠᠢ",
        past_2s = "ᠠᠢᠰᠲᠢ",
        past_3s = "ᠠᠢᠲ",
        past_1p = "ᠠᠢᠨᠤᠰ",
        past_2p = "ᠠᠢᠰᠲᠢᠰ",
        past_3p = "ᠡᠷᠤᠨ",
       
        fut_1s = "ᠠᠷᠢᠣ",
        fut_2s = "ᠠᠷᠡᠰ",
        fut_3s = "ᠠᠷᠡᠲ",
        fut_1p = "ᠠᠷᠡᠨᠤᠰ",
        fut_2p = "ᠠᠷᠡᠵᠢᠰ",
        fut_3p = "ᠠᠷᠡᠨ"
       
     },
     },


Line 16: Line 42:
         pres_3s = "ᠡᠲ",
         pres_3s = "ᠡᠲ",
         pres_1p = "ᠡᠨᠤᠰ",
         pres_1p = "ᠡᠨᠤᠰ",
         pres_2p = "ᠡᠴᠢᠰ",
         pres_2p = "ᠡᠵᠢᠰ",
         pres_3p = "ᠡᠨ"
         pres_3p = "ᠡᠨ",
 
        imperf_1s = "ᠠᠨ",
        imperf_2s = "ᠠᠰ",
        imperf_3s = "ᠠᠲ",
        imperf_1p = "ᠠᠨᠤᠰ",
        imperf_2p = "ᠠᠵᠢᠰ",
        imperf_3p = "ᠠᠨ",
 
        past_1s = "ᠢ",
        past_2s = "ᠢᠰᠲᠢ",
        past_3s = "ᠢᠲ",
        past_1p = "ᠢᠨᠤᠰ",
        past_2p = "ᠢᠰᠲᠢᠰ",
        past_3p = "ᠡᠷᠤᠨ",
       
        fut_1s = "ᠡᠷᠢᠣ",
        fut_2s = "ᠡᠷᠡᠰ",
        fut_3s = "ᠡᠷᠡᠲ",
        fut_1p = "ᠡᠷᠡᠨᠤᠰ",
        fut_2p = "ᠡᠷᠡᠵᠢᠰ",
        fut_3p = "ᠡᠷᠡᠨ"
     },
     },


     ire = {
     ire = {
         pres_1s = "§1S_IRE§",
         pres_1s = "",
         pres_2s = "§2S_IRE§",
         pres_2s = "ᠢᠰ",
         pres_3s = "§3S_IRE§",
         pres_3s = "ᠢᠲ",
         pres_1p = "§1P_IRE§",
         pres_1p = "ᠢᠨᠤᠰ",
         pres_2p = "§2P_IRE§",
         pres_2p = "ᠢᠵᠢᠰ",
         pres_3p = "§3P_IRE§"
         pres_3p = "ᠢᠤᠨ",
       
        imperf_1s = "ᠢᠠᠨ",
        imperf_2s = "ᠢᠠᠰ",
        imperf_3s = "ᠢᠠᠲ",
        imperf_1p = "ᠢᠠᠨᠤᠰ",
        imperf_2p = "ᠢᠠᠵᠢᠰ",
        imperf_3p = "ᠢᠠᠨ",
 
        past_1s = "ᠢ",
        past_2s = "ᠢᠰᠲᠢ",
        past_3s = "ᠢᠲ",
        past_1p = "ᠢᠨᠤᠰ",
        past_2p = "ᠢᠰᠲᠢᠰ",
        past_3p = "ᠢᠡᠷᠤᠨ",
       
        fut_1s = "ᠢᠷᠢᠣ",
        fut_2s = "ᠢᠷᠡᠰ",
        fut_3s = "ᠢᠷᠡᠲ",
        fut_1p = "ᠢᠷᠡᠨᠤᠰ",
        fut_2p = "ᠢᠷᠡᠵᠢᠰ",
        fut_3p = "ᠢᠷᠡᠨ"
     }
     }
}
}
----------------------------------------------------------------
-- CLASS DETECTION
----------------------------------------------------------------


local function detect_class(title)
local function detect_class(title)
     if mw.ustring.match(title, "ᠠᠷᠡ$") then
     if mw.ustring.match(title, "ᠠᠷᠡ$") then
         return "are"
         return "are"
     elseif mw.ustring.match(title, "ᠡᠷᠡ$") then
     elseif mw.ustring.match(title, "ᠡᠷᠡ$") then
         return "ere"
         return "ere"
     elseif mw.ustring.match(title, "ᠢᠷᠡ$") then
     elseif mw.ustring.match(title, "ᠢᠷᠡ$") then
         return "ire"
         return "ire"
     end
     end
     return nil
     return nil
end
end


local function get_stem(title, class)
local function get_stem(title, class)
     if class == "are" then
     if class == "are" then
         return mw.ustring.gsub(title, "ᠠᠷᠡ$", "")
         return mw.ustring.gsub(title, "ᠠᠷᠡ$", "")
     elseif class == "ere" then
     elseif class == "ere" then
         return mw.ustring.gsub(title, "ᠡᠷᠡ$", "")
         return mw.ustring.gsub(title, "ᠡᠷᠡ$", "")
     elseif class == "ire" then
     elseif class == "ire" then
         return mw.ustring.gsub(title, "ᠢᠷᠡ$", "")
         return mw.ustring.gsub(title, "ᠢᠷᠡ$", "")
     end
     end
     return title
     return title
end
end
----------------------------------------------------------------
-- TRANSLITERATION
----------------------------------------------------------------


local translit = {
local translit = {
Line 72: Line 140:
     ["ᠲ"] = "t",
     ["ᠲ"] = "t",
     ["ᠨ"] = "n",
     ["ᠨ"] = "n",
     [""] = "c",
     ["ᠴ"] = "č",
     [""] = "č"
    ["ᠶ"] = "y",
     [""] = "d"
}
}


local function romanize(text)
local function romanize(text)
     local result = text
     local result = text
     for bichig, latin in pairs(translit) do
     for bichig, latin in pairs(translit) do
         result = mw.ustring.gsub(result, bichig, latin)
         result = mw.ustring.gsub(result, bichig, latin)
     end
     end
     return result
     return result
end
end


local function make_link(form)
----------------------------------------------------------------
-- DISPLAY HELPERS
----------------------------------------------------------------


     return
local function make_cell(form)
        '<div style="text-align:center;">'
     return "<div style='text-align:center;'>"
         .. "[[" .. form .. "]]"
         .. "[[Contionary:" .. form .. "|" .. form .. "]]"
         .. "<br />"
         .. "<br /><span style='color:#777777; font-size:90%;'>"
        .. "<span style='color:#777777; font-size:90%;'>"
         .. romanize(form)
         .. romanize(form)
         .. "</span>"
         .. "</span></div>"
         .. "</div>"
end
 
local function combine(stem, ending)
 
    if mw.ustring.match(stem, "ᠶ$") and
      mw.ustring.match(ending, "^ᠢ") then
 
         ending = mw.ustring.gsub(ending, "^ᠢ", "")
    end
 
    return stem .. ending
end
end
----------------------------------------------------------------
-- MAIN FUNCTION
----------------------------------------------------------------


function p.show(frame)
function p.show(frame)


     local args = frame:getParent().args
     local args = frame:getParent().args
     local title = mw.title.getCurrentTitle().text
     local title = mw.title.getCurrentTitle().text


     local class = args.class or detect_class(title)
     local class = args.class or detect_class(title)
     if not class then
     if not class then
         return "Error: could not determine conjugation class."
         return "Error: could not determine conjugation class."
Line 116: Line 195:


     for slot, ending in pairs(endings[class]) do
     for slot, ending in pairs(endings[class]) do
         if args[slot] and args[slot] ~= "" then
         if args[slot] and args[slot] ~= "" then
             forms[slot] = args[slot]
             forms[slot] = args[slot]
         else
         else
             forms[slot] = stem .. ending
             forms[slot] = combine(stem, ending)
         end
         end
    end
    local text =
        '{| class="wikitable mw-collapsible mw-collapsed"\n'
        .. '|+ Conjugation of [[Contionary:' .. title .. '|' .. title .. ']] (<span style="color:#777777;">' .. romanize(title) .. '</span>)\n'
        ----------------------------------------------------------------
        -- HEADER
        ----------------------------------------------------------------
        .. '|-\n'
        .. '! Mood !! Tense !! colspan="3" | Singular !! colspan="3" | Plural\n'
        .. '|-\n'
        .. '!  !!  !! 1st !! 2nd !! 3rd !! 1st !! 2nd !! 3rd\n'


    end
        ----------------------------------------------------------------
        -- PRESENT
        ----------------------------------------------------------------
 
        .. '|-\n'
        .. '! rowspan="4" | Indicative\n'
        .. '! Present\n'
        .. '| ' .. make_cell(forms.pres_1s)
        .. ' || ' .. make_cell(forms.pres_2s)
        .. ' || ' .. make_cell(forms.pres_3s)
        .. ' || ' .. make_cell(forms.pres_1p)
        .. ' || ' .. make_cell(forms.pres_2p)
        .. ' || ' .. make_cell(forms.pres_3p)
        .. '\n'
 
        ----------------------------------------------------------------
        -- IMPERFECT
        ----------------------------------------------------------------
 
        .. '|-\n'
        .. '! Imperfect\n'
        .. '| ' .. make_cell(forms.imperf_1s)
        .. ' || ' .. make_cell(forms.imperf_2s)
        .. ' || ' .. make_cell(forms.imperf_3s)
        .. ' || ' .. make_cell(forms.imperf_1p)
        .. ' || ' .. make_cell(forms.imperf_2p)
        .. ' || ' .. make_cell(forms.imperf_3p)
        .. '\n'


local text =
        ----------------------------------------------------------------
    "'''Conjugation of [[" .. title .. "]]''' (''"
        -- PAST
    .. romanize(title)
        ----------------------------------------------------------------
    .. "'')\n\n"
    .. '{| class="wikitable mw-collapsible mw-collapsed"\n'
    .. '|+ Present indicative\n'


    -- header row 1
        .. '|-\n'
    .. '|-\n'
        .. '! Past\n'
    .. '! rowspan="2" | Mood\n'
        .. '| ' .. make_cell(forms.past_1s)
    .. '! rowspan="2" | Tense\n'
        .. ' || ' .. make_cell(forms.past_2s)
    .. '! colspan="3" | Singular\n'
        .. ' || ' .. make_cell(forms.past_3s)
    .. '! colspan="3" | Plural\n'
        .. ' || ' .. make_cell(forms.past_1p)
        .. ' || ' .. make_cell(forms.past_2p)
        .. ' || ' .. make_cell(forms.past_3p)
        .. '\n'
       
        ----------------------------------------------------------------
        -- FUTURE
        ----------------------------------------------------------------


    -- header row 2
        .. '|-\n'
    .. '|-\n'
        .. '! Future\n'
    .. '! 1st !! 2nd !! 3rd !! 1st !! 2nd !! 3rd\n'
        .. '| ' .. make_cell(forms.fut_1s)
        .. ' || ' .. make_cell(forms.fut_2s)
        .. ' || ' .. make_cell(forms.fut_3s)
        .. ' || ' .. make_cell(forms.fut_1p)
        .. ' || ' .. make_cell(forms.fut_2p)
        .. ' || ' .. make_cell(forms.fut_3p)
        .. '\n'


    -- body
        .. '|}'
    .. '|-\n'
    .. '! Indicative\n'
    .. '! Present\n'
    .. '| ' .. make_link(forms.pres_1s)
    .. ' || ' .. make_link(forms.pres_2s)
    .. ' || ' .. make_link(forms.pres_3s)
    .. ' || ' .. make_link(forms.pres_1p)
    .. ' || ' .. make_link(forms.pres_2p)
    .. ' || ' .. make_link(forms.pres_3p)
    .. '\n'
    .. '|}'


     return text
     return text

Latest revision as of 17:16, 20 June 2026



local p = {}

----------------------------------------------------------------
-- ENDINGS
----------------------------------------------------------------

local endings = {
    are = {
        pres_1s = "ᠣ",
        pres_2s = "ᠠᠰ",
        pres_3s = "ᠠᠲ",
        pres_1p = "ᠠᠨᠤᠰ",
        pres_2p = "ᠠᠵᠢᠰ",
        pres_3p = "ᠠᠨ",

        imperf_1s = "ᠠᠨ",
        imperf_2s = "ᠠᠰ",
        imperf_3s = "ᠠᠲ",
        imperf_1p = "ᠠᠨᠤᠰ",
        imperf_2p = "ᠠᠵᠢᠰ",
        imperf_3p = "ᠠᠨ",

        past_1s = "ᠠᠢ",
        past_2s = "ᠠᠢᠰᠲᠢ",
        past_3s = "ᠠᠢᠲ",
        past_1p = "ᠠᠢᠨᠤᠰ",
        past_2p = "ᠠᠢᠰᠲᠢᠰ",
        past_3p = "ᠡᠷᠤᠨ",
        
        fut_1s = "ᠠᠷᠢᠣ",
        fut_2s = "ᠠᠷᠡᠰ",
        fut_3s = "ᠠᠷᠡᠲ",
        fut_1p = "ᠠᠷᠡᠨᠤᠰ",
        fut_2p = "ᠠᠷᠡᠵᠢᠰ",
        fut_3p = "ᠠᠷᠡᠨ"
        
    },

    ere = {
        pres_1s = "ᠣ",
        pres_2s = "ᠡᠰ",
        pres_3s = "ᠡᠲ",
        pres_1p = "ᠡᠨᠤᠰ",
        pres_2p = "ᠡᠵᠢᠰ",
        pres_3p = "ᠡᠨ",

        imperf_1s = "ᠠᠨ",
        imperf_2s = "ᠠᠰ",
        imperf_3s = "ᠠᠲ",
        imperf_1p = "ᠠᠨᠤᠰ",
        imperf_2p = "ᠠᠵᠢᠰ",
        imperf_3p = "ᠠᠨ",

        past_1s = "ᠢ",
        past_2s = "ᠢᠰᠲᠢ",
        past_3s = "ᠢᠲ",
        past_1p = "ᠢᠨᠤᠰ",
        past_2p = "ᠢᠰᠲᠢᠰ",
        past_3p = "ᠡᠷᠤᠨ",
        
        fut_1s = "ᠡᠷᠢᠣ",
        fut_2s = "ᠡᠷᠡᠰ",
        fut_3s = "ᠡᠷᠡᠲ",
        fut_1p = "ᠡᠷᠡᠨᠤᠰ",
        fut_2p = "ᠡᠷᠡᠵᠢᠰ",
        fut_3p = "ᠡᠷᠡᠨ"
    },

    ire = {
        pres_1s = "ᠣ",
        pres_2s = "ᠢᠰ",
        pres_3s = "ᠢᠲ",
        pres_1p = "ᠢᠨᠤᠰ",
        pres_2p = "ᠢᠵᠢᠰ",
        pres_3p = "ᠢᠤᠨ",
        
        imperf_1s = "ᠢᠠᠨ",
        imperf_2s = "ᠢᠠᠰ",
        imperf_3s = "ᠢᠠᠲ",
        imperf_1p = "ᠢᠠᠨᠤᠰ",
        imperf_2p = "ᠢᠠᠵᠢᠰ",
        imperf_3p = "ᠢᠠᠨ",

        past_1s = "ᠢ",
        past_2s = "ᠢᠰᠲᠢ",
        past_3s = "ᠢᠲ",
        past_1p = "ᠢᠨᠤᠰ",
        past_2p = "ᠢᠰᠲᠢᠰ",
        past_3p = "ᠢᠡᠷᠤᠨ",
        
        fut_1s = "ᠢᠷᠢᠣ",
        fut_2s = "ᠢᠷᠡᠰ",
        fut_3s = "ᠢᠷᠡᠲ",
        fut_1p = "ᠢᠷᠡᠨᠤᠰ",
        fut_2p = "ᠢᠷᠡᠵᠢᠰ",
        fut_3p = "ᠢᠷᠡᠨ"
    }
}

----------------------------------------------------------------
-- CLASS DETECTION
----------------------------------------------------------------

local function detect_class(title)
    if mw.ustring.match(title, "ᠠᠷᠡ$") then
        return "are"
    elseif mw.ustring.match(title, "ᠡᠷᠡ$") then
        return "ere"
    elseif mw.ustring.match(title, "ᠢᠷᠡ$") then
        return "ire"
    end
    return nil
end

local function get_stem(title, class)
    if class == "are" then
        return mw.ustring.gsub(title, "ᠠᠷᠡ$", "")
    elseif class == "ere" then
        return mw.ustring.gsub(title, "ᠡᠷᠡ$", "")
    elseif class == "ire" then
        return mw.ustring.gsub(title, "ᠢᠷᠡ$", "")
    end
    return title
end

----------------------------------------------------------------
-- TRANSLITERATION
----------------------------------------------------------------

local translit = {
    ["ᠠ"] = "a",
    ["ᠡ"] = "e",
    ["ᠢ"] = "i",
    ["ᠣ"] = "o",
    ["ᠤ"] = "u",
    ["ᠷ"] = "r",
    ["ᠸ"] = "v",
    ["ᠵ"] = "z",
    ["ᠰ"] = "s",
    ["ᠲ"] = "t",
    ["ᠨ"] = "n",
    ["ᠴ"] = "č",
    ["ᠶ"] = "y",
    ["ᠳ"] = "d"
}

local function romanize(text)
    local result = text
    for bichig, latin in pairs(translit) do
        result = mw.ustring.gsub(result, bichig, latin)
    end
    return result
end

----------------------------------------------------------------
-- DISPLAY HELPERS
----------------------------------------------------------------

local function make_cell(form)
    return "<div style='text-align:center;'>"
        .. "[[Contionary:" .. form .. "|" .. form .. "]]"
        .. "<br /><span style='color:#777777; font-size:90%;'>"
        .. romanize(form)
        .. "</span></div>"
end

local function combine(stem, ending)

    if mw.ustring.match(stem, "ᠶ$") and
       mw.ustring.match(ending, "^ᠢ") then

        ending = mw.ustring.gsub(ending, "^ᠢ", "ᠡ")
    end

    return stem .. ending
end

----------------------------------------------------------------
-- MAIN FUNCTION
----------------------------------------------------------------

function p.show(frame)

    local args = frame:getParent().args
    local title = mw.title.getCurrentTitle().text

    local class = args.class or detect_class(title)
    if not class then
        return "Error: could not determine conjugation class."
    end

    local stem = get_stem(title, class)

    local forms = {}

    for slot, ending in pairs(endings[class]) do
        if args[slot] and args[slot] ~= "" then
            forms[slot] = args[slot]
        else
            forms[slot] = combine(stem, ending)
        end
    end

    local text =
        '{| class="wikitable mw-collapsible mw-collapsed"\n'
        .. '|+ Conjugation of [[Contionary:' .. title .. '|' .. title .. ']] (<span style="color:#777777;">' .. romanize(title) .. '</span>)\n'

        ----------------------------------------------------------------
        -- HEADER
        ----------------------------------------------------------------

        .. '|-\n'
        .. '! Mood !! Tense !! colspan="3" | Singular !! colspan="3" | Plural\n'

        .. '|-\n'
        .. '!  !!  !! 1st !! 2nd !! 3rd !! 1st !! 2nd !! 3rd\n'

        ----------------------------------------------------------------
        -- PRESENT
        ----------------------------------------------------------------

        .. '|-\n'
        .. '! rowspan="4" | Indicative\n'
        .. '! Present\n'
        .. '| ' .. make_cell(forms.pres_1s)
        .. ' || ' .. make_cell(forms.pres_2s)
        .. ' || ' .. make_cell(forms.pres_3s)
        .. ' || ' .. make_cell(forms.pres_1p)
        .. ' || ' .. make_cell(forms.pres_2p)
        .. ' || ' .. make_cell(forms.pres_3p)
        .. '\n'

        ----------------------------------------------------------------
        -- IMPERFECT
        ----------------------------------------------------------------

        .. '|-\n'
        .. '! Imperfect\n'
        .. '| ' .. make_cell(forms.imperf_1s)
        .. ' || ' .. make_cell(forms.imperf_2s)
        .. ' || ' .. make_cell(forms.imperf_3s)
        .. ' || ' .. make_cell(forms.imperf_1p)
        .. ' || ' .. make_cell(forms.imperf_2p)
        .. ' || ' .. make_cell(forms.imperf_3p)
        .. '\n'

        ----------------------------------------------------------------
        -- PAST
        ----------------------------------------------------------------

        .. '|-\n'
        .. '! Past\n'
        .. '| ' .. make_cell(forms.past_1s)
        .. ' || ' .. make_cell(forms.past_2s)
        .. ' || ' .. make_cell(forms.past_3s)
        .. ' || ' .. make_cell(forms.past_1p)
        .. ' || ' .. make_cell(forms.past_2p)
        .. ' || ' .. make_cell(forms.past_3p)
        .. '\n'
        
        ----------------------------------------------------------------
        -- FUTURE
        ----------------------------------------------------------------

        .. '|-\n'
        .. '! Future\n'
        .. '| ' .. make_cell(forms.fut_1s)
        .. ' || ' .. make_cell(forms.fut_2s)
        .. ' || ' .. make_cell(forms.fut_3s)
        .. ' || ' .. make_cell(forms.fut_1p)
        .. ' || ' .. make_cell(forms.fut_2p)
        .. ' || ' .. make_cell(forms.fut_3p)
        .. '\n'

        .. '|}'

    return text
end

return p