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), "", "")
end
-- (super temporary fix) Get the correct accent
local function get_accent(entry)
local accent = match(reverse(decomp(entry)), "")
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
-- Define parameters
local params = {
-- head
= { alias_of = "head" }, -- param 1 is alias of head
= { required = true }, -- head
-- pos = "nouns"
= {}, -- definite forms
= {}, -- 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 = "definite singular",
"]",
"]"
})
end
-- Handle plural forms
if processed_args.pl == "-" then
table.insert(inflections, { -- add singular form
label = "singular only"
})
elseif processed_args.pl == "pl" then
forms = generate_noun_forms(gsub(processed_args.head, "wó$", ""))
table.insert(inflections, { -- add plural form
label = "definite plural",
"]"
})
table.insert(inflections, { -- add plural form
label = "plural only"
})
else
local is_collective = processed_args.pl == "col"
table.insert(inflections, { -- add plural form
label = is_collective and "collective plural" or "plural",
"]"
})
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 "definite collective plural" or "definite plural",
"]"
})
end
end
-- For numerals, check whether the numeral is cardinal or ordinal
elseif pos == "numerals" 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, "Ewe ordinal numbers")
else -- otherwise cardinal
table.insert(categories, "Ewe cardinal numbers")
end
end
-- Finalise and return data
data.inflections = inflections
data.categories = categories
return head.full_headword(data)
end
return export