local m_utilities = require("Module:utilities")
local m_links = require("Module:links")
local export = {}
local lang = require("Module:languages").getByCode("sv")
local vowel = ""
local consonant = ""
local inflections = {}
local function postprocess(args, data)
if args then
for key, form in pairs(data.forms) do
if (key:find("actv$")) then
data.forms = nil
end
end
-- default handling of participles for passive-only verbs
if not args then
for key, form in pairs(data.forms) do
if key == "prespart" then
for i, subform in ipairs(form) do
form = form .. "s"
end
end
end
end
if not args then
data.forms = nil
end
else
-- only deponent verbs have passive imperative forms
data.forms = nil
data.forms = nil
end
if args then
for key, form in pairs(data.forms) do
if (key:find("pasv$")) then
data.forms = nil
end
end
end
if args then
data.forms = nil
end
if args then
data.forms = nil
end
-- add particle to participles; it is added separately for the table later
if args or args then
data.particle = args
table.insert(data.categories, "Swedish phrasal verbs")
local part = args or args or ""
for key, form in pairs(data.forms) do
if key == "prespart" or key == "pastpart" then
for i, subform in ipairs(form) do
form = part .. form
end
end
end
end
if args and data.definitions and data.definitions:find("%)$") then
data.definitions = mw.ustring.sub(data.definitions, 1, mw.ustring.len(data.definitions) - 1) .. ", " .. args .. ")"
end
end
local function convert_to_accel(form)
-- no accel for now
return nil
end
-- Make the table
local function make_table(data)
local function show_form(form, accel, show_particle)
if not form then
return "—"
elseif type(form) ~= "table" then
error("a non-table value was given in the list of inflected forms.")
end
local ret = {}
local part = ""
if show_particle and data.particle then
part = " " .. m_links.full_link({lang = lang, term = data.particle})
end
for key, subform in ipairs(form) do
table.insert(ret, m_links.full_link({lang = lang, term = subform, accel = accel and { = accel } or nil}) .. part)
end
return table.concat(ret, ", ")
end
local function repl(param)
if param == "head" then
return data.particle and (data.head .. " " .. data.particle) or data.head
elseif param == "definitions" then
return data.definitions
else
return show_form(data.forms, convert_to_accel(param), param ~= "prespart" and param ~= "pastpart")
end
end
local wikicode = [=[
<div class="NavFrame" style="max-width:54em;" data-toggle-category="inflection">
<div class="NavHead" >Conjugation of ]=] .. mw.getCurrentFrame():expandTemplate{title = "l-self", args = {"sv", data.head}} .. [=[ {{{definitions}}}</div>
<div class="NavContent" style="overflow:auto">
{| class="inflection-table" style="width: 100%; line-height: 125%; background-color: #F9F9F9; text-align: center; border: 1px solid #CCCCFF;" cellpadding="3" cellspacing="1"
|-
!
! colspan=2 style="width: 50%; background-color:#EFEFEF;" | Active
! colspan=2 style="width: 50%; background-color:#EFEFEF;" | Passive
|-
! style="background-color:#EFEFEF;" | Infinitive
| colspan=2 | {{{infactv}}}
| colspan=2 | {{{infpasv}}}
|-
! style="background-color:#EFEFEF;" | Supine
| colspan=2 | {{{supactv}}}
| colspan=2 | {{{suppasv}}}
|-
! style="background-color:#EFEFEF;" | Imperative
| colspan=2 | {{{impactv}}}
| colspan=2 | {{{imppasv}}}
|-
! style="background-color:#EFEFEF;" | ''Imper. plural''<sup>1</sup>
| colspan=2 | {{{imppactv}}}
| colspan=2 | {{{impppasv}}}
|-
!
! style="width: 25%; background-color:#EFEFEF;" | Present
! style="width: 25%; background-color:#EFEFEF;" | Past
! style="width: 25%; background-color:#EFEFEF;" | Present
! style="width: 25%; background-color:#EFEFEF;" | Past
|-
! style="background-color:#EFEFEF;" | Indicative
| {{{indpresactv}}}
| {{{indpastactv}}}
| {{{indprespasv}}}
| {{{indpastpasv}}}
|-
! style="background-color:#EFEFEF;" | ''Ind. plural''<sup>1</sup>
| {{{indppresactv}}}
| {{{indppastactv}}}
| {{{indpprespasv}}}
| {{{indppastpasv}}}
|-
! style="background-color:#EFEFEF;" | ''Subjunctive''<sup>2</sup>
| {{{subjpresactv}}}
| {{{subjpastactv}}}
| {{{subjprespasv}}}
| {{{subjpastpasv}}}
|-
!
! colspan=4 style="width: 100%; background-color:#EFEFEF;" | Participles
|-
! style="background-color:#EFEFEF;"| Present participle
| colspan=4 | {{{prespart}}}
|-
! style="background-color:#EFEFEF;" | Past participle
| colspan=4 | {{{pastpart}}}
|-
| colspan=5 style="text-align: left;" | <small><sup>1</sup> Archaic. <sup>2</sup> Dated. See ].</small>
|}</div></div>]=]
return mw.ustring.gsub(wikicode, "{{{(+)}}}", repl)
end
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local infl_type = frame.args or error("Inflection type has not been specified. Please pass parameter 1 to the module invocation")
local args = frame:getParent().args
if not inflections then
error("Unknown inflection type '" .. infl_type .. "'")
end
local data = {head = args or mw.title.getCurrentTitle().text, definitions = "", forms = {}, categories = {}}
-- Generate the forms
inflections(args, data)
-- Postprocess
postprocess(args, data)
return make_table(data) .. m_utilities.format_categories(data.categories, lang)
end
local function split_multi(forms)
if not forms or forms == "" or forms == "-" then
return nil
end
return mw.text.split(forms, ",")
end
--[=[
Inflection functions
]=]--
local function make_passive(forms)
local pasv = {}
for i, subform in ipairs(forms) do
table.insert(pasv, subform .. "s")
end
return pasv
end
local weak_present_endings = {
= "",
= "r",
= "r",
= "ver",
= "mer",
= "ner"
}
local weak_past_endings = {
= "",
= "",
= "t",
= "t",
= "dd"
}
local weak_sup_endings = {
= "",
= "tt"
}
local weak_part_endings = {
= "ende"
}
local weak_prespasv_endings1 = {
= "ns"
}
local weak_prespasv_endings2 = {
= "ves",
= "mes",
= "nes"
}
local weak_subj_endings = {
= "me",
= "ne"
}
local weak_impp_endings = {
= "n",
= "ven",
= "men",
= "nen"
}
local function make_weak_present_form(stem, endc)
local result = {stem .. (weak_present_endings or "er")}
if endc == "dj" then
table.insert(result, stem .. "jer")
end
return result
end
local function make_weak_prespasv_form(stem, endc)
if endc == "s" then
return {stem .. "es"}
end
local result = {stem .. (weak_prespasv_endings1 or "s")}
if endc ~= "vw" and endc ~= "a" then
table.insert(result, stem .. (weak_prespasv_endings2 or "es"))
end
if endc == "dj" then
table.insert(result, stem .. "jes")
end
return result
end
inflections = function(args, data)
data.definitions = "(weak)"
table.insert(data.categories, "Swedish weak verbs")
local head = data.head
-- remove passive final -s to make forms correct
if head:find("s$") and args then
head = mw.ustring.sub(head, 1, mw.ustring.len(head) - 1)
end
local basic = args or head
local past = args or basic
local full = args or head
local endc = args or (args and "" or "a")
local bare = basic
local vowelstem = mw.ustring.find(basic, vowel .. "$")
if endc == "a" then
bare = mw.ustring.sub(bare, 1, mw.ustring.len(bare) - 1)
vowelstem = false
end
data.forms = {head}
data.forms = make_weak_present_form(basic, endc)
data.forms = args and split_multi(args) or {past .. (weak_past_endings or "d") .. "e"}
data.forms = args and split_multi(args) or {past .. (weak_sup_endings or "t")}
data.forms = args and split_multi(args) or {basic .. ((endc == "nn") and "n" or "")}
data.forms = args and split_multi(args) or {bare .. (weak_impp_endings or "en")}
data.forms = args and split_multi(args) or {full .. (not args and weak_part_endings or "nde")}
data.forms = args and split_multi(args) or {past .. (weak_past_endings or "d")}
data.forms = data.forms
data.forms = data.forms
data.forms = args and split_multi(args) or (vowelstem and data.forms or {bare .. (weak_subj_endings or "e")})
data.forms = data.forms
data.forms = make_passive(data.forms)
data.forms = make_weak_prespasv_form(basic, endc)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
data.forms = data.forms
data.forms = data.forms
data.forms = make_passive(data.forms)
data.forms = data.forms
end
local strong_pres_endings = {
= "",
= "r",
= "ver",
= "mer",
= "ner"
}
local strong_sup_endings = {
= "vit",
= "mit",
= "nit"
}
local strong_pastpart_endings = {
= "ven",
= "men",
= "nen"
}
local strong_subj_endings = {
= "",
= "ve",
= "me",
= "ne"
}
local strong_impp_endings = {
= "n",
= "ven",
= "men",
= "nen"
}
local function make_strong_ppl_stem(class, endc, past, sup)
local base
if class == "3" or class == "4" then
base = sup
else
base = past
end
if endc == "mm" then
base = base .. "m"
elseif endc == "nn" then
base = base .. "n"
end
return base
end
local function make_strong_prespasv_form(stem, endc)
if endc == "s" then
return {stem .. "es"}
end
local result = {stem .. (weak_prespasv_endings1 or "s")}
if endc ~= "vw" and endc ~= "a" then
table.insert(result, stem .. (weak_prespasv_endings2 or "es"))
end
if endc == "dj" then
table.insert(result, stem .. "jes")
end
return result
end
local function get_final_vowel(stem)
return mw.ustring.match(stem, ".*(" .. vowel .. ")")
end
local function try_detect_strong_class(pres, past, sup, endc)
local presv = get_final_vowel(pres)
local pastv = get_final_vowel(past)
local supv = get_final_vowel(sup)
if supv == "i" or supv == "ä" or supv == "e" then
if supv == "i" and pastv == "e" and presv == "i" then
return "1"
elseif (pastv == "a" or pastv == "å") and (presv == "e" or presv == "i" or presv == "ä") then
return "5"
end
elseif supv == "u" then
if pastv == "ö" and (presv == "u" or presv == "y") then
return "2"
elseif pastv == "a" then
if presv == "i" then
return "3"
elseif presv == "e" or presv == "ä" then
if pres:find(consonant .. consonant .. "$") then
return "3"
else
return "4"
end
end
end
elseif supv == "a" or supv == "å" then
if supv == "a" and pastv == "o" and presv == "a" then
return "6"
elseif (pastv == "ö" or pastv == "ä") and (presv == "å" or presv == "a") then
return "7"
end
end
return nil
end
inflections = function(args, data)
table.insert(data.categories, "Swedish strong verbs")
local head = data.head
-- remove passive final -s to make forms correct
if head:find("s$") and args then
head = mw.ustring.sub(head, 1, mw.ustring.len(head) - 1)
end
local endc = args or ""
local pres = args or error("At least 3 arguments required for strong verb inflections (missing present stem)")
local past = args or error("At least 3 arguments required for strong verb inflections (missing past stem)")
local sup = args
-- it's fine to not specify the supine stem if supine and pp forms are manually given
if not sup and (not args or not (args or args)) then
error("At least 3 arguments required for strong verb inflections (missing supine stem; alternatively specify supine and past participle forms manually)")
elseif not sup then
sup = mw.ustring.sub(args, 1, mw.ustring.len(args) - 1)
end
local class = args or try_detect_strong_class(pres, past, sup, endc)
local full = args or (head .. (endc == "vw" and "e" or ""))
local ppl = args or make_strong_ppl_stem(class, endc, past, sup)
if class then
table.insert(data.categories, "Swedish class " .. class .. " strong verbs")
data.definitions = "(class " .. class .. " strong)"
else
data.definitions = "(strong)"
end
if class == "5" then -- for class 5, replace final -a- with -å- in plural/subjunctive stem
ppl = mw.ustring.gsub(ppl, "(.*)a(.*)", "%1å%2")
end
if endc == "fv" and ppl:find("f$") then
ppl = ppl .. "v"
end
data.forms = {head}
data.forms = {pres .. (strong_pres_endings or "er")}
data.forms = {past}
data.forms = args and split_multi(args) or {sup .. (strong_sup_endings or "it")}
data.forms = args and split_multi(args) or {pres}
data.forms = args and split_multi(args) or {pres .. (strong_impp_endings or "en")}
data.forms = args and split_multi(args) or {full .. "nde"}
data.forms = args and split_multi(args) or {sup .. (strong_pastpart_endings or "en")}
data.forms = args and split_multi(args) or data.forms
data.forms = {ppl .. "o"}
data.forms = args and split_multi(args) or {pres .. (strong_subj_endings or "e")}
data.forms = args and split_multi(args) or {ppl .. "e"}
data.forms = make_passive(data.forms)
data.forms = make_strong_prespasv_form(pres, endc)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
data.forms = make_passive(data.forms)
end
inflections = function(args, data)
table.insert(data.categories, "Swedish irregular verbs")
data.definitions = "(irregular)"
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
data.forms = split_multi(args)
end
return export