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

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


local rules = {
function p.main(frame)
    {"ия$", "ия", "ии"},     -- стратегия -> стратегии
    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 = {}
     {"е$", "е", "я"},        -- поле -> поля
     {"й$", "й", "и"},        -- край -> края
    {"ь$", "ь", "и"},        -- лошадь -> лошади
     {"о$", "о", "а"}        -- окно -> окна
}


function p.main(frame)
    if include_base then
    local text = frame.args[1] or ""
        local t = mw.title.new("Файл:" .. name .. "." .. ext)
    local words = {}
         if t and t.exists then
    for word in text:gmatch("%S+") do
             table.insert(found, "")
        -- Если слово заканчивается на "о" или "я", оставляем без изменений,
         end
        -- за исключением случаев, когда слово оканчивается на "мя" (например, "время")
    end
         if word:match("[оя]$") and not word:match("мя$") then
 
             table.insert(words, word)
    for i = 1, max do
         else
        local t = mw.title.new("Файл:" .. name .. "-" .. i .. "." .. ext)
            local pluralized = nil
        if t and t.exists then
            for _, rule in ipairs(rules) do
             table.insert(found, "-" .. i)
                if word:match(rule[1]) then
                    pluralized = word:gsub(rule[2] .. "$", rule[3])
                    break
                end
            end
            if not pluralized then
                pluralized = word .. "ы"
            end
             table.insert(words, pluralized)
         end
         end
     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