Module:tln-conj: Difference between revisions

Nehster9 (talk | contribs)
mNo edit summary
Nehster9 (talk | contribs)
mNo edit summary
Line 194: Line 194:
     local forms = {}
     local forms = {}


local function get_slot_stem(slot)
local function get_slot_stem(args, slot)


     local prefix = mw.ustring.match(slot, "^(.-)_")
     local parts = mw.text.split(slot, "_")


     if args[prefix .. "_stem"] and args[prefix .. "_stem"] ~= "" then
    local mood = nil
        return args[prefix .. "_stem"]
    local tense = nil
    local person_number = nil
 
    -- Detect capital prefix = mood (your convention)
     if mw.ustring.match(parts[1], "^[A-Z]") then
        mood = parts[1]
        tense = parts[2]
        person_number = parts[3]
    else
        tense = parts[1]
        person_number = parts[2]
    end
 
    local person = person_number:sub(1,1)
    local number = person_number:sub(2,2)
 
    -- priority list (MOST specific → LEAST specific)
    local candidates = {}
 
    if mood then
        table.insert(candidates, mood .. "_" .. tense .. "_" .. person_number .. "_stem")
        table.insert(candidates, mood .. "_" .. tense .. "_" .. person .. "_stem")
        table.insert(candidates, mood .. "_" .. tense .. "_" .. number .. "_stem")
        table.insert(candidates, mood .. "_" .. tense .. "_stem")
        table.insert(candidates, mood .. "_stem")
    end
 
    table.insert(candidates, tense .. "_" .. person_number .. "_stem")
    table.insert(candidates, tense .. "_" .. person .. "_stem")
    table.insert(candidates, tense .. "_" .. number .. "_stem")
    table.insert(candidates, tense .. "_stem")
 
    table.insert(candidates, "stem")
 
    for _, key in ipairs(candidates) do
        if args[key] and args[key] ~= "" then
            return args[key]
        end
     end
     end


Line 211: Line 248:


     else
     else
         local slot_stem = get_slot_stem(slot)
         local slot_stem = get_slot_stem(args, slot)
         forms[slot] = combine(slot_stem, ending)
         forms[slot] = combine(slot_stem, ending)