Module:Trig-verbs: Difference between revisions

From The Languages of David J. Peterson
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 25: Line 25:


function export.get_verb_root(frame)
function export.get_verb_root(frame)
local title = mw.title.getCurrentTitle()
local pagename = title.text
local params = {
local params = {
[1] = { required = true },
[1] = { default = pagename },
}
}
output, other = get_verb_parts(string.lower(args[1]))
local args = m_params.process(frame:getParent().args, params)
    local output, other = get_verb_parts(string.lower(args[1]))
return output
 
end
 
function export.get_verb_sat(frame)
local title = mw.title.getCurrentTitle()
local pagename = title.text
local params = {
[1] = { default = pagename },
}
local args = m_params.process(frame:getParent().args, params)
    local other, output = get_verb_parts(string.lower(args[1]))
return output
return output

Latest revision as of 17:44, 17 January 2024

Documentation for this module may be created at Module:Trig-verbs/documentation

export = {}

require("Module:Trig-verbs/data")

local m_params = require("Module:parameters")
local m_utilities  = require("Module:utilities")
local m_links = require("Module:links")

lang = require("Module:Languages").getByCode('trig')

function export.l(term, face, alt)
	return m_links.full_link( { term = term, lang = lang, alt = alt }, face )
end

local function get_verb_parts(verb) 
	if not verb then
		return nil,nil
	end
	
	term = mw.text.trim(verb)
	root, sat = string.match(term,'(%S+)%s+(%S+)')
	
	return root or verb, sat or ''
end

function export.get_verb_root(frame)
	
	local title = mw.title.getCurrentTitle()
	local pagename = title.text
	
	local params = {
		[1] = { default = pagename },
	}
	
	local args = m_params.process(frame:getParent().args, params)
    local output, other = get_verb_parts(string.lower(args[1]))
	
	return output

end

function export.get_verb_sat(frame)
	
	local title = mw.title.getCurrentTitle()
	local pagename = title.text
	
	local params = {
		[1] = { default = pagename },
	}
	
	local args = m_params.process(frame:getParent().args, params)
    local other, output = get_verb_parts(string.lower(args[1]))
	
	return output

end

function export.trig_from_root(frame)
	
	local output = {}
	local categories = {}
	
	local title = mw.title.getCurrentTitle()
	local namespace = title.nsText
	
	local params = {
		[1] = { alias_of = "root"},
		[2] = { alias_of = "sat"},
		["source"] = {},
		["root"] = {},
		["sat"] = {},		
		["nocat"] = { type = "boolean", default = false },
		["plain"] = { type = "boolean", default = false },
		["alt"] = {},
		["face"] = { default = "term" },
		["notext"] = { type = "boolean", default = false },
		["nolink"] = { type = "boolean", default = false },
	}
	
	local args = m_params.process(frame:getParent().args, params)
	
	if not args["root"] and namespace == "Template" then
		args["root"] = "tes"
		args["sat"] = "op"
		args["source"] = "test"
	elseif not args["root"] and namespace ~= "Template" then
		args["root"], args["sat"] = get_verb_parts(string.lower(title.text))
	end

	local link_text = export.l(args["root"], args["face"], args["root"] )
	if args["source"] then
		link_text = link_text..' ("'..args["source"]..'")'
	end
	
	link_text = link_text.." and "..export.l(args["sat"], args["face"], args["sat"])
	table.insert(categories, m_utilities.format_categories( { "Trigedasleng verbs with the satellite " .. args["sat"] }, lang) )
		
	table.insert(output, link_text)
	table.insert(categories, m_utilities.format_categories( { "Trigedasleng verbs belonging to the root " .. args["root"]}, lang) )
	
	
	if args["plain"] then
		return args["root"].." + "..args["sat"]
	elseif args["nocat"] then
		return table.concat(output)
	elseif args["notext"] then
		return table.concat(categories)
	else
		return table.concat(output) .. table.concat(categories)
	end
	
	return output
end

local function getSatTable(root,sat,exclude)

	exclude = string.gsub(','..exclude..',',"%s+","")
	local lines = {}
	
	for _,value in ipairs(SATELLITES) do
		if sat ~= value then
			if string.find(exclude,','..value..",") then
--				table.insert(lines,"<span>''"..root.." "..value.." (not used)''</span>")
			else
				table.insert(lines,'[['..root..' '..value..']]')
			end
		end
	end
	
	return lines
end

function export.showVerbSiblings(frame)
	
	local args = frame:getParent().args
	local exclude = args.exclude or ""
	
	local title = mw.title.getCurrentTitle()
	if title.nsText == "" then
		input = string.lower(title.text)
	else
		input = "test au"
	end
	
	root, sat = get_verb_parts(input) 
	
	local output = {}

	table.insert(output,'{| role="presentation" class="mw-collapsible mw-collapsed" style="background-color:#f0f0f0;width:50%;"\n')
    table.insert(output,'! style="font-weight:normal; background-color:#fafafa; |')
    table.insert(output," Other verbs from root ''[["..(root or "unknown") .."]]''&nbsp;\n|-\n| ")
	
	local sats = getSatTable(root,sat,exclude)
	
	return table.concat(output)..require("Module:Columns").create_list { 
			background_color = "#F8F8FF",
			column_count = 3,
			lang = lang,
		    content = sats,
	}..'\n|}'
end
	
return export