Module:snon-mut-decl: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (One intermediate revision by the same user not shown) | |||
| Line 126: | Line 126: | ||
local result = frame:expandTemplate{ | local result = frame:expandTemplate{ | ||
require("Template: | args { | ||
require("Template:Snon-decl-blank-full") | |||
} | |||
} | } | ||
return result | return result | ||
Latest revision as of 18:15, 7 April 2026
Documentation for this module may be created at Module:snon-mut-decl/doc
local export = {}
local yesno = require("Module:yesno")
local toNFC = mw.ustring.toNFC
local toNFD = mw.ustring.toNFD
local ulower = mw.ustring.lower
local umatch = mw.ustring.match
local usub = mw.ustring.sub
local GRAVE = "\204\128"
local lang = require("Module:languages").getByCode("cy")
local PAGENAME = mw.loadData("Module:headword/data").pagename
local MARKER = "<sup>△</sup>"
local mutation_rules = {
["b"] = {"bb", "m", "bh"},
["bh"] = {"b", "m", "gh"},
["c"] = {"g", "ngh", "ch"},
["ch"] = {"gh", "ngh"},
["d"] = {"dd", "n", "dh"},
["dh"] = {"d", "n", "gh"},
["g"] = {"gg", "ng", "gh"},
["h"] = {"gh", "nh", "ch"},
["l"] = {"lh"},
["m"] = {"mh"},
["n"] = {"nh"},
["p"] = {"b", "mh", "ph"},
["ph"] = {"bh", "mh", "h"},
["r"] = {"rr", "rh"},
["s"] = {"z", "sh"},
["t"] = {"d", "nh", "th"},
["th"] = {"dh", "nh", "ch"},
}
function export.get_mutation_data(term)
local data = {radical = term}
local term_lower = term:gsub("^.[\128-\191]*", ulower) -- term with lowercase initial
data.is_uppercase = term_lower ~= term
local normalized = toNFD(term_lower)
data.vowel = normalized:match("^[aeiouøy]") and true or false
if data.vowel then
data.final = term_lower
data.mut1 = "gh-"
data.mut2 = "n-"
data.mut3 = "ch-"
return data
end
local initial, final, mut
for i = 3, 1, -1 do
initial = usub(normalized, 1, i)
mut = mutation_rules[initial]
if mut then
final = usub(normalized, i + 1)
break
elseif i == 1 then
error(("no mutation rule found for %s"):format(term))
end
end
if type(mut) == "table" then
for k, v in pairs(mut) do
if tonumber(k) then
data["mut" .. k] = v
end
end
data.colloquial = mut.colloquial
end
data.final = toNFC(final)
return data
end
local function construct_mutation(data, accel_form, initial, override)
local normal_mutation
if not initial then
normal_mutation = nil
else
normal_mutation = initial .. data.final
if data.is_uppercase then
normal_mutation = require("Module:string utilities").ucfirst(normal_mutation)
end
end
local has_override = override
if not yesno(override, true) or override == "-" then -- TODO: yesno to be removed.
override = nil
end
local has_irreg_mutation = has_override and override ~= normal_mutation
local mutation
-- don't combine the following into A and B or C because `override` may be nil
if has_override then
mutation = override
else
mutation = normal_mutation
end
local marker = has_irreg_mutation and MARKER or ""
if mutation then
return require("Module:links").full_link({lang = lang, accel = {form = accel_form, lemma = data.radical}, term = mutation}) .. marker, true, has_irreg_mutation
else
return "''unchanged''" .. marker, false, has_irreg_mutation
end
end
function export.show(frame)
local params = {
[1] = {},
["soft"] = {},
["nasal"] = {},
["aspirate"] = {},
["nocat"] = {type = "boolean"},
}
local parargs = frame:getParent().args
local args = require("Module:parameters").process(parargs, params)
local title = args[1] or PAGENAME
local data = export.get_mutation_data(title)
local soft, has_soft, has_irreg_soft = construct_mutation(data, "soft", data.mut1, args.soft)
local nasal, has_nasal, has_irreg_nasal = construct_mutation(data, "nasal", data.mut2, args.nasal)
local aspirate, has_aspirate, has_irreg_aspirate = construct_mutation(data, data.vowel and "h-prothesis" or "aspirate", data.mut3, args.aspirate)
local result = frame:expandTemplate{
args {
require("Template:Snon-decl-blank-full")
}
}
return result
end
return export