Модуль:Песочница/Pok: различия между версиями

мНет описания правки
Нет описания правки
 
(не показана 91 промежуточная версия этого же участника)
Строка 1: Строка 1:
local p = {}
local p = {}
local getArgs = require('Module:Arguments').getArgs


-- Простые правила образования множественного числа
function p.main(frame)
local rules = {
    local args = getArgs(frame, { removeBlanks = false })
     {"ие$", "ие", "ия"},  -- здание -> здания
     local name = args[1] or ""
     {"ка$", "ка", "ки"},  -- собака -> собаки
    local attributes = args[2] or ""
     {"ок$", "ок", "ки"},  -- носок -> носки
     if name == "" then
     {"ец$", "ец", "цы"},  -- молодец -> молодцы
        return "<span class=\"error\">Ошибка: не указано имя файла.</span>"
    {"ье$", "ье", "ья"},  -- зелье -> зелья
     end
     {"о$", "о", "а"},    -- окно -> окна
     local ext = (args["ext"] or "png"):gsub("^%.", "")
     {"е$", "е", "я"},    -- поле -> поля
     local namespace = args["namespace"] or "Файл"
     {"й$", "й", "и"},    -- край -> края
     local max = tonumber(args["max"]) or 50
     {"ь$", "ь", "и"}      -- лошадь -> лошади
     local include_base = (args["base"] ~= "no")
}
 
     local found = {}


-- Функция преобразования в множественное число для каждого слова
    if include_base then
function p.main(frame)
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
    local text = frame.args[1] or ""
        if t and t.exists then
    local words = {}
            table.insert(found, "")
    for word in text:gmatch("%S+") do
         end
         local pluralized = word
    end
        -- Применяем правила для образования множественного числа
 
        for _, rule in ipairs(rules) do
    for i = 1, max do
            if word:match(rule[1]) then
        local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
                pluralized = word:gsub(rule[2].."$", rule[3])
        if t and t.exists then
                break
             table.insert(found, "-" .. i)
             end
         end
         end
        table.insert(words, pluralized)
     end
     end
     return table.concat(words, " ")
 
     if #found == 0 then
        return ""
    end
 
    local before = "[[" .. namespace .. ":" .. name
    local after = "." .. ext .. "|" .. attributes .. "]]"
 
    local parts = {}
    table.insert(parts, "<choose before=\"" .. before .. "\" after=\"" .. after .. "\">")
    for _, suf in ipairs(found) do
        table.insert(parts, "<option>" .. suf .. "</option>")
    end
    table.insert(parts, "</choose>")
 
    return frame:preprocess(table.concat(parts, "\n"))
end
end


return p
return p