Module:xchc-noun: Difference between revisions

From Linguifex
Jump to navigation Jump to search
No edit summary
No edit summary
Line 20: Line 20:
local vowel = "[aeɛioɔuyø]"
local vowel = "[aeɛioɔuyø]"


local function matchEnd(foo, pat)
local function me(foo, pat)
return foo:match(pat .. "ː?$")
return foo:match(pat .. "ː?$")
end
end


local function gsubh(word, o, e, def)
local function gsubh(word, o, e, def)
local backh = word:match("ɛ") and "ɛ" or word:match("ɔ") and "ɔ" or nil
local repl = {["ɛ"] = e, ["ɔ"] = o}
local repl = {["ɛ"] = e, ["ɔ"] = o}
return word:gsub("V", repl[backh] or def)
return word:gsub("V", repl[backh] or def)
Line 41: Line 42:
if g ~= "i" and g ~= "a" then error("Unknown gender: it must be either ‘i’ or ‘a’") end
if g ~= "i" and g ~= "a" then error("Unknown gender: it must be either ‘i’ or ‘a’") end
local wordpron = m_ipa.crux(word)
local function wordpron(w)
backh = word:match("ɛ") and "ɛ" or word:match("ɔ") and "ɔ" or nil
return m_ipa.crux(w)
local singular = word
end
local paucal = wordpron:matchEnd("[eiøy]") and "ч"
  or wordpron:matchEnd("[ɛa]") and "н"
local data = {}
  or wordpron:matchEnd("[uoɔ]") and "ӈ"
data.word = word
data.g = g
data.sg = word
data.pau = wordpron(word):me("[eiøy]") and "ч"
  or wordpron(word):me("[ɛa]") and "н"
  or wordpron(word):me("[uoɔ]") and "ӈ"
  or gsubh("Vӈ", "о̆", "э̆", "о̆")
  or gsubh("Vӈ", "о̆", "э̆", "о̆")
local plural = {
data.pl = {
["i"] = wordpron:matchEnd(voiceless) and gsubh("фVд","ө","э","э") or gsubh("вVд","ө","э","э"),
["i"] = wordpron(word):me(voiceless) and gsubh("фVд","ө","э","э") or gsubh("вVд","ө","э","э"),
["a"] = wordpron:matchEnd(voiceless) and gsubh("шVд","о̆","э̆","о̆") or gsubh("жVд","о̆","э̆","о̆"),
["a"] = wordpron(word):me(voiceless) and gsubh("шVд","о̆","э̆","о̆") or gsubh("жVд","о̆","э̆","о̆"),
}
}
end
function make_table(data)
local function show_form(form)
if not form then
return "—"
end
local ret = {}
for _, 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 == "irregular" and data.decl_type or "''" .. data.decl_type .. "''-declension"
elseif param == "title" then
return NAMESPACE == "Template" and "sivi" or data.alt or PAGENAME
elseif param == "word" and NAMESPACE == "Template" then
return "sivi"
elseif param == "word" then
return data.head
elseif param == "gender" then
return (data.g == "i" and "inanimate" or "animate")
else
return show_form(data.forms[param])
end
end
function make_cases(data)
local w_number = {["si"] = data.word .. data.sg, ["pa"] = data.word .. data.pa, ["pl"] = data.word .. data.pl}
local cases = {"nominative", "accusative", "dative", "genitive", "instrumental", "prosecutive", "adessive<br/>comitative", "ablative<br/>elative", "illative<br/>allative"}
local cases_sh = {"nom", "acc", "dat", "gen", "ins", "pro", "ade", "abl", "ill"}
local numbers = {"singular", "paucal", "plural"}
local numbers_sh = {"si", "pa", "pl"}
local ret = {}
if data.unc then
numbers[2], numbers[3], numbers_sh[2], numbers_sh[3] = nil, nil, nil, nil
end
for _, n in ipairs(numbers) do
table.insert(ret, "! " .. n .. "\n")
end
table.insert(ret, "|-\n")
for _, case in ipairs(cases) do
table.insert(ret, "! " .. case .. "\n")
end
table.insert(ret, "|-\n")
for _, case in ipairs(cases) do
table.insert(ret, "| " .. show_form(case .. data.sg) .. show_form(case .. data.pau) .. show_form(case .. data.pl[data.g]) .. "\n")
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; min-width: 70em; display:inline-block;">
<div style="min-height: 1.6em; font-size: 100%; text-align: left; background-color:#DEE9FB; 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);">'''''{title}'''''<span style="font-weight:normal;">{after_title}</span>&nbsp;</div>
<div class="mw-collapsible-content" style="font-size: 100%;">
]=]
end
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; min-width: 70em; display:inline-block;">
<div style="min-height: 1.6em; font-size: 100%; text-align: left; background-color:#DEE9FB; 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);">'''''{title}'''''<span style="font-weight:normal;">{after_title}</span>&nbsp;</div>
<div class="mw-collapsible-content" style="font-size: 100%;">
]=]


return export
return export

Revision as of 14:24, 7 December 2023



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 m_tr = require('Module:xchc-translit')
local m_ipa = require('Module:xchc-pron')

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

local export = {}

local voiced = "mnɲŋbdɡvzʒɣlr"
local voiceless = "ptkfsʃxh"
local consonant = "[" .. voiced .. voiceless .. "]"
local vowel = "[aeɛioɔuyø]"

local function me(foo, pat)
	return foo:match(pat .. "ː?$")
end

local function gsubh(word, o, e, def)
	local backh = word:match("ɛ") and "ɛ" or word:match("ɔ") and "ɔ" or nil
	local repl = {["ɛ"] = e, ["ɔ"] = o}
	return word:gsub("V", repl[backh] or def)
end

function export.show(frame)
	local parent_args = frame:getParent().args
	
	local numbers = {}
	local decl = {}
	local g = NAMESPACE == "Template" and "a" or parent_args[1]
	local word = NAMESPACE == "Template" and "өра̄" or parent_args["word"] or PAGENAME
	local unc = parent_args["unc"] or false
	local args = {}
	
	if g ~= "i" and g ~= "a" then error("Unknown gender: it must be either ‘i’ or ‘a’") end
	
	local function wordpron(w)
		return m_ipa.crux(w)
	end
	
	local data = {}
	data.word = word
	data.g = g
	data.sg = word
	data.pau = wordpron(word):me("[eiøy]") and "ч"
				   or wordpron(word):me("[ɛa]") and "н"
				   or wordpron(word):me("[uoɔ]") and "ӈ"
				   or gsubh("Vӈ", "о̆", "э̆", "о̆")
	data.pl = {
		["i"] = wordpron(word):me(voiceless) and gsubh("фVд","ө","э","э") or gsubh("вVд","ө","э","э"),
		["a"] = wordpron(word):me(voiceless) and gsubh("шVд","о̆","э̆","о̆") or gsubh("жVд","о̆","э̆","о̆"),
	}

end

function make_table(data)

	local function show_form(form)
		if not form then
			return "—"
		end
		
		local ret = {}
		
		for _, 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 == "irregular" and data.decl_type or "''" .. data.decl_type .. "''-declension"
		elseif param == "title" then
			return NAMESPACE == "Template" and "sivi" or data.alt or PAGENAME
		elseif param == "word" and NAMESPACE == "Template" then
			return "sivi"
		elseif param == "word" then
			return data.head
		elseif param == "gender" then
			return (data.g == "i" and "inanimate" or "animate")
		else
			return show_form(data.forms[param])
		end
	end

	function make_cases(data)
		local w_number = {["si"] = data.word .. data.sg, ["pa"] = data.word .. data.pa, ["pl"] = data.word .. data.pl}
		
		local cases = {"nominative", "accusative", "dative", "genitive", "instrumental", "prosecutive", "adessive<br/>comitative", "ablative<br/>elative", "illative<br/>allative"}
		local cases_sh = {"nom", "acc", "dat", "gen", "ins", "pro", "ade", "abl", "ill"}
		local numbers = {"singular", "paucal", "plural"}
		local numbers_sh = {"si", "pa", "pl"}
		local ret = {}
		
		if data.unc then
			numbers[2], numbers[3], numbers_sh[2], numbers_sh[3] = nil, nil, nil, nil
		end
		
		for _, n in ipairs(numbers) do
			table.insert(ret, "! " .. n .. "\n")
		end
		table.insert(ret, "|-\n")
		for _, case in ipairs(cases) do
			table.insert(ret, "! " .. case .. "\n")
		end
		table.insert(ret, "|-\n")
		for _, case in ipairs(cases) do
			table.insert(ret, "| " .. show_form(case .. data.sg) .. show_form(case .. data.pau) .. show_form(case .. data.pl[data.g]) .. "\n")
		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; min-width: 70em; display:inline-block;">
	<div style="min-height: 1.6em; font-size: 100%; text-align: left; background-color:#DEE9FB; 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);">'''''{title}'''''<span style="font-weight:normal;">{after_title}</span>&nbsp;</div>
	<div class="mw-collapsible-content" style="font-size: 100%;">
	]=]

end

return export