Module:qay-verb: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
Line 144: Line 144:
table.insert(ret, '\n! colspan=2 style="background-color:#BDBDFF; color: black;" | ' .. ordinal(person) .. '\n')
table.insert(ret, '\n! colspan=2 style="background-color:#BDBDFF; color: black;" | ' .. ordinal(person) .. '\n')
table.insert(ret, '\n|' .. link(show_form(data.forms[columns[1] .. "_" .. person .. "_" .. num])))
table.insert(ret, '\n|' .. link(show_form(data.forms[columns[1] .. "_" .. person .. "_" .. num])))
table.insert(ret, '\n|' .. link(show_form(data.forms[columns[2] .. "_" .. person .. "_" .. num] .. '\n|-')))
table.insert(ret, '\n|' .. link(show_form(data.forms[columns[2] .. "_" .. person .. "_" .. num])) .. '\n|-')
end
end
end
end

Revision as of 11:29, 25 June 2023

Documentation for this module may be created at Module:qay-verb/doc

local export = {}

local m_u = require('Module:utilities')
local m_data = require('Module:qay-verb/data')

local sub = mw.ustring.sub
local find = mw.ustring.find
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit

local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local NAMESPACE = mw.title.getCurrentTitle().nsText
local lang = require("Module:languages").getByCode("qay")

local function detect_decl(word)
	if word:match("a$") then
		return "a", {word}
	elseif word:match("[eiou]$") or word:match("[eiou]y") then
		return "v", {word}
	elseif word:match("[ptkbdgmncvshrlj][ptkbdgmncvshrlj]") then
		return "2c", {word}
	else
		return "c", {word}
	end
end

-- The main entry point.
function export.show(frame)
	local parent_args = frame:getParent().args
	
	local numbers = {}
	local decl = {}
	local word = NAMESPACE == "Template" and "no" or parent_args["word"] or sub(PAGENAME,1,-2)
	local args = {}
	local decl_type = NAMESPACE == "Template" and "v" or parent_args["decl"] or detect_decl(word)
	
	if not m_data[word] then
		if frame.args.decl then
			decl_type = frame.args.decl
		else
			if parent_args.c and parent_args[1] then
				decl_type = parent_args.c
				numbers = {parent_args[1]}
			else
				decl_type, numbers = detect_decl(word)
			end
		end
		
	--	if not decl_type then decl_type, numbers = "fricative", {root} end
		
		args = require("Module:parameters").process(parent_args, m_data[decl_type].params, true)
		
		if numbers then
			for i, number in ipairs(numbers) do
				args[i] = number
			end
		end
	end

	local data = {forms = {}, categories = {}}
	
	data.head = parent_args["head"] or word
	data.nocat = parent_args["nocat"] and true or false
	data.decl_type = decl_type
	
	-- Generate the forms
	if m_data[word] then
		m_data[word](parent_args, data)
	else
		m_data[decl_type](args, data)
	end
	
	-- make the table
	return make_table(data)
end

function make_table(data)
	
	local function ordinal(n)
		return n .. (n=="1" and "st" or n=="2" and "nd" or n=="3" and "rd" or "th")
	end
	
	local function tooltip(gender)
		return require('Module:getn').format_list({gender})
	end
	
	local function show_form(form)
		if not form then
			return "—"
		end
		
		local ret = {}
		
		for key, subform in ipairs(form) do
			table.insert(ret, subform)
		end
			
		return table.concat(ret, ", ")
	end
	
	local function link(term)
		local links = {}
		for alt in gmatch(term, "([^%s,]+)") do
			alt = term == "—" and term or "[[Contionary:" .. alt .. "|" .. alt .. "]]"
			table.insert(links, alt)
		end
		return table.concat(links, ", ")
	end	
	
	local function repl(param)
		if param == "decl_type" then
			return data.decl_type
		elseif param == "pagename" and NAMESPACE == "Template" then
			return "no-"
		elseif param == "pagename" then
			return PAGENAME
		else
			return show_form(data.forms[param])
		end
	end

	local function make_forms(data)
		local numbers = {"s", "p"}
		local persons = {"1", "2", "3"}
		local genders = {"m", "f", "n", "in"}
		local columns = {"top", "cli"}
		local ret = {}
		
		for _, num in ipairs(numbers) do
			table.insert(ret, '\n|-\n ! style="background-color:#4848B7; color:white; width: 15%" rowspan=6 | ' .. (num == "s" and "Singular" or "Plural"))
			for _, person in ipairs(persons) do
				if person == "3" then
					table.insert(ret, '\n! rowspan=4 style="background-color:#BDBDFF; color: black;" | ' .. ordinal(person) .. '\n')
					for _, g in ipairs(genders) do
						table.insert(ret, '! style="background-color:#DBDBFF" | ' .. tooltip(g))
						table.insert(ret, '\n|' .. link(show_form(data.forms[columns[1] .. "_" .. person .. "_" .. num .. "_" .. g])))
						table.insert(ret, '\n|' .. link(show_form(data.forms[columns[2] .. "_" .. person .. "_" .. num .. "_" .. g])))
					end
				else
					table.insert(ret, '\n! colspan=2 style="background-color:#BDBDFF; color: black;" | ' .. ordinal(person) .. '\n')
					table.insert(ret, '\n|' .. link(show_form(data.forms[columns[1] .. "_" .. person .. "_" .. num])))
					table.insert(ret, '\n|' .. link(show_form(data.forms[columns[2] .. "_" .. person .. "_" .. num])) .. '\n|-')
				end
			end
		end
		return table.concat(ret)
	end

	local navframe = [=[
<div class="mw-collapsible" style="border-collapse: collapse; margin: 0px 0px -1px 0px; padding: 2px; border: 1px solid #aaaaaa; text-align: center; font-size: 95%; overflow: auto; width: 55%;">
<div style="min-height: 1.6em; font-weight:bold; font-size: 100%; text-align: left; background-color:#efefef; padding-left: 10px; background-image: -webkit-gradient(linear, left top, left bottom, from(#EFEFEF), to(#DFDFDF), color-stop(0.6, #E3E3E3)); background-image: -moz-linear-gradient(top, #EFEFEF, #E3E3E3 60%, #DFDFDF);  background-image: -o-linear-gradient(top, #EFEFEF, #E3E3E3 60%, #DFDFDF);">''no-'' — verb (vocalic)</div>
<div class="mw-collapsible-content" style="font-size: 100%;">
	]=]
	
	local wikicode = [=[
{| border="1px solid #d0d0d0" style="border-collapse:collapse; background:#F9F9FF; text-align:center; width:100%" cellspacing="1" cellpadding="2"
|- style="background-color:#000080; color:white"
!  &nbsp; !! colspan="2" style="width:20%" | Person !! Topicalized !! Clitic agent
]=] .. make_forms(data) .. [=[
|}</div></div>]=]
	
	return gsub(navframe .. wikicode, "{{{([a-z0-9_]+)}}}", repl)
		   .. (not data.nocat and m_u.format_categories(data.categories, lang) or "")
end

return export