local export = {}
local pos_functions = {}
local lang = require("Module:languages").getByCode("mk")
local langname = lang:getCanonicalName()
local rfind = mw.ustring.find
local rsubn = mw.ustring.gsub
-- version of rsubn() that discards all but the first return value
local function rsub(term, foo, bar)
local retval = rsubn(term, foo, bar)
return retval
end
local function make_entry_name(head)
return lang:makeEntryName(require("Module:links").remove_links(head))
end
local function track(page)
require("Module:debug").track("mk-headword/" .. page)
return true
end
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local NAMESPACE = mw.title.getCurrentTitle().nsText
local PAGENAME = mw.title.getCurrentTitle().text
local tracking_categories = {}
local iparams = {
[1] = {required = true},
["def"] = {},
["suff_type"] = {},
}
local iargs = require("Module:parameters").process(frame.args, iparams)
local args = frame:getParent().args
local poscat = iargs[1]
local def = iargs.def
local suff_type = iargs.suff_type
local postype = nil
if suff_type then
postype = poscat .. '-' .. suff_type
else
postype = poscat
end
local data = {lang = lang, categories = {}, heads = {}, genders = {}, inflections = {}}
if poscat == "suffixes" then
table.insert(data.categories, "Macedonian " .. suff_type .. "-forming suffixes")
end
if pos_functions[postype] then
local new_poscat = pos_functions[postype](postype, def, args, data)
if new_poscat then
poscat = new_poscat
end
end
for _, head in ipairs(data.heads) do
if rfind(head, "[́̀ѐѝ]") then
track("accents")
end
end
if not rfind(poscat, " forms?$") then
for _, head in ipairs(data.heads) do
-- Don't trigger on prefixes, suffixes or reflexive verbs.
if (rfind(head, " ") or rfind(head, ".%-.")) and not rfind(head, "^се [^ ]+$") then
table.insert(data.categories, "馬其頓語詞組")
break
end
end
end
for _, inflection_set in ipairs(data.inflections) do
for _, inflection in ipairs(inflection_set) do
local title = mw.title.new(make_entry_name(inflection))
if title and not title.exists then
table.insert(tracking_categories, "標題行有紅鏈的" .. langname .. poscat)
end
end
end
data.pos_category = (NAMESPACE == "Reconstruction" and "重構" or "") .. poscat
return require("Module:headword").full_headword(data)
.. require("Module:utilities").format_categories(tracking_categories, lang)
end
pos_functions["動詞"] = function(postype, def, args, data)
local params = {
["head"] = {list = true},
[1] = {},
["pf"] = {list = true},
["impf"] = {list = true},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
local cats = {}
data.heads = args.head
data.id = args.id
if args[1] == "pf" then
data.genders = {"pf"}
cats = {"完整體動詞"}
elseif args[1] == "impf" then
data.genders = {"impf"}
cats = {"非完整體動詞"}
elseif args[1] == "both" then
data.genders = {"impf", "pf"}
cats = {"雙體動詞", "非完整體動詞", "完整體動詞"}
elseif args[1] == "?" or not args[1] then
data.genders = {"?"}
else
error("Unrecognized aspect '" .. args[1] .. "'")
end
for _, cat in ipairs(cats) do
table.insert(data.categories, "馬其頓語" .. cat)
end
local pf = args.pf
if #pf == 1 and pf[1] == "-" then
table.insert(data.inflections, {label = "無完整體"})
elseif #pf > 0 then
pf.label = "完整體"
table.insert(data.inflections, pf)
end
local impf = args.impf
if #impf == 1 and impf[1] == "-" then
table.insert(data.inflections, {label = "無非完整體"})
elseif #impf > 0 then
impf.label = "非完整體"
table.insert(data.inflections, impf)
end
end
local function nouns(pos, def, args, data)
local params = {
["head"] = {list = true},
[1] = {list = "g"},
[2] = {list = "pl"},
[3] = {alias_of = "dim"},
["dim"] = {list = true},
["m"] = {list = true},
["f"] = {list = true},
["adj"] = {list = true},
["aug"] = {list = true},
["indecl"] = {type = "boolean"},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = args.head
local genders = {}
local cat2 = nil
for _, g in ipairs(args[1]) do
if g == "m" or g == "m-p" then
cat2 = "馬其頓語陽性名詞"
elseif g == "f" or g == "f-p" then
cat2 = "馬其頓語陰性名詞"
elseif g == "n" or g == "n-p" then
cat2 = "馬其頓語中性名詞"
elseif g ~= "p" and g ~= "?" then
error("Unrecognized gender: '" .. g .. "'")
end
if g == "m-p" or g == "f-p" or g == "n-p" or g == "p" then
table.insert(data.categories, "馬其頓語唯複名詞")
end
table.insert(genders, g)
end
if #genders == 0 then
genders = {"?"}
end
if cat2 then
table.insert(data.categories, cat2)
end
if #genders > 1 then
table.insert(data.categories, "有多種性的馬其頓語名詞")
end
data.genders = genders
if args.indecl then
table.insert(data.inflections, {label = "無變格"})
end
local pl = args[2]
if #pl == 1 and pl[1] == "-" then
table.insert(data.inflections, {label = "不可數"})
table.insert(data.categories, "馬其頓語不可數名詞")
elseif #pl > 0 then
pl.label = "複數"
table.insert(data.inflections, pl)
end
local m = args.m
if #m > 0 then
m.label = "陽性"
table.insert(data.inflections, m)
end
local f = args.f
if #f > 0 then
f.label = "陰性"
table.insert(data.inflections, f)
end
local adj = args.adj
if #adj > 0 then
adj.label = "關係形容詞"
table.insert(data.inflections, adj)
end
local dim = args.dim
if #dim == 1 and dim[0] == "-" then
table.insert(data.inflections, {label = "無指小"})
elseif #dim > 0 then
dim.label = "指小"
table.insert(data.inflections, dim)
end
local aug = args.aug
if #aug == 1 and aug[0] == "-" then
table.insert(data.inflections, {label = "無指大"})
elseif #aug > 0 then
aug.label = "指大"
table.insert(data.inflections, aug)
end
data.id = args.id
end
pos_functions["名詞"] = nouns
pos_functions["專有名詞"] = nouns
local function adverbs(pos, def, args, data)
local params = {
["head"] = {list = true},
[1] = {list = "comp"},
[2] = {list = "sup"},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = args.head
local comp = args[1]
if comp[1] == "-" then
table.insert(data.inflections, {label = "無比較級"})
else
local head
if #data.heads > 0 then
head = make_entry_name(data.heads[1])
else
head = mw.title.getCurrentTitle().text
end
if #comp == 0 then
comp = {"по" .. head}
end
comp.label = "比較級"
table.insert(data.inflections, comp)
local sup = args[2]
if #sup == 0 then
sup = {"нај" .. head}
end
sup.label = "最高級"
table.insert(data.inflections, sup)
end
data.id = args.id
end
pos_functions["副詞"] = adverbs
local function adjectives(pos, def, args, data)
local params = {
["head"] = {list = true},
[1] = {list = "comp"},
[2] = {list = "sup"},
["indecl"] = {type = "boolean"},
["dim"] = {list = true},
["adv"] = {list = true},
["absn"] = {list = true},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = args.head
if args.indecl then
table.insert(data.inflections, {label = "無變格"})
end
local comp = args[1]
if comp[1] == "-" then
table.insert(data.inflections, {label = "無比較級"})
else
local head
if #data.heads > 0 then
head = make_entry_name(data.heads[1])
else
head = mw.title.getCurrentTitle().text
end
if #comp == 0 then
comp = {"по" .. head}
end
comp.label = "比較級"
table.insert(data.inflections, comp)
local sup = args[2]
if #sup == 0 then
sup = {"нај" .. head}
end
sup.label = "最高級"
table.insert(data.inflections, sup)
end
local dim = args.dim
if #dim > 0 then
dim.label = "指小詞"
table.insert(data.inflections, dim)
end
local adv = args.adv
if #adv > 0 then
adv.label = "副詞"
table.insert(data.inflections, adv)
end
local absn = args.absn
if #absn > 0 then
absn.label = "抽象名詞"
table.insert(data.inflections, absn)
end
data.id = args.id
end
pos_functions["形容詞"] = adjectives
pos_functions["限定詞"] = adjectives
pos_functions["代詞"] = adjectives
pos_functions["後綴形容詞"] = function(postype, def, args, data)
return adjectives("suffixes", def, args, data)
end
pos_functions["數字形容詞"] = function(postype, def, args, data)
return adjectives("numerals", def, args, data)
end
pos_functions["分詞"] = function(pos, def, args, data)
local params = {
["head"] = {list = true},
[1] = {required = true, list = true, default = "aor"},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = args.head
data.id = args.id
table.insert(data.categories, "馬其頓語動詞變位形式")
for _, part in ipairs(args[1]) do
if part == "adv" then
table.insert(data.categories, "馬其頓語副分詞")
elseif part == "aor" then
table.insert(data.categories, "馬其頓語不定過去分詞")
elseif part == "impf" then
table.insert(data.categories, "馬其頓語過去未完成分詞")
elseif part == "pres" then
table.insert(data.categories, "馬其頓語現在分詞")
elseif part == "pass" or part == "ppp" then
table.insert(data.categories, "馬其頓語過去分詞")
elseif part == "prespass" then
table.insert(data.categories, "馬其頓語被動現在分詞")
else
error("Unrecognized participle type '" .. part .. "': Should be adv, aor, impf, pres, pass or prespass")
end
end
end
pos_functions["短語"] = function(postype, def, args, data)
local params = {
["head"] = {list = true, default = def},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = args.head
data.id = args.id
end
local function non_lemma_forms(postype, def, args, data)
local params = {
["head"] = {list = true, default = def},
["g"] = {list = true},
["id"] = {},
}
local args = require("Module:parameters").process(args, params)
data.heads = args.head
data.genders = args.g
data.id = args.id
if postype == "participle forms" or postype == "動名詞" then
table.insert(data.categories, "馬其頓語動詞變位形式")
elseif postype == "verbal noun forms" then
table.insert(data.categories, "馬其頓語動詞變位形式")
return "noun forms"
end
end
pos_functions["noun forms"] = non_lemma_forms
pos_functions["proper noun forms"] = non_lemma_forms
pos_functions["pronoun forms"] = non_lemma_forms
pos_functions["verb forms"] = non_lemma_forms
pos_functions["verbal nouns"] = non_lemma_forms
pos_functions["verbal noun forms"] = non_lemma_forms
pos_functions["adjective forms"] = non_lemma_forms
pos_functions["participle forms"] = non_lemma_forms
pos_functions["determiner forms"] = non_lemma_forms
pos_functions["numeral forms"] = non_lemma_forms
pos_functions["suffix forms"] = non_lemma_forms
return export