Module:User:KarikaSlayer/sv-conj

local m_links = require("Module:links") local m_utilities = require("Module:utilities")

local lang = require("Module:languages").getByCode("sv")

local export = {}

local forms = {}

local forms_to_use = {"top", "inf", "pres", "past", "sup", "imp", "pres_part", "past_part", "bottom"}

function forms.top(args) local ret = [=[[=[ Conjugation of   {| class="inflection-table" style="width: 100%; line-height: 125%; background-color: #F9F9F9; text-align: center; border: 1px solid #CCCCFF;" cellpadding="3" cellspacing="1" ! style="width: ]=] .. (args["nop"] or args["noa"]) and "100%" or "50%"	ret = ret .. '"; background-color:#EFEFEF;" | ' .. (args["noa"] and 'passive' or 'active') .. '\n'	if not data.no_passive and not data.no_active then ret = ret .. '! style="width: 50%; background-color:#EFEFEF;" | passive\n' end end

function forms.inf(args) local function get_inf(stem, class, irr, pass) return irr and irregulars[mw.title.getCurrentTitle.text]["inf"] or (mw.title.getCurrentTitle.text .. (pass and "s" or "")) end local ret = '|-\n! style="background-color:#EFEFEF;" | infinitive\n' ret = ret .. '| ' .. show_form(get_inf(args[1], args.class, args.irr)) .. '\n' if not data.no_passive then ret = ret .. '| ' .. show_form(get_inf(args[1], args.class, args.irr, true)) .. '\n' end return ret end

function forms.inf(args) local part = args.particle or "" local function get_inf(args, pass) return {args.irr and irregulars[mw.title.getCurrentTitle.text]["inf"] or (mw.title.getCurrentTitle.text .. (pass and "s" or ""))} end local ret = '|-\n! style="background-color:#EFEFEF;" | infinitive\n' ret = ret .. '| ' .. show_form(get_inf(args)) .. (args.particle and show_form(args.particle) or "") .. '\n' if not data.no_passive then ret = ret .. '| ' .. show_form(get_inf(args, true)) .. '\n' end return ret end

function forms.pres(args) local part = args.particle or "" local function get_inf(args, pass) if class == "weak" then if not args[1] then return {mw.title.getCurrentTitle.text .. "r"} elseif mw.ustring.sub(args[1], -1, -1) == "r" then return {args[1]} elseif mw.ustring.sub(args[1], -2, -1) == "dj" then return {mw.ustring.sub(args[1], 1, -1) .. "er", args[1] .. "er"} end end return irr and irregulars[mw.title.getCurrentTitle.text]["inf"] or (mw.title.getCurrentTitle.text .. (pass and "s" or "")) end local ret = '|-\n! style="background-color:#EFEFEF;" | infinitive\n' ret = ret .. '| ' .. show_form(get_inf(args[1], args.class, args.irr)) .. '\n' if not data.no_passive then ret = ret .. '| ' .. show_form(get_inf(args[1], args.class, args.irr, true)) .. '\n' end return ret end

local function get_past_stem(stem)

end

-- Shows forms with links, or a dash if empty local function show_form(subforms, form_name) if not subforms then return "&mdash;" elseif type(subforms) ~= "table" then error("a non-table value was given in the list of inflected forms.") elseif #subforms == 0 then return "&mdash;" end local ret = {} -- Go over each subform and insert links for key, subform in ipairs(subforms) do		table.insert(ret, m_links.full_link({lang = lang, term = subform})) end return table.concat(ret, ", ") end

-- Shows the table with the given forms local function make_table(data) local ret = {[=[ Conjugation of ]=]} table.insert(ret, m_links.full_link({lang = lang, alt = data.forms.act_inf[1]}, "term") .. " (" .. data.conj .. ") \n") table.insert(ret, [=[ {| class="inflection-table" style="width: 100%; line-height: 125%; background-color: #F9F9F9; text-align: center; border: 1px solid #CCCCFF;" cellpadding="3" cellspacing="1" ! style="width: ]=])	table.insert(ret, data.no_passive and '100%' or '50%')	table.insert(ret, '; background-color:#EFEFEF;" | active\n') if not data.no_passive then table.insert(ret, '! style="width: 50%; background-color:#EFEFEF;" | passive\n') end table.insert(ret, '|-\n! style="background-color:#EFEFEF;" | infinitive\n') table.insert(ret, '| ' .. show_form(data.forms.act_inf) .. '\n') if not data.no_passive then table.insert(ret, '| ' .. show_form(data.forms.pas_inf) .. '\n') end table.insert(ret, '|-\n! style="background-color:#EFEFEF;" | present tense\n') table.insert(ret, '| ' .. show_form(data.forms.act_pres) .. '\n') if not data.no_passive then table.insert(ret, '| ' .. show_form(data.forms.pas_pres) .. '\n') end table.insert(ret, '|-\n! style="background-color:#EFEFEF;" | past tense\n') table.insert(ret, '| ' .. show_form(data.forms.act_past) .. '\n') if not data.no_passive then table.insert(ret, '| ' .. show_form(data.forms.pas_past) .. '\n') end table.insert(ret, '|-\n! style="background-color:#EFEFEF;" | supine\n') table.insert(ret, '| ' .. show_form(data.forms.act_sup) .. '\n') if not data.no_passive then table.insert(ret, '| ' .. show_form(data.forms.pas_sup) .. '\n') end table.insert(ret, '|-\n! style="background-color:#EFEFEF;" | imperative\n') table.insert(ret, '| ' .. show_form(data.forms.act_imp) .. '\n') if not data.no_passive then table.insert(ret, '| ' .. show_form(data.forms.pas_imp) .. '\n') end table.insert(ret, '|-\n! style="background-color:#EFEFEF;"| present participle\n') table.insert(ret, data.no_passive and '| colspan=2 ' or '') table.insert(ret, '| ' .. show_form(data.forms.pres_part) .. '\n') table.insert(ret, '|-\n! style="background-color:#EFEFEF;"| past participle\n') table.insert(ret, data.no_passive and '| colspan=2 ' or '') table.insert(ret, '| ' .. show_form(data.forms.past_part) .. '\n') table.insert(ret, '|} ')

return table.concat(ret) end

-- Main entry point function export.show(frame) local args = mw.clone(frame:getParent.args) -- Create the forms local data = {forms = {}, categories = {}} if mw.title.getCurrentTitle.nsText ~= "" then return end local title = mw.title.getCurrentTitle.text if frame.args["conj"] == "weak" then if not args[1] then -- -ar verb end end local last3 = mw.ustring.sub(word, -3, -1) local last2 = mw.ustring.sub(word, -2, -1) if m_infl[word] then args[1] = m_infl[word].get_stem(word) m_infl[word](args, data) elseif m_infl[last3] then args[1] = m_infl[last3].get_stem(word) m_infl[last3](args, data) elseif m_infl[last2] then args[1] = m_infl[last2].get_stem(word) -- Distinguishing first and second conjugation -ar verbs if mw.ustring.match(word, "[àèéìòó][bcdfgjłmnprstvxz][bcdfgjłmnprstvxz]?ar$") or args.conj == "2nd" then m_infl["ar-2nd"](args, data) else m_infl[last2](args, data) end else error("Inflection for " .. word .. " not found.") end return make_table(data) .. m_utilities.format_categories(data.categories, lang) end

return export