Module:taln-headword: Difference between revisions

From Linguifex
Jump to navigation Jump to search
Nehster9 (talk | contribs)
mNo edit summary
No edit summary
 
(17 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local p = {}
local export = {}
local pos_functions = {}


local function get_args(frame)
local lang = require("Module:languages").getByCode("taln")
    return frame:getParent().args
local langname = lang:getCanonicalName()
end
 
local require_when_needed = require("Module:utilities/require when needed")
local m_headword_utilities = require_when_needed("Module:headword utilities")


local function format_rom(rom)
local force_cat = false
    if rom and rom ~= "" then
        return " • (" .. rom .. ")"
    end
    return ""
end


local function format_gender(g)
local insert = table.insert
    local gender_map = {
local ipairs = ipairs
        m = "m.",
        f = "f.",
        n = "n."
    }


    local label = gender_map[g] or (g and (g .. ".") or "?.")
local list_param = { list = true, disallow_holes = true }
local bool_param = { type = "boolean" }


    return " ''" .. label .. "''"
local function nonempty_list(list)
local ret = {}
if not list then
return ret
end
for _, v in ipairs(list) do
if v and v ~= "" then
insert(ret, v)
end
end
return ret
end
end


-- =========================
local function parse_term_list(forms, paramname)
-- NOUN
return m_headword_utilities.parse_term_list_with_modifiers{
-- =========================
forms = forms,
function p.noun(frame)
paramname = paramname,
    local args = get_args(frame)
splitchar = ",",
    local title = mw.title.getCurrentTitle().text
}
end


    local rom = args.rom or ""
local function insert_inflection(data, terms, label, accel)
    local g = args.g or "?"
m_headword_utilities.insert_inflection{
    local pl = args.pl or ""
headdata = data,
    local plrom = args.plrom or ""
terms = terms,
 
label = label,
    local text = "'''" .. title .. "'''"
accel = accel and { form = accel } or nil,
    text = text .. format_rom(rom)
}
    text = text .. format_gender(g)
end


    if pl ~= "" then
local function ensure_heads(data, args)
        text = text .. " plural '''[[" .. pl .. "]]'''"
local heads = nonempty_list(args.head)
local trs = args.tr or {}


        if plrom ~= "" then
if not heads[1] then
            text = text .. " (" .. plrom .. ")"
local default_head = data.pagename
        end
if not args.nolinkhead then
    end
default_head = m_headword_utilities.add_links_to_multiword_term(default_head, {})
end
heads = { default_head }
end


    return text
for i, head in ipairs(heads) do
insert(data.heads, {
term = head,
tr = trs[i],
})
end
end
end


-- =========================
function export.show(frame)
-- VERB
local iparams = {
-- =========================
[1] = { required = true },
function p.verb(frame)
}
    local args = frame:getParent().args
local iargs = require("Module:parameters").process(frame.args, iparams)
    local title = mw.title.getCurrentTitle().text
local poscat = iargs[1]


    local rom = args.rom or ""
local params = {
["head"] = list_param,
["tr"] = { list = true, allow_holes = true },
["id"] = {},
["sort"] = {},
["nolinkhead"] = bool_param,
["pagename"] = {}, -- for testing
}


    local pres1 = args.pres1 or ""
if pos_functions[poscat] then
    local past1 = args.past1 or ""
local posparams = pos_functions[poscat].params
    local part = args.part or ""
if type(posparams) == "function" then
posparams = posparams(lang)
end
for key, val in pairs(posparams) do
params[key] = val
end
end


    local pres1rom = args.pres1rom or ""
local args = require("Module:parameters").process(frame:getParent().args, params)
    local past1rom = args.past1rom or ""
local pagename = args.pagename or mw.loadData("Module:headword/data").pagename
    local partrom = args.partrom or ""


    local function format_form(form, rom_form)
local data = {
        if form == "" then
lang = lang,
            return ""
pos_category = poscat,
        end
categories = {},
heads = {},
genders = {},
inflections = { enable_auto_translit = true },
pagename = pagename,
id = args.id,
sort_key = args.sort,
force_cat_output = force_cat,
}


        local out = "[[" .. form .. "]]"
ensure_heads(data, args)


        if rom_form and rom_form ~= "" then
if pos_functions[poscat] and pos_functions[poscat].func then
            out = out .. " (" .. rom_form .. ")"
pos_functions[poscat].func(args, data)
        end
end


        return out
return require("Module:headword").full_headword(data)
    end
end
 
    local text = "'''" .. title .. "'''"
 
    if rom ~= "" then
        text = text .. " • (" .. rom .. ")"
    end
 
    local parts = {}
 
    if pres1 ~= "" then
        table.insert(parts, "first-person singular present " .. format_form(pres1, pres1rom))
    end
 
    if past1 ~= "" then
        table.insert(parts, "first-person singular past " .. format_form(past1, past1rom))
    end
 
    if part ~= "" then
        table.insert(parts, "past participle " .. format_form(part, partrom))
    end
 
    if #parts > 0 then
        text = text .. " (" .. table.concat(parts, ", ") .. ")"
    end


    return text
pos_functions.nouns = {
end
params = {
["g"] = { required = true, type = "genders", list = true, disallow_holes = true, flatten = true },
["nopl"] = bool_param,
["pl"] = list_param,
},
func = function(args, data)
local genders = nonempty_list(args.g)
if not genders[1] then
error("Parameter g= (gender) is required and must be non-empty")
end
data.genders = genders


-- =========================
local plurals = parse_term_list(args.pl, "pl")
-- ADJECTIVE (basic placeholder)
-- =========================
function p.adj(frame)
    local args = get_args(frame)
    local title = mw.title.getCurrentTitle().text


    local rom = args.rom or ""
if args.nopl or (plurals[1] and plurals[1].term == "-") then
insert(data.categories, langname .. " uncountable nouns")
elseif plurals[1] then
insert_inflection(data, plurals, "plural", "p")
else
insert(data.categories, langname .. " countable nouns")
end
end,
}


    local text = "'''" .. title .. "'''"
pos_functions.verbs = {
    text = text .. format_rom(rom)
params = {
    text = text .. " ''adj.''"
["pres"] = list_param,
["past"] = list_param,
["part"] = list_param,
},
func = function(args, data)
local pres = parse_term_list(args.pres, "pres")
local past = parse_term_list(args.past, "past")
local part = parse_term_list(args.part, "part")


    return text
if pres[1] then
end
insert_inflection(data, pres, "first-person singular present", "1|s|pres|ind")
end
if past[1] then
insert_inflection(data, past, "first-person singular past", "1|s|past|ind")
end
if part[1] then
insert_inflection(data, part, "past participle", "pastpart")
end
end,
}


return p
return export

Latest revision as of 13:57, 21 June 2026



local export = {}
local pos_functions = {}

local lang = require("Module:languages").getByCode("taln")
local langname = lang:getCanonicalName()

local require_when_needed = require("Module:utilities/require when needed")
local m_headword_utilities = require_when_needed("Module:headword utilities")

local force_cat = false

local insert = table.insert
local ipairs = ipairs

local list_param = { list = true, disallow_holes = true }
local bool_param = { type = "boolean" }

local function nonempty_list(list)
	local ret = {}
	if not list then
		return ret
	end
	for _, v in ipairs(list) do
		if v and v ~= "" then
			insert(ret, v)
		end
	end
	return ret
end

local function parse_term_list(forms, paramname)
	return m_headword_utilities.parse_term_list_with_modifiers{
		forms = forms,
		paramname = paramname,
		splitchar = ",",
	}
end

local function insert_inflection(data, terms, label, accel)
	m_headword_utilities.insert_inflection{
		headdata = data,
		terms = terms,
		label = label,
		accel = accel and { form = accel } or nil,
	}
end

local function ensure_heads(data, args)
	local heads = nonempty_list(args.head)
	local trs = args.tr or {}

	if not heads[1] then
		local default_head = data.pagename
		if not args.nolinkhead then
			default_head = m_headword_utilities.add_links_to_multiword_term(default_head, {})
		end
		heads = { default_head }
	end

	for i, head in ipairs(heads) do
		insert(data.heads, {
			term = head,
			tr = trs[i],
		})
	end
end

function export.show(frame)
	local iparams = {
		[1] = { required = true },
	}
	local iargs = require("Module:parameters").process(frame.args, iparams)
	local poscat = iargs[1]

	local params = {
		["head"] = list_param,
		["tr"] = { list = true, allow_holes = true },
		["id"] = {},
		["sort"] = {},
		["nolinkhead"] = bool_param,
		["pagename"] = {}, -- for testing
	}

	if pos_functions[poscat] then
		local posparams = pos_functions[poscat].params
		if type(posparams) == "function" then
			posparams = posparams(lang)
		end
		for key, val in pairs(posparams) 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 data = {
		lang = lang,
		pos_category = poscat,
		categories = {},
		heads = {},
		genders = {},
		inflections = { enable_auto_translit = true },
		pagename = pagename,
		id = args.id,
		sort_key = args.sort,
		force_cat_output = force_cat,
	}

	ensure_heads(data, args)

	if pos_functions[poscat] and pos_functions[poscat].func then
		pos_functions[poscat].func(args, data)
	end

	return require("Module:headword").full_headword(data)
end

pos_functions.nouns = {
	params = {
		["g"] = { required = true, type = "genders", list = true, disallow_holes = true, flatten = true },
		["nopl"] = bool_param,
		["pl"] = list_param,
	},
	func = function(args, data)
		local genders = nonempty_list(args.g)
		if not genders[1] then
			error("Parameter g= (gender) is required and must be non-empty")
		end
		data.genders = genders

		local plurals = parse_term_list(args.pl, "pl")

		if args.nopl or (plurals[1] and plurals[1].term == "-") then
			insert(data.categories, langname .. " uncountable nouns")
		elseif plurals[1] then
			insert_inflection(data, plurals, "plural", "p")
		else
			insert(data.categories, langname .. " countable nouns")
		end
	end,
}

pos_functions.verbs = {
	params = {
		["pres"] = list_param,
		["past"] = list_param,
		["part"] = list_param,
	},
	func = function(args, data)
		local pres = parse_term_list(args.pres, "pres")
		local past = parse_term_list(args.past, "past")
		local part = parse_term_list(args.part, "part")

		if pres[1] then
			insert_inflection(data, pres, "first-person singular present", "1|s|pres|ind")
		end
		if past[1] then
			insert_inflection(data, past, "first-person singular past", "1|s|past|ind")
		end
		if part[1] then
			insert_inflection(data, part, "past participle", "pastpart")
		end
	end,
}

return export