Module:taln-headword: Difference between revisions

From Linguifex
Jump to navigation Jump to search
Nehster9 (talk | contribs)
mNo edit summary
No edit summary
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 function format_rom(rom)
    if rom and rom ~= "" then
        return " • (" .. rom .. ")"
    end
    return ""
end


local function format_gender(g)
local m_headword_utilities = require_when_needed("Module:headword utilities")
    local gender_map = {
        m = "m.",
        f = "f.",
        n = "n."
    }


    local label = gender_map[g] or (g and (g .. ".") or "?.")
local force_cat = false


    return " ''" .. label .. "''"
local insert = table.insert
end


-- =========================
-- The main entry point.
-- NOUN
function export.show(frame)
-- =========================
local poscat = frame.args[1] or
function p.noun(frame)
error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
    local args = get_args(frame)
    local title = mw.title.getCurrentTitle().text


    local rom = args.rom or ""
local parargs = frame:getParent().args
    local g = args.g or "?"
    local pl = args.pl or ""
    local plrom = args.plrom or ""


    local text = "'''" .. title .. "'''"
local params = {
    text = text .. format_rom(rom)
["head"] = { list = true, disallow_holes = true },
    text = text .. format_gender(g)
["tr"] = { list = true, allow_holes = true },
["id"] = {},
["nolinkhead"] = { type = "boolean" },
["pagename"] = {}, -- for testing
}


    if pl ~= "" then
if pos_functions[poscat] then
        text = text .. " plural '''[[Contionary:" .. pl .. "|" .. pl .. "]]'''"
for key, val in pairs(pos_functions[poscat].params) do
params[key] = val
end
end


        if plrom ~= "" then
local args = require("Module:parameters").process(parargs, params)
            text = text .. " (" .. plrom .. ")"
        end
    end


    return text
local pagename = args.pagename or mw.loadData("Module:headword/data").pagename
end


-- =========================
local data = {
-- VERB
lang = lang,
-- =========================
pos_category = poscat,
function p.verb(frame)
categories = {},
    local args = frame:getParent().args
heads = {},
    local title = mw.title.getCurrentTitle().text
genders = {},
inflections = { enable_auto_translit = true },
pagename = pagename,
id = args.id,
sort_key = args.sort,
force_cat_output = force_cat,
}


    local rom = args.rom or ""
local heads = args.head
for i = 1, #heads do
insert(data.heads, {
term = heads[i],
tr = args.tr[i],
})
end


    local pres1 = args.pres1 or ""
if pos_functions[poscat] then
    local past1 = args.past1 or ""
pos_functions[poscat](args, data)
    local part = args.part or ""
end
return require("Module:headword").full_headword(data)
end


    local pres1rom = args.pres1rom or ""
pos_functions.nouns = function(args, data)
    local past1rom = args.past1rom or ""
local params = {
    local partrom = args.partrom or ""
["g"] = {required = true, type = "genders"},
 
["nopl"] = {type = "boolean"},
    local function format_form(form, rom_form)
["pl"] = {list = true, allow_holes = false},
        if form == "" then
}
            return ""
        end
args = require("Module:parameters").process(args, params)
 
        local out = "'''[[Contionary:" .. form .. "|" .. form .. "]]'''"
local function insert_inflection(terms, label, accel)
 
m_headword_utilities.insert_inflection {
        if rom_form and rom_form ~= "" then
headdata = data,
            out = out .. " (" .. rom_form .. ")"
terms = terms,
        end
label = label,
 
accel = accel and {form = accel} or nil,
        return out
}
    end
end
 
    local text = "'''" .. title .. "'''"
if args.nopl or (pl and pl[1] == "-") then
 
insert(data.categories, langname .. " uncountable nouns")
    if rom ~= "" then
elseif pl then
        text = text .. " • (" .. rom .. ")"
insert_inflection(pl, "plural", "p")
    end
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
end
end


-- =========================
pos_functions.verbs = function(args, data)
-- ADJECTIVE (basic placeholder)
local params = {
-- =========================
["pres"] = {list = true, allow_holes = false},
function p.adj(frame)
["past"] = {list = true, allow_holes = false},
    local args = get_args(frame)
["part"] = {list = true, allow_holes = false},
    local title = mw.title.getCurrentTitle().text
}
 
    local rom = args.rom or ""
args = require("Module:parameters").process(args, params)
 
    local text = "'''" .. title .. "'''"
local function insert_inflection(terms, label, accel)
    text = text .. format_rom(rom)
m_headword_utilities.insert_inflection {
    text = text .. " ''adj.''"
headdata = data,
 
terms = terms,
    return text
label = label,
accel = accel and {form = accel} or nil,
}
end
if pres then
insert_inflection(pres, "first-person singular present", "1|s|pres|ind")
end
if past then
insert_inflection(past, "first-person singular past", "1|s|past|ind")
end
if part then
insert_inflection(part, "past participle", "pastpart")
end
end
end


return p
return export

Revision as of 12:25, 21 June 2026



local export = {}
local pos_functions = {}

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

local m_headword_utilities = require_when_needed("Module:headword utilities")

local force_cat = false

local insert = table.insert

-- The main entry point.
function export.show(frame)
	local poscat = frame.args[1] or
		error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")

	local parargs = frame:getParent().args

	local params = {
		["head"] = { list = true, disallow_holes = true },
		["tr"] = { list = true, allow_holes = true },
		["id"] = {},
		["nolinkhead"] = { type = "boolean" },
		["pagename"] = {}, -- 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(parargs, 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,
	}

	local heads = args.head
	for i = 1, #heads do
		insert(data.heads, {
			term = heads[i],
			tr = args.tr[i],
		})
	end

	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end
	
	return require("Module:headword").full_headword(data)
end

pos_functions.nouns = function(args, data)
	local params = {
		["g"] = {required = true, type = "genders"},
		["nopl"] = {type = "boolean"},
		["pl"] = {list = true, allow_holes = false},
	}
	
	args = require("Module:parameters").process(args, params)
	
	local function insert_inflection(terms, label, accel)
		m_headword_utilities.insert_inflection {
			headdata = data,
			terms = terms,
			label = label,
			accel = accel and {form = accel} or nil,
		}
	end
	
	if args.nopl or (pl and pl[1] == "-") then
		insert(data.categories, langname .. " uncountable nouns")
	elseif pl then
		insert_inflection(pl, "plural", "p")
	end
end

pos_functions.verbs = function(args, data)
	local params = {
		["pres"] = {list = true, allow_holes = false},
		["past"] = {list = true, allow_holes = false},
		["part"] = {list = true, allow_holes = false},
	}
	
	args = require("Module:parameters").process(args, params)
	
	local function insert_inflection(terms, label, accel)
		m_headword_utilities.insert_inflection {
			headdata = data,
			terms = terms,
			label = label,
			accel = accel and {form = accel} or nil,
		}
	end
	
	if pres then
		insert_inflection(pres, "first-person singular present", "1|s|pres|ind")
	end
	
	if past then
		insert_inflection(past, "first-person singular past", "1|s|past|ind")
	end
	
	if part then
		insert_inflection(part, "past participle", "pastpart")
	end
end

return export