Модуль:Песочница/Pok: различия между версиями
Pok (обсуждение | вклад) мНет описания правки |
Pok (обсуждение | вклад) мНет описания правки |
||
| Строка 1: | Строка 1: | ||
local p = {} | local p = {} | ||
local rules = { | local rules = { | ||
{"ие$", "ие", "ия"}, -- здание -> здания | {"ие$", "ие", "ия"}, -- здание -> здания | ||
| Строка 8: | Строка 7: | ||
{"ец$", "ец", "цы"}, -- молодец -> молодцы | {"ец$", "ец", "цы"}, -- молодец -> молодцы | ||
{"ье$", "ье", "ья"}, -- зелье -> зелья | {"ье$", "ье", "ья"}, -- зелье -> зелья | ||
{"е$", "е", "я"}, -- поле -> поля | {"е$", "е", "я"}, -- поле -> поля | ||
{"й$", "й", "и"}, -- край -> края | {"й$", "й", "и"}, -- край -> края | ||
| Строка 14: | Строка 12: | ||
} | } | ||
function p.main(frame) | function p.main(frame) | ||
local text = frame.args[1] or "" | local text = frame.args[1] or "" | ||
local words = {} | local words = {} | ||
for word in text:gmatch("%S+") do | for word in text:gmatch("%S+") do | ||
local pluralized = | -- Если слово заканчивается на "о" или "я", оставляем без изменений | ||
if word:match("[оя]$") then | |||
table.insert(words, word) | |||
else | |||
local pluralized = nil | |||
for _, rule in ipairs(rules) do | |||
if word:match(rule[1]) then | |||
pluralized = word:gsub(rule[2].."$", rule[3]) | |||
break | |||
end | |||
end | end | ||
if not pluralized then | |||
pluralized = word .. "ы" | |||
end | |||
table.insert(words, pluralized) | |||
end | end | ||
end | end | ||
return table.concat(words, " ") | return table.concat(words, " ") | ||