Mô đun:ee-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 lang = require("Module:languages").getByCode("ee")
local m_str_utils = require("Module:string utilities")
local head = require("Module:headword")
local parameters = require("Module:parameters")
local decomp = mw.ustring.toNFD
local gsub = m_str_utils.gsub
local match = m_str_utils.match
local reverse = m_str_utils.reverse
local U = require("Module:string/char")
local acute = U(0x0301) -- acute accent (high tone)
local grave = U(0x0300) -- grave accent (low tone)
local circ = U(0x0302) -- circumflex (rising tone)
local caron = U(0x030C) -- caron (rising tone)
local T = acute .. grave .. circ .. caron -- all tonal accents
-- Remove all tonal accents from a string by first decomposing
local function remove_accents(string)
return gsub(decomp(string), "[" .. T .. "]", "")
end
-- (super temporary fix) Get the correct accent
local function get_accent(entry)
local accent = match(reverse(decomp(entry)), "[" .. T .. "]")
if accent == circ then
return grave -- use grave for circumflex
end
if accent == caron then
return acute -- use acute for caron
end
return accent -- return the original accent
end
-- Noun generation function
local function generate_noun_forms(entry)
return {
defsg = entry .. " lá",
defsg2 = entry .. "a" .. get_accent(entry),
pl = entry .. "wó",
defpl = entry .. "a" .. get_accent(entry) .. "wó"
}
end
-- Main export function
function export.show(frame)
-- Define args
local args = frame:getParent().args
local pos = frame.args[1]
-- Define parameters
local params = {
-- head
[1] = { alias_of = "head" }, -- param 1 is alias of head
["head"] = { required = true }, -- head
-- pos = "nouns"
["def"] = {}, -- definite forms
["pl"] = {}, -- plural forms
}
-- Process parameters
local success, processed_args = pcall(parameters.process, args, params)
if not success then
error(processed_args)
end
-- Canonicalize pos
pos = head.canonicalize_pos(pos)
-- Create the headword line
local data = {
lang = lang,
heads = {processed_args.head},
pos_category = pos
}
local inflections = {}
local categories = {}
-- For nouns, handle various inflection forms
if pos == "nouns" then
local forms = generate_noun_forms(processed_args.head)
-- Handle definite forms
if processed_args.def ~= "-" and processed_args.pl ~= "pl" then
table.insert(inflections, {
label = "số ít xác định",
"[[" .. remove_accents(forms.defsg) .. "|" .. forms.defsg .. "]]",
"[[" .. remove_accents(forms.defsg2) .. "|" .. forms.defsg2 .. "]]"
})
end
-- Handle plural forms
if processed_args.pl == "-" then
table.insert(inflections, { -- add singular form
label = "chỉ có số ít"
})
table.insert(categories, "Danh từ chỉ có số ít tiếng Ewe")
elseif processed_args.pl == "pl" then
forms = generate_noun_forms(gsub(processed_args.head, "wó$", ""))
table.insert(inflections, { -- add plural form
label = "xác định số nhiều",
"[[" .. remove_accents(forms.defpl) .. "|" .. forms.defpl .. "]]"
})
table.insert(inflections, { -- add plural form
label = "chỉ có số nhiều"
})
table.insert(categories, "Danh từ chỉ có số nhiều tiếng Ewe")
else
local is_collective = processed_args.pl == "col"
table.insert(inflections, { -- add plural form
label = is_collective and "số nhiều tập hợp" or "số nhiều",
"[[" .. remove_accents(forms.pl) .. "|" .. forms.pl .. "]]"
})
if processed_args.def ~= "-" and (not is_collective or processed_args.def ~= "col") then
table.insert(inflections, { -- add definite plural form
label = is_collective and "xác đinh số nhiều tập hợp" or "xác định số nhiều",
"[[" .. remove_accents(forms.defpl) .. "|" .. forms.defpl .. "]]"
})
end
end
-- For numerals, check whether the numeral is cardinal or ordinal
elseif pos == "Số từ" then
local entry = remove_accents(processed_args.head)
local forms = generate_noun_forms(processed_args.head)
if match(entry, "gbãtɔ") or match(entry, "lia$") then -- "gbãtɔ" or suffix "-lia" is ordinal
table.insert(categories, "Số thứ tự tiếng Ewe")
else -- otherwise cardinal
table.insert(categories, "Số đếm tiếng Ewe")
end
end
-- Finalise and return data
data.inflections = inflections
data.categories = categories
return head.full_headword(data)
end
return export