Modul:sv-subst
Dokumentationen för denna modul kan skapas på Modul:sv-subst/dok /test
local gt = require("Modul:grammar-table")
local export = require("Modul:grammar")
local lang_code_param = "sv"
local part_of_speech_param = "subst"
local plural_param = "plur"
local singular_param = "sing"
local singular_determined_param = "best"
local archaic_param = "åld"
local common_templatename = "sv-subst-n"
local neuter_templatename = "sv-subst-t"
local uncountable_templatename_suffix = "-oräkn"
local name_templatename_suffix = "-namn"
function export.getTempWikitext(frame)
local args = frame:getParent().args
local title = mw.title.getCurrentTitle()
local prefixed_modulename = frame:getTitle()
local prefixed_templatename = frame:getParent():getTitle()
local pagename = args[base_param] or title.text
local should_categorize = title.namespace == 0
local modulename = mw.ustring.gsub(prefixed_modulename, "^[^:]+:", "")
local templatename = mw.ustring.gsub(prefixed_templatename, "^[^:]+:", "")
local use_old_template = true --add conditions
if use_old_template then
return frame:expandTemplate{
title = 'sv-subst-n-er-old',
args = args
}
else
return export.getWikitext(frame)
end
end
function export._getAcceptedParameters()
return {}
end
function export._getForms(pagename, templatename, args, meta, format)
local last_1 = mw.ustring.sub(pagename, -1, -1)
local last_2 = mw.ustring.sub(pagename, -2, -1)
local last_3 = mw.ustring.sub(pagename, -3, -1)
local last_4 = mw.ustring.sub(pagename, -4, -1)
local without_last_1 = mw.ustring.sub(pagename, 1, -2)
local without_last_2 = mw.ustring.sub(pagename, 1, -3)
local without_last_3 = mw.ustring.sub(pagename, 1, -4)
local ends_with_vowel = not not mw.ustring.find(last_1, "[aouåeiyäö]")
local ends_with_vowel_plus = not not mw.ustring.find(last_1, "[aouåeéiyäö]")
local ends_with_consonant = not not mw.ustring.find(last_1, "[bcdfghjklmnpqrstvwxz]")
local ends_with_vowel_m = not not mw.ustring.find(last_2, "[aouåeiyäö]m")
local ends_with_s_sound = not not mw.ustring.find(last_1, "[szx]")
local no_plural = args[plural_param] == "-"
local no_singular = args[singular_param] == "-"
local sing_obest_nom = pagename
local sing_best_nom = "?"
local plur_obest_nom = "?"
local plur_best_nom = "?"
local sing_obest_gen = "?"
local sing_best_gen = "?"
local plur_obest_gen = "?"
local plur_best_gen = "?"
local sing_best_nom_ald = nil
local sing_best_gen_ald = nil
if templatename == "sv-subst-n" then
sing_obest_nom = "?"
elseif templatename == "sv-subst-t" then
sing_obest_nom = "?"
elseif templatename == "sv-subst-n-0" then
plur_obest_nom = args[plural_param] ~= "" and args[plural_param] or pagename
local plur_without_last_1 = mw.ustring.sub(plur_obest_nom, 1, -2)
if last_3 == "are" then
sing_best_nom = pagename .. "n"
plur_best_nom = plur_without_last_1 .. "na"
elseif last_2 == "er" then
sing_best_nom = pagename .. "n"
plur_best_nom = plur_obest_nom .. "na"
elseif ends_with_vowel_m then
--default
elseif last_1 == "m" or ends_with_s_sound then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "en"
elseif ends_with_vowel then
sing_best_nom = pagename .. "n"
plur_best_nom = plur_obest_nom .. "na"
else
--default
end
elseif templatename == "sv-subst-n-ar" then
plur_obest_nom = args[plural_param] ~= "" and args[plural_param] or pagename .. "ar"
if last_2 == "an" then
if args[plural_param] == without_last_2 .. "ningar" then
sing_best_nom = pagename .. ""
plur_obest_nom = without_last_2 .. "ningar"
plur_best_nom = plur_obest_nom .. "na"
elseif args[plural_param] == pagename .. "ar" then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
else
plur_obest_nom = "?"
end
elseif last_4 == "mmer" then
sing_best_nom = pagename .. "n"
plur_obest_nom = without_last_3 .. "rar"
plur_best_nom = plur_obest_nom .. "na"
elseif last_2 == "er" then
sing_best_nom = pagename .. "n"
plur_obest_nom = without_last_2 .. "rar"
plur_best_nom = plur_obest_nom .. "na"
elseif last_2 == "en" then
if args[plural_param] == pagename .. "ar" then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
elseif args[plural_param] == without_last_2 .. "nar" then
sing_best_nom = without_last_2 .. "nen"
plur_obest_nom = without_last_2 .. "nar"
plur_best_nom = plur_obest_nom .. "na"
else
plur_obest_nom = "?"
end
elseif last_2 == "el" then
if args[plural_param] == pagename .. "ar" then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
elseif args[plural_param] == without_last_2 .. "lar" then
sing_best_nom = pagename .. "n"
plur_obest_nom = without_last_2 .. "lar"
plur_best_nom = plur_obest_nom .. "na"
else
plur_obest_nom = "?"
end
elseif last_3 == "dom" then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
elseif ends_with_vowel_m then
if args[plural_param] == pagename .. "ar" then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
elseif args[plural_param] == pagename .. "mar" then
sing_best_nom = pagename .. "men"
plur_obest_nom = pagename .. "mar"
plur_best_nom = plur_obest_nom .. "na"
else
sing_best_nom = "?"
plur_obest_nom = "?"
plur_best_nom = "?"
end
elseif last_1 == "m" then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
elseif last_1 == "e" then
sing_best_nom = pagename .. "n"
plur_obest_nom = without_last_1 .. "ar"
plur_best_nom = plur_obest_nom .. "na"
elseif ends_with_vowel then
sing_best_nom = pagename .. "n"
plur_best_nom = plur_obest_nom .. "na"
else
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
end
elseif templatename == "sv-subst-n-er" then
plur_obest_nom = args[plural_param] ~= "" and args[plural_param] or pagename .. "er"
if last_3 == "ier" then
sing_best_nom = args[singular_determined_param] ~= "" and args[singular_determined_param] or "?"
plur_best_nom = plur_obest_nom .. "na"
elseif last_2 == "er" then
if args[plural_param] == pagename .. "er" then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
elseif args[plural_param] == without_last_2 .. "rer" then
sing_best_nom = pagename .. "n"
plur_obest_nom = without_last_2 .. "rer"
plur_best_nom = plur_obest_nom .. "na"
else
sing_best_nom = "?"
plur_obest_nom = "?"
end
elseif last_2 == "en" then
if args[plural_param] == pagename .. "er" then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
elseif args[plural_param] == without_last_2 .. "ner" then
sing_best_nom = without_last_2 .. "nen"
plur_obest_nom = without_last_2 .. "ner"
plur_best_nom = plur_obest_nom .. "na"
else
sing_best_nom = "?"
plur_obest_nom = "?"
end
elseif last_2 == "el" then
if args[plural_param] == pagename .. "er" then
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
elseif args[plural_param] == without_last_2 .. "ler" then
sing_best_nom = without_last_2 .. "eln"
plur_obest_nom = without_last_2 .. "ler"
plur_best_nom = plur_obest_nom .. "na"
else
sing_best_nom = "?"
plur_obest_nom = "?"
end
elseif ends_with_vowel_plus then
sing_best_nom = pagename .. "n"
plur_best_nom = plur_obest_nom .. "na"
if args[archaic_param] == "" then
sing_best_nom_ald = pagename .. "en"
sing_best_gen_ald = pagename .. "ens"
end
elseif last_2 == "or" then
if args[singular_determined_param] == pagename .. "n" then
sing_best_nom = pagename .. "n"
elseif args[singular_determined_param] == pagename .. "en" then
sing_best_nom = pagename .. "en"
else
sing_best_nom = "?"
end
plur_best_nom = plur_obest_nom .. "na"
else
sing_best_nom = pagename .. "en"
plur_best_nom = plur_obest_nom .. "na"
end
elseif templatename == "sv-subst-n-or" then
plur_obest_nom = args[plural_param] ~= "" and args[plural_param] or plur_obest_nom
local explicit_plural = plur_obest_nom ~= "?"
if last_1 == "a" then
sing_best_nom = pagename .. "n"
plur_obest_nom = without_last_1 .. "or"
plur_best_nom = plur_obest_nom .. "na"
elseif last_2 == "er" then
sing_best_nom = pagename .. "n"
plur_obest_nom = without_last_2 .. "ror"
plur_best_nom = plur_obest_nom .. "na"
elseif last_2 == "en" then
--default
elseif last_2 == "el" then
sing_best_nom = pagename .. "n"
plur_obest_nom = without_last_2 .. "lor"
plur_best_nom = plur_obest_nom .. "na"
elseif ends_with_vowel then
sing_best_nom = pagename .. "n"
plur_obest_nom = pagename .. "r"
plur_best_nom = plur_obest_nom .. "na"
else
sing_best_nom = pagename .. "en"
plur_obest_nom = pagename .. "or"
plur_best_nom = plur_obest_nom .. "na"
end
elseif templatename == "sv-subst-t-0" then
plur_obest_nom = args[plural_param] ~= "" and args[plural_param] or pagename
local plur_without_last_2 = mw.ustring.sub(plur_obest_nom, 1, -3)
local plur_without_last_3 = mw.ustring.sub(plur_obest_nom, 1, -4)
if last_1 == "e" then
sing_best_nom = pagename .. "t"
plur_best_nom = sing_obest_nom .. "n"
elseif ends_with_vowel then
-- default
elseif last_1 == "m" then
if args[singular_determined_param] == pagename .. "et" then
sing_best_nom = pagename .. "et"
plur_best_nom = plur_obest_nom .. "en"
elseif args[singular_determined_param] == pagename .. "met" then
sing_best_nom = pagename .. "met"
plur_best_nom = plur_obest_nom .. "men"
else
sing_best_nom = "?"
plur_best_nom = "?"
end
elseif last_4 == "mmer" then
sing_best_nom = plur_without_last_3 .. "mret"
plur_best_nom = plur_without_last_3 .. "mren"
elseif last_4 == "mmel" then
sing_best_nom = plur_without_last_3 .. "mlet"
plur_best_nom = plur_without_last_3 .. "mlen"
elseif last_4 == "mmen" then
sing_best_nom = "?"
plur_best_nom = "?"
elseif last_4 == "ller" then
sing_best_nom = plur_without_last_2 .. "ret"
plur_best_nom = plur_without_last_2 .. "ren"
elseif last_2 == "er" then
if args[singular_determined_param] == plur_without_last_2 .. "ret" then
sing_best_nom = pagename .. "ret"
plur_best_nom = plur_obest_nom .. "ren"
elseif args[singular_determined_param] == plur_without_last_2 .. "eret" then
sing_best_nom = pagename .. "ret"
plur_best_nom = plur_obest_nom .. "ren"
else
sing_best_nom = "?"
plur_best_nom = "?"
end
sing_best_nom = pagename .. "et"
plur_best_nom = plur_obest_nom .. "en"
else
end
end
local build_plurals_on_plural_param_rather_than_singular_forms_when_singular_forms_are_missing = args[singular_param] == "-" and args[plural_param] and args[plural_param] ~= ""
if build_plurals_on_plural_param_rather_than_singular_forms_when_singular_forms_are_missing then
plur_obest_nom = args[plural_param]
plur_best_nom = plur_obest_nom .. "na"
end
sing_obest_nom = args[1] or sing_obest_nom
sing_best_nom = args[2] or sing_best_nom
plur_obest_nom = args[3] or plur_obest_nom
plur_best_nom = args[4] or plur_best_nom
local function getGenitive(nominative)
if not nominative then
return
else
local nom_last_1 = mw.ustring.sub(nominative, -1, -1)
local letter_except_sxz_pattern = "[abcdeéfghijklmnopqrtuvwyåäö]"
local ends_with_letter_but_not_szx = not not mw.ustring.find(nom_last_1, letter_except_sxz_pattern)
local gen_ending = ends_with_letter_but_not_szx and "s" or ""
local genitive = nominative .. gen_ending
return genitive
end
end
local sing_obest_gen = getGenitive(sing_obest_nom)
local sing_best_gen = getGenitive(sing_best_nom)
local plur_obest_gen = getGenitive(plur_obest_nom)
local plur_best_gen = getGenitive(plur_best_nom)
local forms = {}
forms.sing_obest_nom = sing_obest_nom
forms.sing_best_nom = sing_best_nom
forms.plur_obest_nom = plur_obest_nom
forms.plur_best_nom = plur_best_nom
forms.sing_obest_gen = args[5] or sing_obest_gen
forms.sing_best_gen = args[6] or sing_best_gen
forms.plur_obest_gen = args[7] or plur_obest_gen
forms.plur_best_gen = args[8] or plur_best_gen
forms.sing_best_nom_ald = sing_best_nom_ald
forms.sing_best_gen_ald = sing_best_gen_ald
if format == "wikitable" or format == "export" then
local word_is_uncountable = meta.uncountable
if word_is_uncountable then
forms.sing_obest_nom = nil
forms.sing_best_nom = nil
forms.plur_obest_nom = nil
forms.plur_best_nom = nil
forms.sing_obest_gen = nil
forms.sing_best_gen = nil
forms.plur_obest_gen = nil
forms.plur_best_gen = nil
forms.obest_nom = args[1] or sing_obest_nom
forms.best_nom = args[2] or sing_best_nom
forms.obest_gen = args[3] or sing_obest_gen
forms.best_gen = args[4] or sing_best_gen
end
if no_singular then
forms.sing_obest_nom = "-"
forms.sing_best_nom = "-"
forms.sing_obest_gen = "-"
forms.sing_best_gen = "-"
if not args[plural_param] then
forms.plur_obest_nom = "?"
forms.plur_best_nom = "?"
forms.plur_obest_gen = "?"
forms.plur_best_gen = "?"
end
end
if no_plural then
forms.plur_obest_nom = "-"
forms.plur_best_nom = "-"
forms.plur_obest_gen = "-"
forms.plur_best_gen = "-"
end
end
return forms
end
function export._getMeta(pagename, templatename, args)
local gender = "?"
local uncountable = mw.ustring.sub(templatename, -mw.ustring.len(uncountable_templatename_suffix), -1) == uncountable_templatename_suffix
local is_common = mw.ustring.sub(templatename, 1, mw.ustring.len(common_templatename)) == common_templatename
local is_neuter = mw.ustring.sub(templatename, 1, mw.ustring.len(neuter_templatename)) == neuter_templatename
if is_common then
gender = "c"
elseif is_neuter then
gender = "n"
end
local meta = {}
meta.numbered_cells = uncountable and 4 or 8
meta.named_cells = {}
meta.gender = gender
meta.uncountable = uncountable
return meta
end
function export._getCategories(forms, meta)
local str = ""
return str
end
return export