Module:snon-mut: Difference between revisions

Melinoë (talk | contribs)
No edit summary
Undo revision 526485 by Sware (talk)
Tag: Undo
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local m_links = require("Module:links")
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local sub = mw.ustring.sub
local upper = mw.ustring.upper
 
local m_l = require("Module:links")


local lang = require("Module:languages").getByCode("snon")
local lang = require("Module:languages").getByCode("snon")
local PAGENAME = mw.loadData("Module:headword/data").pagename


local export = {}
local export = {}


local words = mw.text.split("hello world hi", "%s")


local function repl(forms, param)
local first = table.remove(words, 1)
if param ~= "normal" and forms[param] == forms["normal"] then
local ords = words
return "''not applicable''"
 
function export.mutations(ret, args)
local words = mw.text.split(ret.radical or args.word, "%s")
local lower_radical = mw.ustring.lower(words[1])
local first_letter = match(lower_radical, "^%W*(%w)")
local is_proper = ret.radical ~= lower_radical
local vowels = "([aeiouàèìòù])"
local apostrophe
words[1] = " "
words = table.concat(words, " ")
if args.len then
ret.lenition = args.len
elseif match(first_letter, "[bcdfgmptsnv]") then
ret.lenition = ret.radical:gsub("^(.)", "%1h") .. words
elseif match(first_letter, vowels) then -- h-prothesis
ret.lenition = "h'" .. lower_radical .. words
apostrophe = true
else
ret.lenition = "-"
end
end
local ret = m_links.full_link({lang = lang, term = forms[param]})
local eclipsis_prefixes = {
["b"] = "m", ["c"] = "g", ["d"] = "n", ["f"] = "v", ["g"] = "n",
["p"] = "b", ["t"] = "d", ["h"] = "gh", ["s"] = "z", ["v"] = "b",
}
if args.ecl then
ret.eclipsis = args.ecl
elseif eclipsis_prefixes[first_letter] then
ret.eclipsis = eclipsis_prefixes[first_letter] .. sub(lower_radical, 2, -1) .. words
elseif match(first_letter, vowels) then
ret.eclipsis = "n'" .. lower_radical .. words
apostrophe = true
elseif match(lower_radical, "^ghi" .. vowels) then
ret.eclipsis = gsub(lower_radical, "^ghi" .. vowels, "ni%1") .. words
else
ret.eclipsis = "-"
end
if param == "len" ~= forms.normal then
if is_proper then
ret = ret .. "<br/>''after " .. m_links.full_link({lang = lang}) .. ",'' " .. m_links.full_link({lang = lang})
if apostrophe then
ret.eclipsis = "n" .. gsub(ret.eclipsis, "^n'(%w)", upper)
ret.lenition = "h" .. gsub(ret.lenition, "^h'(%w)", upper)
else
ret.eclipsis = gsub(ret.eclipsis, "^(%w)", upper)
ret.lenition = gsub(ret.lenition, "^(%w)", upper)
end
end
end
return ret
return ret, apostrophe
end
end


 
function export.mutation_table(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] = {default = PAGENAME, template_default = "bèdh"},
}
["ecl"] = {},
["len"] = {},
["temp_len"] = {type = "boolean"},
["temp_ecl"] = {type = "boolean"},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local args = require("Module:parameters").process(frame:getParent().args, params)
local title = mw.loadData("Module:headword/data").pagename
local is_vowel
local forms = require("Module:snon-common").mutations(title, args[1])
local ret = {radical = args[1]}
local wikicode = mw.ustring.find(mw.ustring.lower(title), "^[aeiouàèìòù]") and table_vowel or table_cons
ret, is_vowel = export.mutations(ret, args)
if args.temp_len then
return ret.lenition == "-" and ret.radical or ret.lenition
end
local result = frame:expandTemplate{  
if args.temp_ecl then
title = 'inflection-table-top',  
return ret.eclipsis == "-" and ret.radical or ret.eclipsis
args = {
end
title = '[[Appendix:Scots Norse mutations|Mutated forms]] of ' .. require("Module:links").full_link({lang = lang, alt = title}, 'term'),
palette = 'blue'
local links = {}
}
for k, v in pairs(ret) do
}
if v == "-" then
result = result .. '\n'
links[k] = "''not applicable''"
result = result .. mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", function(param) return repl(forms, param) end)
else
result = result .. frame:expandTemplate{  
links[k] = m_l.full_link{lang = lang, term = v}
title = 'inflection-table-bottom',  
end
args = {
end
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 table_args = {
palette = "blue",
notes = "<p style=font-size:85%;>''Note:'' Certain mutated forms of some words can never occur in standard Scots Norse.<br>All possible mutated forms are displayed for convenience.</p>",
title = "[[Scots Norse#Mutation|Mutated forms]] of " .. ret.radical,
-- class = "wide",
}
}
return result
local contents = [[
|-
! radical !! ]] .. (is_vowel and "h-prothesis" or "lenition") .. [[ !! eclipsis
|-
| {radical} || {lenition} || {eclipsis}
]]
contents = require('Module:string utilities').format(contents, links)
return require("Module:inflection table").inflection_table(frame, table_args, contents)
end
end


return export
return export