local export = {}
local m_links = require("Module:links")
local m_utils = require("Module:utilities")
local lang = require("Module:languages").getByCode("odt")
local decl_data = {}
local function devoice(stem)
stem = mw.ustring.gsub(stem, "ng$", "nc")
stem = mw.ustring.gsub(stem, "d$", "t")
stem = mw.ustring.gsub(stem, "b$", "p")
stem = mw.ustring.gsub(stem, "v$", "f")
stem = mw.ustring.gsub(stem, "z$", "s")
return stem
end
local function umlaut(stem)
subStr = string.sub(stem, -4, -1)
if string.find(subStr, "ie") then
stem = stem.gsub(stem, "ie", "iu")
end
if string.find(subStr, "e") and not string.find(subStr, "ei") then
stem = stem.gsub(stem, "e", "i")
end
if string.find(subStr, "a") then
stem = stem.gsub(stem, "a", "e")
end
if string.find(subStr, "o") and not string.find(stem, "uo") then
stem = stem.gsub(stem, "o", "u")
end
stem = mw.ustring.gsub(stem, "ce", "ke")
stem = mw.ustring.gsub(stem, "ci", "ki")
return stem
end
local function C_to_K(stem)
stem = mw.ustring.gsub(stem, "cc$", "ck")
stem = mw.ustring.gsub(stem, "c$", "k")
stem = mw.ustring.gsub(stem, "z$", "c")
return stem
end
local function K_to_C(stem)
stem = mw.ustring.gsub(stem, "ck$", "cc")
stem = mw.ustring.gsub(stem, "k$", "c")
return stem
end
local function degeminate(stem)
stem = mw.ustring.gsub(stem, "()%1$", "%1")
stem = mw.ustring.gsub(stem, "ck$", "k")
return stem
end
local function categorize(gender)
if gender == 'm' then
cat_gender='masculine'
elseif gender == 'f' then
cat_gender='feminine'
elseif gender == 'n' then
cat_gender='neuter'
else
cat_gender='masculine'
-- error("Unrecognized gender '" .. gender .. "'. Only masculine ('m'), feminine ('f') or neuter ('n')")
end
return cat_gender
end
decl_data = {
params = {
= {},
= {},
= {},
= {alias_of = "g"},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
cat_type = "a-stem noun"
cat_gender = categorize(args.g)
data.decl_type = "" ..cat_gender.. " " ..cat_type.. ""
table.insert(data.categories, "Old Dutch " .. cat_gender .. " " .. cat_type .. "s")
stem_C = K_to_C(args)
stem_K = C_to_K(args)
devoiced_stem = devoice(degeminate(stem_C))
data.forms = {devoiced_stem}
data.forms = {devoiced_stem}
data.forms = {stem_K .. "es"}
data.forms = {stem_K .. "e"}
data.forms = {stem_C .. "a"}
data.forms = {stem_C .. "a"}
data.forms = {stem_C .. "o"}
data.forms = {stem_C .. "on"}
if args.g == 'n' then
data.forms = {devoiced_stem}
data.forms = {devoiced_stem}
end
end
})
decl_data = {
params = {
= {},
= {},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
args.g='f'
cat_type = "ō/ōn-stem noun"
cat_gender = categorize(args.g)
data.decl_type = "" ..cat_gender.. " " ..cat_type.. ""
table.insert(data.categories, "Old Dutch " .. cat_type .. "s")
data.forms = {args .. "a"}
data.forms = {args .. "a", args .. "on"}
data.forms = {args .. "on"}
data.forms = {args .. "on"}
data.forms = {args .. "a", args .. "on"}
data.forms = {args .. "a", args .. "on"}
data.forms = {args .. "ono"}
data.forms = {args .. "on"}
end
})
decl_data = {
params = {
= {},
= {},
= {},
= {alias_of = "g"},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
cat_type = "ja-stem noun"
cat_gender = categorize(args.g)
data.decl_type = "" ..cat_gender.. " " ..cat_type.. ""
table.insert(data.categories, "Old Dutch " .. cat_gender .. " " .. cat_type .. "s")
stem_C = K_to_C(args)
stem_K = C_to_K(args)
data.forms = {stem_K .. "i"}
data.forms = {stem_K .. "i"}
data.forms = {stem_K .. "is"}
data.forms = {stem_K .. "i"}
data.forms = {stem_C .. "a"}
data.forms = {stem_C .. "a"}
data.forms = {stem_C .. "o"}
data.forms = {stem_C .. "on"}
if args.g == 'n' then
data.forms = {stem_K .. "i"}
data.forms = {stem_K .. "i"}
end
end
})
decl_data = {
params = {
= {},
= {},
= {},
= {alias_of = "g"},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
cat_type = "wa-stem noun"
cat_gender = categorize(args.g)
data.decl_type = "" ..cat_gender.. " " ..cat_type.. ""
table.insert(data.categories, "Old Dutch " .. cat_gender .. " " .. cat_type .. "s")
data.forms = {args .. "o"}
data.forms = {args .. "o"}
data.forms = {args .. "wes"}
data.forms = {args .. "we"}
data.forms = {args .. "wa"}
data.forms = {args .. "wa"}
data.forms = {args .. "wo"}
data.forms = {args .. "won"}
if args.g == 'n' then
data.forms = {args .. "o"}
data.forms = {args .. "o"}
end
end
})
decl_data = {
params = {
= {},
= {},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
args.g='f'
cat_type = "wō-stem noun"
cat_gender = categorize(args.g)
data.decl_type = "" ..cat_gender.. " " ..cat_type.. ""
table.insert(data.categories, "Old Dutch " .. cat_type .. "s")
data.forms = {args .. "wa"}
data.forms = {args .. "wa", args .. "won"}
data.forms = {args .. "won"}
data.forms = {args .. "won"}
data.forms = {args .. "wa", args .. "won"}
data.forms = {args .. "wa", args .. "won"}
data.forms = {args .. "wono"}
data.forms = {args .. "won"}
end
})
decl_data = {
params = {
= {},
= {},
= {},
= {},
= {},
= {alias_of = "g"},
= {alias_of = "w"},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
cat_type = "i-stem noun"
cat_gender = categorize(args.g)
data.decl_type = "" ..cat_gender.. " " ..cat_type.. ""
table.insert(data.categories, "Old Dutch " .. cat_gender .. " " .. cat_type .. "s")
stem_C = K_to_C(args)
stem_K = C_to_K(args)
umlauted_stem_C = umlaut(stem_C)
umlauted_stem_K = umlaut(stem_K)
devoiced_stem = degeminate(devoice(stem_C))
if args.w == 'l' or args.nomut == '1' then
umlauted_stem_C = stem_C
umlauted_stem_K = stem_K
end
data.forms = {devoiced_stem}
data.forms = {devoiced_stem}
data.forms = {umlauted_stem_K .. "is"}
data.forms = {umlauted_stem_K .. "i"}
data.forms = {umlauted_stem_K .. "i"}
data.forms = {umlauted_stem_K .. "i"}
data.forms = {umlauted_stem_C .. "o"}
data.forms = {umlauted_stem_K .. "in", umlauted_stem_C .. "on"}
if args.w == 'l' then
data.forms = {umlauted_stem_K .. "i"}
data.forms = {umlauted_stem_K .. "i"}
end
if args.g == 'f' then
data.forms = {umlauted_stem_K .. "i"}
end
end
})
decl_data = {
params = {
= {},
= {},
= {},
= {},
= {},
= {alias_of = "g"},
= {alias_of = "w"},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
cat_type = "u-stem noun"
cat_gender = categorize(args.g)
data.decl_type = "" ..cat_gender.. " " ..cat_type.. ""
table.insert(data.categories, "Old Dutch " .. cat_gender .. " " .. cat_type .. "s")
stem_C = K_to_C(args)
stem_K = C_to_K(args)
umlauted_stem_C = umlaut(stem_C)
umlauted_stem_K = umlaut(stem_K)
devoiced_stem = degeminate(devoice(stem_C))
if args.w == 'l' or args.nomut == '1' then
umlauted_stem_C = stem_C
umlauted_stem_K = stem_K
end
data.forms = {devoiced_stem}
data.forms = {devoiced_stem}
data.forms = {umlauted_stem_K .. "is"}
data.forms = {umlauted_stem_K .. "i"}
data.forms = {umlauted_stem_K .. "i"}
data.forms = {umlauted_stem_K .. "i"}
data.forms = {stem_C .. "o"}
data.forms = {stem_C .. "on"}
if args.w == 'l' then
data.forms = {stem_C .. "o"}
data.forms = {stem_C .. "o"}
end
if args.g == 'f' then
data.forms = {umlauted_stem_K .. "i"}
end
end
})
decl_data = {
params = {
= {},
= {},
= {},
= {alias_of = "g"},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
cat_type = "an-stem noun"
cat_gender = categorize(args.g)
data.decl_type = "" ..cat_gender.. " " ..cat_type.. ""
table.insert(data.categories, "Old Dutch " .. cat_gender .. " " .. cat_type .. "s")
stem_C = K_to_C(args)
stem_K = C_to_K(args)
data.forms = {stem_C .. "o"}
data.forms = {stem_C .. "on"}
data.forms = {stem_K .. "in"}
data.forms = {stem_K .. "in"}
data.forms = {stem_C .. "on"}
data.forms = {stem_C .. "on"}
data.forms = {stem_C .. "ono"}
data.forms = {stem_C .. "on"}
if args.g == 'n' then
data.forms = {stem_C .. "a"}
data.forms = {stem_C .. "a"}
data.forms = {stem_C .. "on", stem_C .. "a"}
data.forms = {stem_C .. "on", stem_C .. "a"}
end
end
})
decl_data = {
params = {
= {},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
args.g='f'
args.nopl='1'
cat_type = "īn-stem noun"
cat_gender = categorize(args.g)
data.decl_type = "" ..cat_gender.. " " ..cat_type.. ""
table.insert(data.categories, "Old Dutch " .. cat_type .. "s")
data.forms = {args .. "i"}
data.forms = {args .. "i"}
data.forms = {args .. "i"}
data.forms = {args .. "i"}
end
})
decl_data = {
params = {
= {},
= {},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
data.decl_type = "consonant stem"
stem_C = K_to_C(args)
stem_K = C_to_K(args)
devoiced_stem = devoice(degeminate(stem_C))
data.forms = {devoiced_stem}
data.forms = {devoiced_stem}
data.forms = {stem_K .. "es"}
data.forms = {stem_K .. "e"}
data.forms = {devoiced_stem}
data.forms = {devoiced_stem}
data.forms = {stem_C .. "o"}
data.forms = {stem_C .. "on"}
table.insert(data.categories, "Old Dutch consonant stem nouns")
end
})
decl_data = {
params = {
= {},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
data.decl_type = "r-stem"
data.forms = {args}
data.forms = {args}
data.forms = {args}
data.forms = {args}
data.forms = {args}
data.forms = {args}
data.forms = {args .. "o"}
data.forms = {args .. "on"}
table.insert(data.categories, "Old Dutch r-stem nouns")
end
})
decl_data = {
params = {
= {},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
data.decl_type = "z-stem"
stem_C = K_to_C(args)
stem_K = C_to_K(args)
devoiced_stem = devoice(degeminate(stem_C))
data.forms = {devoiced_stem}
data.forms = {devoiced_stem}
data.forms = {stem_K .. "es"}
data.forms = {stem_K .. "e"}
data.forms = {stem_K .. "ir"}
data.forms = {stem_K .. "ir"}
data.forms = {stem_K .. "iro"}
data.forms = {stem_K .. "iron"}
table.insert(data.categories, "Old Dutch z-stem nouns")
end
})
decl_data = {
params = {
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
},
}
setmetatable(decl_data, {__call = function(self, args, data)
data.decl_type = "" .. args.type .. ""
data.forms = {args}
data.forms = {args}
data.forms = {args}
data.forms = {args}
data.forms = {args}
data.forms = {args}
data.forms = {args}
data.forms = {args}
end
})
-- The main entry point for automatic declension.
function export.show(frame)
local parent_args = frame:getParent().args
local decl_type = (frame.args or parent_args) or "a"
if not decl_data then
error("Unknown declension '" .. decl_type .. "'")
end
local data = {forms = {}, categories = {}}
data.head = parent_args or nil
local args = require("Module:parameters").process(parent_args, decl_data.params, true)
-- Override for templates
if not args then
setmetatable(args, {__index = function(self, key)
return "{{{" .. key .. "}}}"
end
})
end
-- Generate the forms
if parent_args.irr then
table.insert(data.categories, "Old Dutch irregular nouns")
if decl_data.irregular then
decl_data.irregular(data)
else
decl_data(args, data)
end
else
decl_data(args, data)
end
-- Make the table
if args.nopl=='1' then
return make_table_nopl(data)
else
return make_table(data)
end
end
-- The main entry point for manual declension.
function export.show_manual(frame)
local parent_args = frame:getParent().args
local params = {
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {},
= {}, -- currently ignored
}
local data = {forms = {}, categories = {}}
local args = require("Module:parameters").process(parent_args, params)
local function split(arg)
return arg and mw.text.split(arg, "%s*,%s*") or nil
end
data.forms.nom_sg = split(args)
data.forms.nom_pl = split(args)
data.forms.acc_sg = split(args)
data.forms.acc_pl = split(args)
data.forms.gen_sg = split(args)
data.forms.gen_pl = split(args)
data.forms.dat_sg = split(args)
data.forms.dat_pl = split(args)
data.decl_type = "irregular"
-- Make the table
if args.nopl=='1' then
return make_table_nopl(data)
else
return make_table(data)
end
end
function make_table(data)
local function show_form(form)
if not form then
return "—"
end
local ret = {}
for key, subform in ipairs(form) do
if mw.title.getCurrentTitle().nsText == "Reconstruction" and subform ~= "—" then
subform = "*" .. subform
end
table.insert(ret, m_links.full_link({lang = lang, term = subform}))
end
return table.concat(ret, ", ")
end
local function repl(param)
if param == "decl_type" then
return data.decl_type
else
return show_form(data.forms)
end
end
local wikicode = [=[
<div class="NavFrame" style="width: 42em">
<div class="NavHead" style="">Declension of {{{nom_sg}}} ({{{decl_type}}})</div>
<div class="NavContent">
{| style="background:#f1f5eb; text-align:center; width:100%" cellpadding="0" cellspacing="1" class="inflection-table"
|-
! style="width: 20%; background:#d5dbd8" colspan="1" | '''case'''
! style="width: 40%; background:#e5eede" colspan="1" | singular
! style="width: 40%; background:#e5eede" colspan="1" | plural
|-
! style="background:#ebf0ed" | nominative
| style="background-color:#fdfffc;" | {{{nom_sg}}}
| style="background-color:#fdfffc;" | {{{nom_pl}}}
|-
! style="background:#ebf0ed" | accusative
| style="background-color:#fdfffc;" | {{{acc_sg}}}
| style="background-color:#fdfffc;" | {{{acc_pl}}}
|-
!style="background:#ebf0ed" | genitive
| style="background-color:#fdfffc;" | {{{gen_sg}}}
| style="background-color:#fdfffc;" | {{{gen_pl}}}
|-
! style="background:#ebf0ed" | dative
| style="background-color:#fdfffc;" | {{{dat_sg}}}
| style="background-color:#fdfffc;" | {{{dat_pl}}}
|}</div></div>]=]
return (mw.ustring.gsub(wikicode, "{{{(+)}}}", repl)) .. m_utils.format_categories(data.categories, lang)
end
function make_table_nopl(data)
local function show_form(form)
if not form then
return "—"
end
local ret = {}
for key, subform in ipairs(form) do
if mw.title.getCurrentTitle().nsText == "Reconstruction" and subform ~= "—" then
subform = "*" .. subform
end
table.insert(ret, m_links.full_link({lang = lang, term = subform}))
end
return table.concat(ret, ", ")
end
local function repl(param)
if param == "decl_type" then
return data.decl_type
else
return show_form(data.forms)
end
end
local wikicode = [=[
<div class="NavFrame" style="width: 38em">
<div class="NavHead" style="">Declension of {{{nom_sg}}} ({{{decl_type}}} - no plural)</div>
<div class="NavContent">
{| style="background:#f1f5eb; text-align:center; width:100%" cellpadding="0" cellspacing="1" class="inflection-table"
|-
! style="width: 30%; background:#d5dbd8" colspan="1" | '''case'''
! style="width: 70%; background:#e5eede" colspan="1" | singular
|-
! style="background:#ebf0ed" | nominative
| style="background-color:#fdfffc;" | {{{nom_sg}}}
|-
! style="background:#ebf0ed" | accusative
| style="background-color:#fdfffc;" | {{{acc_sg}}}
|-
!style="background:#ebf0ed" | genitive
| style="background-color:#fdfffc;" | {{{gen_sg}}}
|-
! style="background:#ebf0ed" | dative
| style="background-color:#fdfffc;" | {{{dat_sg}}}
|}</div></div>]=]
return (mw.ustring.gsub(wikicode, "{{{(+)}}}", repl)) .. m_utils.format_categories(data.categories, lang)
end
return export