Module:ryn-mut: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
 
(18 intermediate revisions by the same user not shown)
Line 4: Line 4:
[1] = {alias_of = "r"},
[1] = {alias_of = "r"},
r = {default = mw.title.getCurrentTitle().text},
r = {default = mw.title.getCurrentTitle().text},
n = {},
i = {},
initial = {alias_of = "i"},
s = {},
soft = {alias_of = "s"},
lenited = {alias_of = "s"},
nocat = {type = "boolean"},
nocat = {type = "boolean"},
}
}
Line 11: Line 15:
local UNCHANGED_MARKER = "<i>unchanged</i>"
local UNCHANGED_MARKER = "<i>unchanged</i>"


local mutation_rules = {
local lenition = {
["b"] = {"bh", "mb"},
["b"] = "v",
["bh"] = {nil, "mbh"},
["k"] = "g",
["c"] = {"ch", "nc"},
["d"] = "z",
["ch"] = {nil, "nch"},
["f"] = "h",
["d"] = {"d̦", "nd"},
["g"] = "ŗ",
["d̦"] = {"d̦", "nd̦"},
["ŗ"] = "",
["dh"] = {nil, "ndh"},
["p"] = "b",
["f"] = {nil, "mf"},
["s"] = "r",
["g"] = {"gh", "ng"},
["t"] = "d",
["gh"] = {nil, "ngh"},
["z"] = "r",
["l"] = {nil, "nl"},
["lh"] = {"l", "nlh"},
["m"] = {},
["n"] = {},
["p"] = {"b", "mp"},
["r"] = {nil, "dr"},
["rh"] = {"r", "dr"},
["s"] = {"ș", "ns"},
["ș"] = {"ș", "nș"},
["t"] = {"ț", "nt"},
["ț"] = {"ț", "nț"},
}
}
local vowel_pattern = "[aeiíoóu]"


local function get_radical_data(term)
local function get_radical_data(term, initial_override)
local initial, prevowel, remainder
local initial, remainder
if mw.ustring.sub(term, 2, 2) == "h" then
initial = initial_override or mw.ustring.sub(term, 1, 1)
initial = mw.ustring.sub(term, 1, 2)
remainder = mw.ustring.sub(term, 2)
remainder = mw.ustring.sub(term, 3)
return initial, remainder
prevowel = mw.ustring.find(mw.ustring.sub(term, 3, 3), vowel_pattern) and true or false
else
initial = mw.ustring.sub(term, 1, 1)
remainder = mw.ustring.sub(term, 2)
prevowel = mw.ustring.find(mw.ustring.sub(term, 2, 2), vowel_pattern) and true or false
end
local vowel = mw.ustring.find(initial, vowel_pattern) and true or false
return initial, vowel, prevowel, remainder
end
end


local function mutate_soft(data)
local function mutate_soft(data)
if data.vowel then
local change = lenition[data.initial]
if data.initial == "i" then return data.radical end
if change then
return "i" .. data.radical
return change .. data.remainder
end
end
local change = mutation_rules[data.initial][1]
if change then return change .. data.remainder end
if data.prevowel then return data.initial .. "i" .. data.remainder end
return data.radical
end
local function mutate_nasal(data)
if data.vowel then return "n-" .. data.radical end
local change = mutation_rules[data.initial][2]
if change then return change .. data.remainder end
return data.radical
return data.radical
end
end


function export.mutate(term)
function export.mutate(term, initial_override)
local data = {}
local data = {}
data.radical = term
data.radical = term
data.initial, data.vowel, data.prevowel, data.remainder = get_radical_data(term)
data.initial, data.remainder = get_radical_data(term, initial_override)
data.soft = mutate_soft(data)
data.soft = mutate_soft(data)
data.nasal = mutate_nasal(data)
return data
return data
end
end


local function get_mutation_info(radical, override, expected)
local function get_mutation_info(radical, override, expected)
local irregular = (not override) or (expected ~= override)
local irregular = override and (expected ~= override)
local mutation = override or expected
local mutation = override or expected
local changed = mutation ~= radical
local changed = mutation ~= radical
Line 88: Line 61:
local args = require("Module:parameters").process(frame:getParent().args, params)
local args = require("Module:parameters").process(frame:getParent().args, params)
local radical = args["r"]
local radical = args["r"]
local data = export.mutate(radical)
local data = export.mutate(radical, args["i"])
local s_mut, s_changed, s_irregular = get_mutation_info(radical, args["s"], data.soft)
local s_mut, s_changed, s_irregular = get_mutation_info(radical, args["s"], data.soft)
local n_mut, n_changed, n_irregular = get_mutation_info(radical, args["n"], data.nasal)
local ret = '{| style="display:table; width:54%; border: 1px solid #b3b3b3; font-size: 95%; text-align: center;'
local ret = '{| style="display:table; width:50%; border: 1px solid #b3b3b3; font-size: 95%; text-align: center;'
ret = ret .. '\n|-'
ret = ret .. '\n|-'
ret = ret .. '\n! style="background:#efefef" colspan=3 | [[Appendix:Riyan mutation|Riyan mutation]]'
ret = ret .. '\n! style="background:#efefef" colspan=2 | [[Appendix:Riyan mutation|Riyan mutation]]'
ret = ret .. '\n|-'
ret = ret .. '\n|-'
ret = ret .. '\n! style="padding-top:4px;" | [[Appendix:Glossary#radical|radical]]'
ret = ret .. '\n! style="padding-top:4px;" | [[Appendix:Glossary#radical|radical]]'
ret = ret .. '\n! style="padding-top:4px; | [[Appendix:Glossary#lenition|lenited]]'
ret = ret .. '\n! style="padding-top:4px; | [[Appendix:Glossary#lenition|lenited]]'
ret = ret .. '\n! style="padding-top:4px; | [[Appendix:Glossary#nasal|nasal]]'
ret = ret .. '\n|-'
ret = ret .. '\n|-'
ret = ret .. '\n| style="padding-bottom:4px;" | ' .. radical
ret = ret .. '\n| style="padding-bottom:4px;" | ' .. radical
ret = ret .. '\n| style="padding-bottom:4px;" | ' .. (s_changed and s_mut or UNCHANGED_MARKER) .. (s_irregular and IRREG_MARKER or "")
ret = ret .. '\n| style="padding-bottom:4px;" | ' .. (s_changed and s_mut or UNCHANGED_MARKER) .. (s_irregular and IRREG_MARKER or "")
ret = ret .. '\n| style="padding-bottom:4px;" | ' .. (n_changed and n_mut or UNCHANGED_MARKER) .. (n_irregular and IRREG_MARKER or "")
ret = ret .. '\n|-'
ret = ret .. '\n|-'
if s_irregular or n_irregular then
if s_irregular then
ret = ret .. '\n| colspan=2 | <small style="font-size:85%;">' .. IRREGMARKER .. 'Irregular.</small>'
ret = ret .. '\n| colspan=2 | <small style="font-size:85%;line-height:1.2;display:block;padding-bottom:6px;">' .. IRREG_MARKER .. 'Irregular.</small>'
end
end
if s_changed or n_changed then
if s_changed then
ret = ret .. "\n| colspan=2 | <small style=\"font-size:85%;\">''Note:'' Some of these forms may be hypothetical. Not every possible mutated form of every word actually occurs.</small>"
ret = ret .. "\n| colspan=2 | <small style=\"font-size:85%;line-height:1.2;display:block;padding-bottom:6px;\">''Note:'' Some of these forms may be hypothetical. Not every possible mutated form of every word actually occurs.</small>"
end
end
ret = ret .. '\n|}'
ret = ret .. '\n|}'
if (s_irregular or n_irregular) and (not args["nocat"]) then
if s_irregular and (not args["nocat"]) then
ret = ret .. "[[Categories:Riyan terms with irregular mutation]]"
ret = ret .. "[[Categories:Riyan terms with irregular mutation]]"
end
end

Latest revision as of 21:46, 25 February 2024

Documentation for this module may be created at Module:ryn-mut/documentation

local export = {}

local params = {
	[1] = {alias_of = "r"},
	r = {default = mw.title.getCurrentTitle().text},
	i = {},
	initial = {alias_of = "i"},
	s = {},
	soft = {alias_of = "s"},
	lenited = {alias_of = "s"},
	nocat = {type = "boolean"},
}

local IRREG_MARKER = "<sup>△</sup>"
local UNCHANGED_MARKER = "<i>unchanged</i>"

local lenition = {
	["b"] = "v",
	["k"] = "g",
	["d"] = "z",
	["f"] = "h",
	["g"] = "ŗ",
	["ŗ"] = "",
	["p"] = "b",
	["s"] = "r",
	["t"] = "d",
	["z"] = "r",
}

local function get_radical_data(term, initial_override)
	local initial, remainder
	initial = initial_override or mw.ustring.sub(term, 1, 1)
	remainder = mw.ustring.sub(term, 2)
	return initial, remainder
end

local function mutate_soft(data)
	local change = lenition[data.initial]
	if change then
		return change .. data.remainder
	end
	return data.radical
end

function export.mutate(term, initial_override)
	local data = {}
	data.radical = term
	data.initial, data.remainder = get_radical_data(term, initial_override)
	data.soft = mutate_soft(data)
	return data
end

local function get_mutation_info(radical, override, expected)
	local irregular = override and (expected ~= override)
	local mutation = override or expected
	local changed = mutation ~= radical
	return mutation, changed, irregular
end

function export.show(frame)
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local radical = args["r"]
	local data = export.mutate(radical, args["i"])
	local s_mut, s_changed, s_irregular = get_mutation_info(radical, args["s"], data.soft)
	local ret = '{| style="display:table; width:54%; border: 1px solid #b3b3b3; font-size: 95%; text-align: center;'
	ret = ret .. '\n|-'
	ret = ret .. '\n! style="background:#efefef" colspan=2 | [[Appendix:Riyan mutation|Riyan mutation]]'
	ret = ret .. '\n|-'
	ret = ret .. '\n! style="padding-top:4px;" | [[Appendix:Glossary#radical|radical]]'
	ret = ret .. '\n! style="padding-top:4px; | [[Appendix:Glossary#lenition|lenited]]'
	ret = ret .. '\n|-'
	ret = ret .. '\n| style="padding-bottom:4px;" | ' .. radical
	ret = ret .. '\n| style="padding-bottom:4px;" | ' .. (s_changed and s_mut or UNCHANGED_MARKER) .. (s_irregular and IRREG_MARKER or "")
	ret = ret .. '\n|-'
	if s_irregular then
		ret = ret .. '\n| colspan=2 | <small style="font-size:85%;line-height:1.2;display:block;padding-bottom:6px;">' .. IRREG_MARKER .. 'Irregular.</small>'
	end
	if s_changed then
		ret = ret .. "\n| colspan=2 | <small style=\"font-size:85%;line-height:1.2;display:block;padding-bottom:6px;\">''Note:'' Some of these forms may be hypothetical. Not every possible mutated form of every word actually occurs.</small>"
	end
	ret = ret .. '\n|}'
	if s_irregular and (not args["nocat"]) then
		ret = ret .. "[[Categories:Riyan terms with irregular mutation]]"
	end
	return ret
end

return export