Module:ryn-mut: Difference between revisions

Jump to navigation Jump to search
ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
No edit summary
No edit summary
Line 11: Line 11:
local UNCHANGED_MARKER = "<i>unchanged</i>"
local UNCHANGED_MARKER = "<i>unchanged</i>"


local function is_vowel(c)
local mutation_rules = {
return c == "a" or c == "e" or c == "i" or c == "í" or c == "o" or c == "ó" or c == "u"
["b"] = {"bh", "mb"},
["bh"] = {nil, "mbh"},
["c"] = {"ch", "nc"},
["ch"] = {nil, "nch"},
["d"] = {"d̦", "nd"},
["d̦"] = {"d̦", "nd̦"},
["dh"] = {nil, "ndh"},
["f"] = {nil, "mf"},
["g"] = {"gh", "ng"},
["gh"] = {nil, "ngh"},
["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 initial, prevowel, remainder
if mw.ustring.sub(term, 2, 2) == "h" then
initial = mw.ustring.sub(term, 1, 2)
remainder = mw.ustring.sub(term, 3)
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 is_labial_consonant(c)
local function mutate_soft(data)
return c == "p" or c == "b"
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 return change .. data.remainder end
if data.prevowel then return data.initial .. "i" .. data.remainder end
return data.radical
end
end


local function n_is_exempt(c)
local function mutate_nasal(data)
return c == "m" or c == "n"
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
end


function export.n_mutate(radical, override)
function export.mutate(term)
local function n_mutate_default(radical)
local data = {}
local initial = string.sub(radical, 1, 1)
data.radical = term
if n_is_exempt(initial) then return radical end
data.initial, data.vowel, data.prevowel, data.remainder = get_radical_data(term)
if initial == "r" then return "d" .. radical end
data.soft = mutate_soft(data)
if is_vowel(initial) then return "n-" .. radical end
data.nasal = mutate_nasal(data)
if is_labial_consonant(initial) then return "m" .. radical end
return data
return "n" .. radical
end
end
 
local mut = n_mutate_default(radical)
local function get_mutation_info(radical, override, expected)
if override and mut ~= override then
local irregular = (not override) or (expected ~= override)
return override, true
local mutation = override or expected
else
local changed = mutation ~= radical
return mut, false
return mutation, changed, irregular
end
end
end


function export.show(frame)
function export.show(frame)
local args = require("Module:parameters").process(frame:getParent().args, params)
local args = require("Module:parameters").process(frame:getParent().args, params)
local r = args["r"]
local radical = args["r"]
local n, n_irregular = export.n_mutate(r, args["n"])
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:50%; 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=4 | [[Appendix:Riyan mutation|Riyan mutation]]'
ret = ret .. '\n! style="background:#efefef" colspan=3 | [[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#nasal|nasal]]'
ret = ret .. '\n! style="padding-top:4px; | [[Appendix:Glossary#nasal|nasal]]'
ret = ret .. '\n|-'
ret = ret .. '\n|-'
ret = ret .. '\n| style="padding-bottom:4px;" | ' .. r
ret = ret .. '\n| style="padding-bottom:4px;" | ' .. radical
ret = ret .. '\n| style="padding-bottom:4px;" | ' .. ((n == r) and UNCHANGED_MARKER or n) .. (n_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 n_irregular then
if s_irregular or n_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%;">' .. IRREGMARKER .. 'Irregular.</small>'
end
end
if n ~= r then
if s_changed or n_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%;\">''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 n_irregular and (not args["nocat"]) then
if (s_irregular or n_irregular) and (not args["nocat"]) then
ret = ret .. "[[Categories:Riyan terms with irregular mutation]]"
ret = ret .. "[[Categories:Riyan terms with irregular mutation]]"
end
end

Navigation menu