Module:ryn-mut: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
local mutation_rules = { | local mutation_rules = { | ||
["b"] = {" | ["b"] = {"v", "mb"}, | ||
[" | ["v"] = {nil, "mv"}, | ||
[" | ["k"] = {"h", "nk"}, | ||
[" | ["h"] = {"r̦", "nh"}, | ||
["d"] = {"d̦", "nd"}, | ["d"] = {"d̦", "nd"}, | ||
["d̦"] = {"d̦", "nd̦"}, | ["d̦"] = {"d̦", "nd̦"}, | ||
[" | ["ð"] = {nil, "nð"}, | ||
["f"] = {nil, "mf"}, | ["f"] = {nil, "mf"}, | ||
["g"] = {" | ["g"] = {"r̦", "ng"}, | ||
[" | ["r̦"] = {nil, "nr̦"}, | ||
["l"] = {nil, "nl"}, | ["l"] = {nil, "nl"}, | ||
[" | ["hl"] = {"l", "nl"}, | ||
["m"] = {}, | ["m"] = {}, | ||
["n"] = {}, | ["n"] = {}, | ||
["p"] = {"b", "mp"}, | ["p"] = {"b", "mp"}, | ||
["r"] = {nil, "dr"}, | ["r"] = {nil, "dr"}, | ||
[" | ["hr"] = {"r", "dr"}, | ||
["s"] = {"ș", "ns"}, | ["s"] = {"ș", "ns"}, | ||
["ș"] = {"ș", "nș"}, | ["ș"] = {"ș", "nș"}, | ||
["t"] = {"ț", "nt"}, | ["t"] = {"ț", "nt"}, | ||
["ț"] = {"ț", "nț"}, | ["ț"] = {"ț", "nț"}, | ||
} | } | ||
local vowel_pattern = "[ | local vowel_pattern = "[aáeiíouú]" | ||
local | local gh_to_v_vowel_pattern = "[eiíuú]" | ||
local function get_radical_data(term) | local function get_radical_data(term) | ||
local initial, prevowel, remainder | local initial, prevowel, remainder | ||
initial = mw.ustring.sub(term, 1, 1) | |||
if initial == "h" then | |||
local next_initial = mw.ustring.sub(term, 2, 2) | |||
if next_initial == "r" or next_initial == "l" then | |||
initial = initial .. next_initial | |||
prevowel = mw.ustring.find(mw.ustring.sub(term, 3, 3), vowel_pattern) | |||
remainder = mw.ustring.sub(term, 3) | |||
return initial, false, prevowel, remainder | |||
end | |||
end | end | ||
prevowel = mw.ustring.find(mw.ustring.sub(term, 2, 2), vowel_pattern) | |||
remainder = mw.ustring.sub(term, 2) | |||
local vowel = mw.ustring.find(initial, vowel_pattern) and true or false | local vowel = mw.ustring.find(initial, vowel_pattern) and true or false | ||
return initial, vowel, prevowel, remainder | return initial, vowel, prevowel, remainder | ||
Line 62: | Line 64: | ||
if change then | if change then | ||
local r_initial = mw.ustring.sub(data.remainder, 1, 1) | local r_initial = mw.ustring.sub(data.remainder, 1, 1) | ||
if change == " | if change == "r̦" and mw.ustring.find(r_initial, gh_to_v_vowel_pattern) then | ||
change = " | change = "v" | ||
end | end | ||
return change .. data.remainder | return change .. data.remainder |
Revision as of 16:34, 8 August 2023
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},
n = {},
s = {},
nocat = {type = "boolean"},
}
local IRREG_MARKER = "<sup>△</sup>"
local UNCHANGED_MARKER = "<i>unchanged</i>"
local mutation_rules = {
["b"] = {"v", "mb"},
["v"] = {nil, "mv"},
["k"] = {"h", "nk"},
["h"] = {"r̦", "nh"},
["d"] = {"d̦", "nd"},
["d̦"] = {"d̦", "nd̦"},
["ð"] = {nil, "nð"},
["f"] = {nil, "mf"},
["g"] = {"r̦", "ng"},
["r̦"] = {nil, "nr̦"},
["l"] = {nil, "nl"},
["hl"] = {"l", "nl"},
["m"] = {},
["n"] = {},
["p"] = {"b", "mp"},
["r"] = {nil, "dr"},
["hr"] = {"r", "dr"},
["s"] = {"ș", "ns"},
["ș"] = {"ș", "nș"},
["t"] = {"ț", "nt"},
["ț"] = {"ț", "nț"},
}
local vowel_pattern = "[aáeiíouú]"
local gh_to_v_vowel_pattern = "[eiíuú]"
local function get_radical_data(term)
local initial, prevowel, remainder
initial = mw.ustring.sub(term, 1, 1)
if initial == "h" then
local next_initial = mw.ustring.sub(term, 2, 2)
if next_initial == "r" or next_initial == "l" then
initial = initial .. next_initial
prevowel = mw.ustring.find(mw.ustring.sub(term, 3, 3), vowel_pattern)
remainder = mw.ustring.sub(term, 3)
return initial, false, prevowel, remainder
end
end
prevowel = mw.ustring.find(mw.ustring.sub(term, 2, 2), vowel_pattern)
remainder = mw.ustring.sub(term, 2)
local vowel = mw.ustring.find(initial, vowel_pattern) and true or false
return initial, vowel, prevowel, remainder
end
local function mutate_soft(data)
if data.vowel then
if data.initial == "i" then return data.radical end
return "i" .. data.radical
end
local change = mutation_rules[data.initial][1]
if change then
local r_initial = mw.ustring.sub(data.remainder, 1, 1)
if change == "r̦" and mw.ustring.find(r_initial, gh_to_v_vowel_pattern) then
change = "v"
end
return change .. data.remainder
end
if data.prevowel and (not mw.ustring.sub(data.remainder, 1, 1) == "i") 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
end
function export.mutate(term)
local data = {}
data.radical = term
data.initial, data.vowel, data.prevowel, data.remainder = get_radical_data(term)
data.soft = mutate_soft(data)
data.nasal = mutate_nasal(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)
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;'
ret = ret .. '\n|-'
ret = ret .. '\n! style="background:#efefef" colspan=3 | [[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! style="padding-top:4px; | [[Appendix:Glossary#nasal|nasal]]'
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| style="padding-bottom:4px;" | ' .. (n_changed and n_mut or UNCHANGED_MARKER) .. (n_irregular and IRREG_MARKER or "")
ret = ret .. '\n|-'
if s_irregular or n_irregular then
ret = ret .. '\n| colspan=3 | <small style="font-size:85%;">' .. IRREG_MARKER .. 'Irregular.</small>'
end
if s_changed or n_changed then
ret = ret .. "\n| colspan=3 | <small style=\"font-size:85%;\">''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 or n_irregular) and (not args["nocat"]) then
ret = ret .. "[[Categories:Riyan terms with irregular mutation]]"
end
return ret
end
return export