|
|
| (10 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| local export = {} | | local m_links = require("Module:links") |
|
| |
|
| local yesno = require("Module:yesno") | | local lang = require("Module:languages").getByCode("snon") |
|
| |
|
| local toNFC = mw.ustring.toNFC | | local export = {} |
| 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("snon")
| |
| local PAGENAME = mw.loadData("Module:headword/data").pagename
| |
| local MARKER = "<sup>△</sup>"
| |
|
| |
|
| local mutation_rules = {
| |
| ["b"] = {"b", "m", "bh"},
| |
| ["c"] = {"g", "ngh", "ch"},
| |
| ["d"] = {"d", "n", "dh"},
| |
| ["g"] = {"g", "ng", "gh"},
| |
| ["h"] = {"gh", "nh", "'"},
| |
| ["l"] = {"l", "l", "lh"},
| |
| ["m"] = {"b", "m", "mh"},
| |
| ["n"] = {"d", "n", "nh"},
| |
| ["p"] = {"b", "mh", "ph"},
| |
| ["f"] = {"v", "mh", "fh"},
| |
| ["v"] = {"b", "m", "vh"},
| |
| ["r"] = {"r", "r", "rh"},
| |
| ["s"] = {"z", "nh","sh"},
| |
| ["t"] = {"d", "nh", "th"},
| |
| }
| |
|
| |
|
| function export.get_mutation_data(term) | | local function repl(forms, param) |
| local data = {radical = term}
| | if param ~= "normal" and forms[param] == forms["normal"] then |
|
| | return "''not applicable''" |
| 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 = "h-"
| |
| return data
| |
| end | | end |
| | | |
| local initial, final, mut | | local ret = m_links.full_link({lang = lang, term = forms[param]}) |
| 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 ret |
|
| |
| return data | |
| end | | 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 table_cons = [=[ |
| | ! radical |
| | ! lenition |
| | ! eclipsis |
| | |- |
| | | {{{normal}}} |
| | | {{{len}}} |
| | | {{{ecl}}} |
| | ]=] |
| | |
| | |
| | local table_vowel = [=[ |
| | ! radical !! eclipsis !! with ''h''-prothesis |
| | |- |
| | | {{{normal}}} |
| | | {{{ecl}}} |
| | | {{{hpro}}} |
| | ]=] |
| | |
| | |
| | function export.mut(frame) |
| local params = { | | local params = { |
| [1] = {}, | | [1] = {}, |
| ["soft"] = {}, | | } |
| ["nasal"] = {}, | | |
| ["aspirate"] = {}, | | local args = require("Module:parameters").process(frame:getParent().args, params) |
| ["nocat"] = {type = "boolean"}, | | |
| | local title = mw.loadData("Module:headword/data").pagename |
| | local forms = require("Module:snon-common").mutations(title, args[1]) |
| | local wikicode = mw.ustring.find(mw.ustring.lower(title), "^[aeiouàèìòù]") and table_vowel or table_cons |
| | |
| | local result = frame:expandTemplate{ |
| | title = 'inflection-table-top', |
| | args = { |
| | title = '[[Appendix:Scots Norse mutations|Mutated forms]] of ' .. require("Module:links").full_link({lang = lang, alt = title}, 'term'), |
| | palette = 'blue' |
| | } |
| | } |
| | result = result .. '\n' |
| | result = result .. mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", function(param) return repl(forms, param) end) |
| | result = result .. frame:expandTemplate{ |
| | title = 'inflection-table-bottom', |
| | args = { |
| | notes = '<p style="font-size:85%;"><i>Note:</i> Certain mutated forms of some words can never occur in standard Modern Scots Norse.<br>All possible mutated forms are displayed for convenience.</p>' |
| | } |
| } | | } |
| 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{ title = 'inflection-table-top',
| |
| args = { title = '[[Appendix:Scots Norse mutations|Mutated forms]] of ' .. require("Module:links").full_link({lang = lang, alt = title}, 'term'), palette = 'blue' } }
| |
| result = result .. '\n! [[radical]]'
| |
| result = result .. '\n! ' .. (data.vowel and 'gh-prothesis' or '[[soft mutation|voiced]]')
| |
| result = result .. '\n! ' .. (data.vowel and 'n-prothesis' or '[[nasal mutation|nasal]]')
| |
| result = result .. '\n! ' .. (data.vowel and 'h-prothesis' or '[[aspirate mutation|lenition]]')
| |
| result = result .. '\n|-'
| |
| result = result .. '\n| ' .. require("Module:links").full_link({lang = lang, term = data.radical})
| |
| result = result .. '\n| ' .. soft
| |
| result = result .. '\n| ' .. nasal
| |
| result = result .. '\n| ' .. aspirate
| |
| notes = ''
| |
| if has_irreg_soft or has_irreg_nasal or has_irreg_aspirate then
| |
| notes = notes .. '<p style="font-size:85%;">' .. MARKER .. 'Irregular.</p>'
| |
| end
| |
| if has_soft or has_nasal or has_aspirate then
| |
| notes = notes .. '<p style="font-size:85%;"><i>Note:</i> Certain mutated forms of some words can never occur in standard Scots Norse.<br>All possible mutated forms are displayed for convenience.</p>'
| |
| end
| |
| result = result .. '\n' .. frame:expandTemplate{ title = 'inflection-table-bottom', args = { notes = notes } }
| |
| if not args.nocat and (has_irreg_soft or has_irreg_nasal or has_irreg_aspirate) then
| |
| result = result .. require("Module:utilities").format_categories("Welsh terms with irregular mutation", lang)
| |
| end
| |
| return result | | return result |
| end | | end |
|
| |
|
| return export | | return export |
Documentation for this module may be created at Module:snon-mut/doc
local m_links = require("Module:links")
local lang = require("Module:languages").getByCode("snon")
local export = {}
local function repl(forms, param)
if param ~= "normal" and forms[param] == forms["normal"] then
return "''not applicable''"
end
local ret = m_links.full_link({lang = lang, term = forms[param]})
return ret
end
local table_cons = [=[
! radical
! lenition
! eclipsis
|-
| {{{normal}}}
| {{{len}}}
| {{{ecl}}}
]=]
local table_vowel = [=[
! radical !! eclipsis !! with ''h''-prothesis
|-
| {{{normal}}}
| {{{ecl}}}
| {{{hpro}}}
]=]
function export.mut(frame)
local params = {
[1] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local title = mw.loadData("Module:headword/data").pagename
local forms = require("Module:snon-common").mutations(title, args[1])
local wikicode = mw.ustring.find(mw.ustring.lower(title), "^[aeiouàèìòù]") and table_vowel or table_cons
local result = frame:expandTemplate{
title = 'inflection-table-top',
args = {
title = '[[Appendix:Scots Norse mutations|Mutated forms]] of ' .. require("Module:links").full_link({lang = lang, alt = title}, 'term'),
palette = 'blue'
}
}
result = result .. '\n'
result = result .. mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", function(param) return repl(forms, param) end)
result = result .. frame:expandTemplate{
title = 'inflection-table-bottom',
args = {
notes = '<p style="font-size:85%;"><i>Note:</i> Certain mutated forms of some words can never occur in standard Modern Scots Norse.<br>All possible mutated forms are displayed for convenience.</p>'
}
}
return result
end
return export