Mô đun:bg-headword
Giao diện
- Trang mô đun này thiếu trang con tài liệu. Xin hãy tạo trang tài liệu này.
- Liên kết hữu ích: danh sách trang con • liên kết • nhúng • trường hợp kiểm thử • chỗ thử
local export = {}
local pos_functions = {}
local en_utilities_module = "Module:en-utilities"
local headword_utilities_module = "Module:headword utilities"
local table_module = "Module:table"
local m_table -- defined when needed
local dump = mw.dumpObject
local insert = table.insert
local remove = table.remove
local lang = require("Module:languages").getByCode("bg")
local langname = lang:getCanonicalName()
local alias_of_comp_not_list = {alias_of = "comp", list = false}
local alias_of_sup_not_list = {alias_of = "sup", list = false}
local boolean = {type = "boolean"}
local list = {list = true}
local genders = {"m", "m-p", "f", "f-p", "n", "n-p", "p", "mf", "mf-p", "mfbysense", "mfbysense-p"}
local genders_param = {list = true, set = genders}
local function track(page)
require("Module:debug/track")("bg-headword/" .. page)
return true
end
local function glossary_link(anchor, text)
return "[[Phụ lục:Từ điển thuật ngữ#" .. anchor .. "|" .. (text or anchor) .. "]]"
end
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local poscat = frame.args[1] or error("Từ loại không được chỉ định. Vui lòng thêm tham số đầu tiên đề gọi mô đun.")
local params = {
["head"] = {list = true, disallow_holes = true},
[1] = {alias_of = "head", list = false},
["tr"] = {list = true, allow_holes = true},
["id"] = true,
["splithyph"] = boolean,
["nolinkhead"] = boolean,
["json"] = boolean,
["pagename"] = true, -- for testing
}
if pos_functions[poscat] then
for key, val in pairs(pos_functions[poscat].params) do
params[key] = val
end
end
local args = require("Module:parameters").process(frame:getParent().args, params)
local pagename = args.pagename or mw.loadData("Module:headword/data").pagename
local user_specified_heads = args.head
local heads = user_specified_heads
if args.nolinkhead then
track("nolinkhead")
local heads_n = #heads
if heads_n == 0 then
heads[1] = pagename
elseif heads_n == 1 and heads[1] == pagename then
track("redundant-head")
end
end
local is_suffix = pagename:find("^%-") and poscat ~= "Biến thể hình thái hậu tố"
local orig_poscat = poscat
poscat = pos_functions[poscat].overriding_poscat or poscat
local data = {
lang = lang,
pos_category = is_suffix and "Hậu tố" or poscat,
orig_poscat = orig_poscat,
is_suffix = is_suffix,
categories = {},
heads = heads,
no_redundant_head_cat = #user_specified_heads == 0,
inflections = {},
pagename = pagename,
id = args.id,
}
if is_suffix then
local singular_poscat = require(en_utilities_module).singularize(poscat)
insert(data.categories, " Dạng hậu tố của " .. singular_poscat .. " " .. langname)
insert(data.inflections, {label = "dạng hậu tố " .. singular_poscat})
end
for i, head in pairs(heads) do
-- Add category for words spelled without vowels
if not mw.ustring.match(head, "[аъоуеияѝюѫѭѩѧꙑѥѣАЪОУЕИЯЍЮѪѬѨѦꙐѢѤ]") then
insert(data.categories, "Mục từ có đánh vần thiếu nguyên âm " .. langname)
end
-- Try to link terms with multiple words (no-op if there is only one word
-- or if the term contains link syntax already)
if not args.nolinkhead then
heads[i] = require(headword_utilities_module).add_links_to_multiword_term(heads[i], {})
end
end
if pos_functions[poscat] then
pos_functions[poscat].func(args, data, is_suffix)
end
if args.json then
return require("Module:JSON").toJSON(data)
end
return require("Module:headword").full_headword(data)
end
-- Returns the lemma we should use in acceleration tags, which contains
-- the stress mark for polysyllabic words.
local function get_accel_lemma(data)
local accel_lemma
if #data.heads > 0 then
accel_lemma = data.heads[1]
else
accel_lemma = data.pagename
end
return accel_lemma
end
local function insert_infl(data, forms, label, accel)
if forms and #forms > 0 then
forms.label = label
if accel then
accel.lemma = get_accel_lemma(data)
forms.accel = accel
end
insert(data.inflections, forms)
end
end
local function handle_infl(args, data, argpref, label, accel)
insert_infl(data, args[argpref], label, accel)
end
pos_functions["Động từ"] = {
params = {
[2] = {set = {"pf", "impf", "both", "biasp", "?"}, default = "?"},
["pf"] = list,
["impf"] = list,
["impers"] = boolean,
},
func = function(args, data)
m_table = m_table or require(table_module)
local aspect = args[2]
if aspect == "both" then
aspect = "biasp"
end
data.genders = {aspect}
handle_infl(args, data, "pf", "hoàn thành")
handle_infl(args, data, "impf", "chưa hoàn thành")
if args.impers then
insert(data.inflections, {label = "không ngôi"})
data.gloss = "trần thuật hiện tại ở ngôi thứ ba số ít"
else
data.gloss = "trần thuật hiện tại ở ngôi thứ nhất số ít"
end
end
}
local valid_genders
local function get_valid_genders()
m_table = m_table or require(table_module)
valid_genders, get_valid_genders = valid_genders or m_table.listToSet{"m", "m-p", "f", "f-p", "n", "n-p", "p", "mf", "mf-p", "mfbysense", "mfbysense-p"}, nil
return valid_genders
end
local nouns = {
params = {
[2] = {alias_of = "g", list = false},
["g"] = genders_param,
["m"] = list,
["f"] = list,
["adj"] = list,
["dim"] = list,
["aug"] = list,
["pej"] = list,
["dem"] = list,
["fdem"] = list,
["indecl"] = boolean,
},
func = function(args, data)
data.genders = args.g
if args.indecl then
insert(data.inflections, {label = glossary_link("không biến cách")})
end
handle_infl(args, data, "m", "giống đực")
handle_infl(args, data, "f", "giống cái", {form = "f"})
handle_infl(args, data, "adj", "tính từ quan hệ", {form = "relational adjective"})
handle_infl(args, data, "dim", "giảm nhẹ nghĩa", {form = "diminutive"})
handle_infl(args, data, "aug", "tăng kích", {form = "augmentative"})
handle_infl(args, data, "pej", "nghĩa xấu")
handle_infl(args, data, "dem", "demonym")
handle_infl(args, data, "fdem", "female demonym")
end,
}
pos_functions["Danh từ"] = nouns
pos_functions["Danh từ riêng"] = nouns
-- Handle comparatives and superlatives for adjectives and adverbs, including user-specified comparatives and
-- superlatives and default-requested comparatives/superlatives using '+'. Code is the same for adjectives and adverbs.
local function handle_adj_adv_comp(args, data)
local plpos = data.pos_category:gsub("^reconstructed ", "")
if args.comp[1] == "-" then
remove(args.comp, 1)
if #args.comp > 0 then
insert(data.inflections, {label = "thường " .. glossary_link("so sánh được")})
insert(data.categories, plpos .. " so sánh được " .. langname)
insert(data.categories, plpos .. " không so sánh được " .. langname)
else
insert(data.inflections, {label = "không " .. glossary_link("so sánh được")})
insert(data.categories, plpos .. " không so sánh được " .. langname)
end
elseif #args.comp > 0 then
insert(data.categories, plpos .. " so sánh được " .. langname)
end
-- If comp=+, use default comparative 'по́-...', and set a default superlative if unspecified.
local saw_comp_plus = false
local comps = {}
for _, compval in ipairs(args.comp) do
if compval == "+" then
saw_comp_plus = true
for _, head in ipairs(data.heads) do
insert(comps, "по́-" .. head)
end
else
insert(comps, compval)
end
end
if saw_comp_plus and #args.sup == 0 then
args.sup = {"+"}
end
insert_infl(data, comps, "so sánh hơn", {form = "comparative"})
local sups = {}
if args.sup[1] == "-" then
insert(data.inflections, {label = "không có so sánh nhất"})
else
-- If sup=+ (possibly from comp=+), use default superlative 'на́й-...'.
for _, supval in ipairs(args.sup) do
if supval == "+" then
for _, head in ipairs(data.heads) do
insert(sups, "на́й-" .. head)
end
else
insert(sups, supval)
end
end
end
insert_infl(data, sups, "so sánh nhất", {form = "superlative"})
end
pos_functions["Phó từ"] = {
params = {
[2] = alias_of_comp_not_list,
["comp"] = list,
[3] = alias_of_sup_not_list,
["sup"] = list,
},
func = function(args, data)
handle_adj_adv_comp(args, data)
end,
}
local function make_adjective_pos_function(pos)
local params = {
["indecl"] = boolean,
["dim"] = list,
}
if pos == "Tính từ" then
params[2] = alias_of_comp_not_list
params["comp"] = list
params[3] = alias_of_sup_not_list
params["sup"] = list
params["adv"] = list
params["absn"] = list
end
return {
params = params,
overriding_poscat = pos == "Số từ" and "numerals" or nil,
func = function(args, data)
if args.indecl then
insert(data.inflections, {label = glossary_link("không biến cách")})
end
handle_adj_adv_comp(args, data)
handle_infl(args, data, "dim", "giảm nhẹ nghĩa")
handle_infl(args, data, "adv", "Phó từ")
handle_infl(args, data, "absn", "Danh từ trừu tượng", {form = "abstract noun", pos = "Danh từ"})
end,
}
end
pos_functions["Tính từ"] = make_adjective_pos_function("Tính từ")
pos_functions["Từ hạn định"] = make_adjective_pos_function("Từ hạn định")
pos_functions["Đại từ"] = make_adjective_pos_function("Đại từ")
pos_functions["Tính từ số từ"] = make_adjective_pos_function("Số từ")
local participle_types = {
["adv"] = "phó động từ",
["aor"] = "thì quá khứ bất định chủ động quá khứ",
["impf"] = "chưa hoàn thành hiện tại quá khứ",
["pres"] = "chủ động hiện tại",
["pass"] = "bị động quá khứ",
["ppp"] = "bị động quá khứ",
["prespass"] = "bị động hiện tại",
}
pos_functions["Phân từ"] = {
params = {
[2] = {required = true, list = true, default = "aor"},
},
func = function(args, data)
insert(data.categories, "Biến thể hình thái động từ tiếng Bulgari")
for _, part in ipairs(args[2]) do
local part_type = participle_types[part]
if not part_type then
m_table = m_table or require(table_module)
error("Không rõ loại phân từ " .. dump(part) .. "; phải là " .. m_table.serialCommaJoin(m_table.keysToList(participle_types), {conj = "hoặc", dump = true, dontTag = true}))
end
insert(data.categories, "Phân từ loại " .. part_type .. " tiếng Bulgari")
end
end
}
pos_functions["Biến thể hình thái phân từ"] = {
params = {
["g"] = genders_param,
},
func = function(args, data)
data.genders = args.g
insert(data.categories, "Biến thể hình thái động từ tiếng Bulgari")
end
}
pos_functions["Danh động từ"] = {
params = {
-- Verbal nouns in Bulgarian are overwhelmingly formed with the suffixes
-- "-не" or "-ние", which both have neuter gender.
["g"] = {list = true, set = genders, default = "n"},
},
overriding_poscat = "Danh từ",
func = function(args, data)
data.genders = args.g
end
}
pos_functions["Biến thể hình thái danh động từ"] = {
params = {
["g"] = genders_param,
},
overriding_poscat = "Biến thể hình thái danh từ",
func = function(args, data)
data.genders = args.g
end
}
return export