Module:kilta-headword: Difference between revisions

no edit summary
No edit summary
No edit summary
(33 intermediate revisions by the same user not shown)
Line 17: Line 17:
end
end


local function plural(word)
local function plural(word, n, pos)
local pl = {}
local w = split(word, " ")
n = tonumber(n)
if n > #w then error("Word index outside bounds.") end
if word:match("[kh]wa$") or word:match("a$") then
if pos == "n" then
pl = {sub(word, 1, -1) .. "úr"}
if w[n]:match("[kh]wa$") or w[n]:match("a$") then
elseif word:match("ës$") or word:match("uin$") or word:match("[str]$") then
w[n] = sub(w[n], 1, -1) .. "úr"
pl = {word .. "á"}
elseif w[n]:match("ës$") or w[n]:match("uin$") or w[n]:match("[str]$") then
elseif word:match("[nml]$") then
w[n] = w[n] .. "á"
pl = {word .. "ur"}
elseif w[n]:match("[nml]$") then
w[n] = w[n] .. "ur"
end
elseif pos == "adj" then
if w[n]:match("[kh]win$") then
w[n] = sub(w[n], 1, -4) .. "ú"
elseif w[n]:match("in$") then
w[n] = sub(w[n], 1, -3) .. "u"
end
end
end
pl.label = "plural"
return {label = "plural", table.concat(w, " ")}
return pl
end
end


Line 38: Line 47:
["pl"] = {list = true},
["pl"] = {list = true},
["w"] = {default = mw.title.getCurrentTitle().text},
["w"] = {default = mw.title.getCurrentTitle().text},
["n"] = {type = number}
["n"] = {type = number, default = 1}
}
}
Line 45: Line 54:
local pos = args[1]; local pl = args.pl
local pos = args[1]; local pl = args.pl
local data = {lang = lang, pos_category = deabb[pos], heads = {word}, categories = {}, inflections = {},}
local data = {lang = lang, pos_category = deabb[pos], heads = {word}, categories = {}, inflections = {},}
 
local w = split(word, "[^%s]*")
if pl[1] == '-' then
if pl[1] == '-' then
Line 61: Line 69:
table.insert(data.inflections, pl)
table.insert(data.inflections, pl)
else
else
table.insert(data.inflections, plural(#w > 1 and w[args.n] or word))
table.insert(data.inflections, plural(word, args.n, pos))
end
end
end
end