Module:qhv-adj: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
 
(98 intermediate revisions by the same user not shown)
Line 7: Line 7:
local m_utils = require("Module:utilities")
local m_utils = require("Module:utilities")
local m_data = require('Module:qhv-adj/data')
local m_data = require('Module:qhv-adj/data')
local PAGENAME = mw.title.getCurrentTitle().text
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local NAMESPACE = mw.title.getCurrentTitle().nsText
local NAMESPACE = mw.title.getCurrentTitle().nsText
local NONSYLLABIC = u(0x032F) -- non-syllabic, combining inverted breve below
local DIPHTHONG = u(0x035C) -- double articulation, combining double breve below


local lang = require("Module:languages").getByCode("qhv")
local lang = require("Module:languages").getByCode("qhv")
Line 17: Line 14:
local export = {}
local export = {}


function export.detect_decl(word, number, class, reanalyzed)
local endings = {
local syllables = require("Module:qhv-pron").write_stress(word, true)
["a"] = "I", ["e"] = "II", ["z"] = "IIr", ["ie"] = "III",
local IPA = require("Module:qhv-pron").crux(word)
}
local vowel = "[aeiouy]ː?"
 
if number and class then
function export.detect_decl(word, class)
local decl = number .. "-" .. class
if class then
return decl, {sub(word, 1, -(#endings_reverse[decl] + 1))}
local decl = class
elseif reanalyzed then
return decl, {sub(word, 1, (decl == "III" and -3 or -2))}
for ending, decl in pairs(reanalyzed_endings) do
if find(word, ending .. "$") then
return "r-" .. decl, {sub(word, 1, -(#ending + 1))}
end
end
elseif (not find(IPA, "ˈ")) and (find(IPA, NONSYLLABIC .. ".$") or find(IPA, DIPHTHONG .. vowel .. ".$") or find(IPA, "ː.$")) then
return "3-s-h", {sub(word, 1, -2)}
else
else
for ending, decl in pairs(endings) do
for ending, decl in pairs(endings) do
Line 39: Line 29:
end
end
end
end
return "6", {word}
end
end


Line 46: Line 35:
local parent_args = frame:getParent().args
local parent_args = frame:getParent().args
local numbers = nil
local decl = {}
local decl = {}
local word = NAMESPACE == "Template" and "vala" or parent_args.word or PAGENAME
local word = NAMESPACE == "Template" and "rōva" or parent_args.word or PAGENAME
local reanalyzed = parent_args["r"]
local args = {}
local args = {}


if not alldata[word] then
if not m_data[word] then
if frame.args.decl then
if frame.args.decl then
decl_type = frame.args.decl
decl_type = frame.args.decl
else
else
if parent_args.n and parent_args.c and parent_args[1] then
if parent_args.c and parent_args[1] then
decl_type = parent_args.n .. "-" .. parent_args.c
decl_type = parent_args.c
numbers = {parent_args[1]}
numbers = {parent_args[1]}
else
else
decl_type, numbers = export.detect_decl(word, parent_args.n, parent_args.c, reanalyzed)
decl_type, numbers = export.detect_decl(word, parent_args.c)
end
end
end
end
Line 68: Line 55:
end
end
args = require("Module:parameters").process(parent_args, alldata[decl_type].params, true)
args = require("Module:parameters").process(parent_args, m_data[decl_type].params, true)
if numbers then
if numbers then
for i, number in ipairs(numbers) do
for i, number in ipairs(numbers) do
Line 77: Line 64:
end
end


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


function make_table(pass)
function make_table(data)
 
local function g_tooltip(n1, n2)
return require('Module:getn').format_list({n1, n2})
end
local function show_form(form)
local function show_form(form)
if not form then
if not form then
Line 112: Line 102:
local links = {}
local links = {}
for alt in gmatch(term, "([^%s,]+)") do
for alt in gmatch(term, "([^%s,]+)") do
alt = "[[Contionary:" .. alt .. "|" .. alt .. "]]"
if alt ~= "—" then
alt = "[[Contionary:" .. alt .. "|" .. alt .. "]]"
end
table.insert(links, alt)
table.insert(links, alt)
end
end
Line 120: Line 112:
local function repl(param)
local function repl(param)
if param == "decl_type" then
if param == "decl_type" then
return pass.decl_type
return data.decl_type
elseif param == "title" then
return pass.forms.nom_sg[1]
elseif param == "pagename" and NAMESPACE == "Template" then
elseif param == "pagename" and NAMESPACE == "Template" then
return "vala"
return "rōva"
elseif param == "pagename" then
elseif param == "pagename" then
return PAGENAME
return PAGENAME
else
else
return show_form(pass.forms[param])
return show_form(data.forms[param])
end
end
end
end


local function make_cases(data, post)
local function make_cases(data, pre)
local cases = {"nominative", "accusative", "genitive", "dative", "locative", "instrumental", "comitative", "vocative"}
local cases = {"nominative", "accusative", "genitive", "dative", "locative", "instrumental", "comitative", "vocative"}
local genders = data.decl_type == "I" and {"lunar", "solar", "terrestrial", "aquatic"} or {"lunar", "terrestrial"}
local ret = {}
local ret = {}
for _, case in ipairs(cases) do
for _, case in ipairs(cases) do
local case_short = sub(case, 1, 3)
local case_short = sub(case, 1, 3)
table.insert(ret, "|- \n! style=\"background-color: #dcffed;\ |" .. case .. "\n")
table.insert(ret, "|- style=\"background-color: #fdfdfd;\" \n! ! style=\"background-color: #FFB976; width:" .. (data.decl_type == "I" and "11.5%" or "16.68%") .. ";\"|" .. case .. "\n")
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(pass.forms[case_short .. "_sg"])) .. "\n")
for _, gender in ipairs(genders) do
if pass.forms[case_short .. "_pl"] or pass.forms[case_short .. "_pa"] or pass.forms[case_short .. "_co"] then
local g_short = sub(gender, 1, 1)
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(pass.forms[case_short .. "_pl"])) .. "\n")
for _, number in ipairs({"sg", "pl"}) do
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(pass.forms[case_short .. "_pa"])) .. "\n")
table.insert(ret, "| style=\"width:" .. (data.decl_type == "I" and "10.10%" or "20.83%") .. ";\" | " .. link(show_form(data.forms[(pre and "" or "post_") .. case_short .. "_" .. g_short .. "_" .. number])) .. "\n")
table.insert(ret, "| style=\"background-color: #edfff6;\" | " .. link(show_form(pass.forms[case_short .. "_co"])) .. "\n")
end
end
end
end
end
return table.concat(ret)
return table.concat(ret)
end
end
local wikicode = [=[
<div class="mw-collapsible" style="border-collapse: collapse; margin: 0px 0px -1px 0px; padding: 2px; text-align: center; border: 1px solid #aaaaaa; font-size: 95%; overflow: auto; width: auto;">
local divframe = [=[
<div class="mw-collapsible mw-collapsed" style="border-collapse: collapse; margin: 0px 0px -1px 0px; padding: 2px; text-align: center; border: 1px solid #aaaaaa; font-size: 95%; overflow: auto; width: auto;">
<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);"><span class="nowrap">Declension of ''<span lang="qhv">{{{pagename}}}</span>'' ([[:Category:High Valyrian class-{{{decl_type}}} adjectives|class {{{decl_type}}}]])</span></div>
<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);"><span class="nowrap">Declension of ''<span lang="qhv">{{{pagename}}}</span>'' ([[:Category:High Valyrian class-{{{decl_type}}} adjectives|class {{{decl_type}}}]])</span></div>
<div class="mw-collapsible-content" style="font-size: 100%;">
<div class="mw-collapsible-content" style="font-size: 100%;">
{| border="1px solid #000000" style="border-collapse: collapse; width:100%; text-align:center; background-color:#fdfdfd; cellspacing="1" cellpadding="2"
]=]
local prepositive = [=[
{| border="1px solid white" style="border-collapse: collapse; background:#ffffff; width:100%; text-align:center;" cellspacing="1" cellpadding="2"
|- style="background-color: #FFB976; text-align:center;"
|- style="background-color: #FFB976; text-align:center;"
! rowspan="2" style="background-color: #E57942;" | Prepositive
! rowspan="2" style="background-color: #E57942;" | Prepositive
! colspan="2" | lunar
! colspan="2" | lunar]=] .. (data.decl_type ~= "I" and " and solar" or "") .. (data.decl_type == "I" and "\n! colspan=\"2\" | solar" or "") .. [=[&#x200B;
! colspan="2" | solar
! colspan="2" | terrestrial]=] .. (data.decl_type ~= "I" and " and aquatic" or "") .. (data.decl_type == "I" and "\n! colspan=\"2\" | aquatic" or "") .. [=[&#x200B;
! colspan="2" | terrestrial
! colspan="2" | aquatic
|- style="background-color: #FFD79B; font-size: 95%"
|- style="background-color: #FFD79B; font-size: 95%"
! {{#invoke:getn|show_list|s|ol}}
! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
! {{#invoke:getn|show_list|p|pa}}
! ]=] .. g_tooltip("p", "pa") .. [=[&#x200B;
! {{#invoke:getn|show_list|s|ol}}
! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
! {{#invoke:getn|show_list|p|pa}}
! ]=] .. g_tooltip("p", "pa") .. (data.decl_type ~= "I" and "" or [=[&#x200B;
! {{#invoke:getn|show_list|s|ol}}
! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
! {{#invoke:getn|show_list|p|pa}}
! ]=] .. g_tooltip("p", "pa") .. [=[&#x200B;
! {{#invoke:getn|show_list|s|ol}}
! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
! {{#invoke:getn|show_list|p|pa}}
! ]=] .. g_tooltip("p", "pa")) .. [=[&#x200B;
|- ]=] .. make_cases(data, false) .. [=[
|- ]=] .. make_cases(data, true) .. [=[
|}<ul style="margin-left:0px;"></ul>
|}<ul style="margin-left:0px;"></ul>
]=]
local postpositive = [=[
{| border="1px solid white" style="border-collapse: collapse; background:#ffffff; width:100%; text-align:center;" cellspacing="1" cellpadding="2"
{| border="1px solid white" style="border-collapse: collapse; background:#ffffff; width:100%; text-align:center;" cellspacing="1" cellpadding="2"
|- style="background-color: #FFB976; text-align:center;"
|- style="background-color: #FFB976; text-align:center;"
! rowspan="2" style="background-color: #E57942;" | Prepositive
! rowspan="2" style="background-color: #E57942;" | Postpositive
! colspan="2" | lunar
! colspan="2" ]=] .. (data.decl_type ~= "I" and "style=\"min-width: 20.83%;\" | lunar and solar" or "| lunar") .. (data.decl_type == "I" and "\n! colspan=\"2\" | solar" or "") .. [=[&#x200B;
! colspan="2" | solar
! colspan="2" ]=] .. (data.decl_type ~= "I" and "style=\"min-width: 20.83%;\" | terrestrial and aquatic" or "| terrestrial") .. (data.decl_type == "I" and "\n! colspan=\"2\" | aquatic" or "") .. [=[&#x200B;
! colspan="2" | terrestrial
! colspan="2" | aquatic
|- style="background-color: #FFD79B; font-size: 95%"
|- style="background-color: #FFD79B; font-size: 95%"
! {{#invoke:getn|show_list|s|ol}}
! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
! {{#invoke:getn|show_list|p|pa}}
! ]=] .. g_tooltip("p", "pa") .. [=[&#x200B;
! {{#invoke:getn|show_list|s|ol}}
! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
! {{#invoke:getn|show_list|p|pa}}
! ]=] .. g_tooltip("p", "pa") .. (data.decl_type ~= "I" and "" or [=[&#x200B;
! {{#invoke:getn|show_list|s|ol}}
! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
! {{#invoke:getn|show_list|p|pa}}
! ]=] .. g_tooltip("p", "pa") .. [=[&#x200B;
! {{#invoke:getn|show_list|s|ol}}
! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
! {{#invoke:getn|show_list|p|pa}}
! ]=] .. g_tooltip("p", "pa")) .. [=[&#x200B;
|- style="background-color:#fdfdfd;" ]=] .. make_cases(data, true) .. [=[
|- ]=] .. make_cases(data, false) .. [=[
|}</div></div>]=]
|}
 
]=]
return (gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. require("Module:utilities").format_categories(pass.categories, lang)
local wikicode = divframe .. prepositive .. postpositive .. "</div></div>"
return (gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. (data.no_cat and "" or require("Module:utilities").format_categories(data.categories, lang))
end
end




return export
return export

Latest revision as of 17:52, 7 May 2021



local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local find = mw.ustring.find
local gmatch = mw.ustring.gmatch
local u = mw.ustring.char

local m_utils = require("Module:utilities")
local m_data = require('Module:qhv-adj/data')
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", "&nbsp;")
local NAMESPACE = mw.title.getCurrentTitle().nsText

local lang = require("Module:languages").getByCode("qhv")

local export = {}

local endings = {
	["a"] = "I", ["e"] = "II", ["z"] = "IIr", ["ie"] = "III",
}

function export.detect_decl(word, class)
	if class then
		local decl = class
		return decl, {sub(word, 1, (decl == "III" and -3 or -2))}
	else
		for ending, decl in pairs(endings) do
			if find(word, ending .. "$") then
				return decl, {sub(word, 1, -(#ending + 1))}
			end
		end
	end
end

-- The main entry point.
function export.show(frame)
	local parent_args = frame:getParent().args
	
	local decl = {}
	local word = NAMESPACE == "Template" and "rōva" or parent_args.word or PAGENAME
	local args = {}

	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 = export.detect_decl(word, parent_args.c)
			end
		end
		
		if not decl_type then
			error("Unknown declension '" .. decl_type .. "'")
		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 nil
	data.no_cat = parent_args["nocat"] or parent_args["det"] or nil
	
	-- 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 g_tooltip(n1, n2)
		return require('Module:getn').format_list({n1, n2})
	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
			if alt ~= "—" then
				alt = "[[Contionary:" .. alt .. "|" .. alt .. "]]"
			end
			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 "rōva"
		elseif param == "pagename" then
			return PAGENAME
		else
			return show_form(data.forms[param])
		end
	end

	local function make_cases(data, pre)
		local cases = {"nominative", "accusative", "genitive", "dative", "locative", "instrumental", "comitative", "vocative"}
		local genders = data.decl_type == "I" and {"lunar", "solar", "terrestrial", "aquatic"} or {"lunar", "terrestrial"}
		local ret = {}
		
		for _, case in ipairs(cases) do
			local case_short = sub(case, 1, 3)
			table.insert(ret, "|- style=\"background-color: #fdfdfd;\" \n! ! style=\"background-color: #FFB976; width:" .. (data.decl_type == "I" and "11.5%" or "16.68%") .. ";\"|" .. case .. "\n")
			for _, gender in ipairs(genders) do
				local g_short = sub(gender, 1, 1)
				for _, number in ipairs({"sg", "pl"}) do
					table.insert(ret, "| style=\"width:" .. (data.decl_type == "I" and "10.10%" or "20.83%") .. ";\" | " .. link(show_form(data.forms[(pre and "" or "post_") .. case_short .. "_" .. g_short .. "_" .. number])) .. "\n")
				end
			end
		end
		return table.concat(ret)
	end
	
	local divframe = [=[
	<div class="mw-collapsible mw-collapsed" style="border-collapse: collapse; margin: 0px 0px -1px 0px; padding: 2px; text-align: center; border: 1px solid #aaaaaa; font-size: 95%; overflow: auto; width: auto;">
	<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);"><span class="nowrap">Declension of ''<span lang="qhv">{{{pagename}}}</span>'' ([[:Category:High Valyrian class-{{{decl_type}}} adjectives|class {{{decl_type}}}]])</span></div>
	<div class="mw-collapsible-content" style="font-size: 100%;">
	]=]
	
	local prepositive = [=[
	{| border="1px solid white" style="border-collapse: collapse; background:#ffffff; width:100%; text-align:center;" cellspacing="1" cellpadding="2"
	|- style="background-color: #FFB976; text-align:center;"
	! rowspan="2" style="background-color: #E57942;" | Prepositive
	! colspan="2" | lunar]=] .. (data.decl_type ~= "I" and " and solar" or "") .. (data.decl_type == "I" and "\n! colspan=\"2\" | solar" or "") .. [=[&#x200B;
	! colspan="2" | terrestrial]=] .. (data.decl_type ~= "I" and " and aquatic" or "") .. (data.decl_type == "I" and "\n! colspan=\"2\" | aquatic" or "") .. [=[&#x200B;
	|- style="background-color: #FFD79B; font-size: 95%"
	! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
	! ]=] .. g_tooltip("p", "pa") .. [=[&#x200B;
	! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
	! ]=] .. g_tooltip("p", "pa") .. (data.decl_type ~= "I" and "" or [=[&#x200B;
	! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
	! ]=] .. g_tooltip("p", "pa") .. [=[&#x200B;
	! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
	! ]=] .. g_tooltip("p", "pa")) .. [=[&#x200B;
	|- ]=] .. make_cases(data, true) .. [=[
	|}<ul style="margin-left:0px;"></ul>
	]=]
	
	local postpositive = [=[
	{| border="1px solid white" style="border-collapse: collapse; background:#ffffff; width:100%; text-align:center;" cellspacing="1" cellpadding="2"
	|- style="background-color: #FFB976; text-align:center;"
	! rowspan="2" style="background-color: #E57942;" | Postpositive
	! colspan="2" ]=] .. (data.decl_type ~= "I" and "style=\"min-width: 20.83%;\" | lunar and solar" or "| lunar") .. (data.decl_type == "I" and "\n! colspan=\"2\" | solar" or "") .. [=[&#x200B;
	! colspan="2" ]=] .. (data.decl_type ~= "I" and "style=\"min-width: 20.83%;\" | terrestrial and aquatic" or "| terrestrial") .. (data.decl_type == "I" and "\n! colspan=\"2\" | aquatic" or "") .. [=[&#x200B;
	|- style="background-color: #FFD79B; font-size: 95%"
	! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
	! ]=] .. g_tooltip("p", "pa") .. [=[&#x200B;
	! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
	! ]=] .. g_tooltip("p", "pa") .. (data.decl_type ~= "I" and "" or [=[&#x200B;
	! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
	! ]=] .. g_tooltip("p", "pa") .. [=[&#x200B;
	! ]=] .. g_tooltip("s", "ol") .. [=[&#x200B;
	! ]=] .. g_tooltip("p", "pa")) .. [=[&#x200B;
	|- ]=] .. make_cases(data, false) .. [=[
	|}
	]=]
	
	local wikicode = divframe .. prepositive .. postpositive .. "</div></div>"
	
	return (gsub(wikicode, "{{{([a-z0-9_]+)}}}", repl)) .. (data.no_cat and "" or require("Module:utilities").format_categories(data.categories, lang))
end


return export