Module:letton-déclinaisons

Bonjour, vous êtes venu ici pour chercher la signification du mot Module:letton-déclinaisons. Dans DICTIOUS, vous trouverez non seulement toutes les significations du dictionnaire pour le mot Module:letton-déclinaisons, mais vous apprendrez également son étymologie, ses caractéristiques et comment dire Module:letton-déclinaisons au singulier et au pluriel. Tout ce que vous devez savoir sur le mot Module:letton-déclinaisons est ici. La définition du mot Module:letton-déclinaisons vous aidera à être plus précis et correct lorsque vous parlerez ou écrirez vos textes. Connaître la définition deModule:letton-déclinaisons, ainsi que celles d'autres mots, enrichit votre vocabulaire et vous fournit des ressources linguistiques plus nombreuses et de meilleure qualité.

 Documentation

Ce module définit une fonction permettant d’afficher la table des flexions des noms communs en letton.

Fonctions pour modèles

generateNounTable

Retourne le wikicode pour le modèle Modèle:lv-nom. Le cas particulier de suns au génitif singulier, qui fait suņa au lieu de suns, est codé en dur dans la fonction.

Paramètres de frame
  • 1 (chaine, optionnel) : Le nominatif singulier du nom à afficher. Si non spécifié, le titre de la page est utilisé.
  • décl (entier, obligatoire) : Le numéro de la déclinaison.
  • vs-complet (boolean, optionnel) : Si true, le vocatif singulier sera affiché dans sa forme complète, sinon il sera affiché sans (radical seul).
  • palatale (chaine, optionnel) : La consonne palatale à utiliser pour les mutations au génitif et pluriel (dépend de la déclinaison).
  • remplacer (booléen, optionnel) : Si true et palatale est renseigné, la consonne palatale remplacera la dernière lettre du radical au lieu d’être inserée après celle-ci.
  • mode (chaine, optionnel) : La valeur sing affichera uniquement le singulier, tandis que la valeur plur affichera uniquement le pluriel.
  • ns (chaine, optionnel) : Permet de spécifier le nominatif singulier.
  • np (chaine, optionnel) : Permet de spécifier le nominatif pluriel.
  • Et ainsi de suite pour chaque cas. Le nom de chacun de ces paramètres est composé de la première lettre du cas puis la première lettre du nombre. Par exemple, ls pour le locatif singulier.
Type de retour
chaine

Liste des sous-pages

  • /data : définition des déclinaisons

local m_params = require("Module:paramètres")
local m_bases = require("Module:bases")
local m_table = require("Module:table")
local bit32 = require("bit32")

local DECLENSIONS = mw.loadData("Module:letton-déclinaisons/data")
local SINGULAR = 1
local PLURAL = 2

local NO_DECL_ERROR = "no_declension_for_key"
local USELESS_PARAM_ERROR = "useless_param"

local p = {}

--- Mutate the given root.
--- @param root string The root to modify.
--- @param modify boolean If true, the `modifierLetter` will replace the letter before the suffix, otherwise it will be inserted after it.
--- @param palatal string|nil The palatal letter that will modify the one preceding the suffix. Leave `nil` to keep it.
--- @return string The mutated root.
local function mutate(root, modify, palatal)
  if modify then
    return mw.ustring.sub(root, 1, -2) .. palatal
  end
  return root .. palatal
end

local DECl_TITLES = {
  "Première", "Deuxième", "Troisième", "Quatrième", "Cinquième", "Sixième"
}
local CASE_NAMES = {
  n = "Nominatif",
  a = "Accusatif",
  g = "Génitif",
  d = "Datif",
  i = "Instrumental",
  l = "Locatif",
  v = "Vocatif",
}
local DISPLAY_ORDER = { "n", "a", "g", "d", "i", "l", "v" }

--- Generate the wikicode for the given noun forms.
--- @param forms table The noun forms.
--- @param declension number The declension number (1-6).
--- @param numberMode number A number indicating whether to show the singular only, plural only, or both.
--- @return string The generated wikicode.
local function generateNounTable(forms, declension, numberMode)
  local showSing = bit32.band(numberMode, SINGULAR) ~= 0
  local showPlur = bit32.band(numberMode, PLURAL) ~= 0
  if not showSing and not showPlur then
    error("Invalid 'numberMode' value: " .. tostring(numberMode))
  end

  local code = mw.ustring.format('{| class="wikitable flextable"\n|+ %s déclinaison\n|-\n|', DECl_TITLES)
  if showSing then
    code = code .. "\n| Singulier"
  end
  if showPlur then
    code = code .. "\n| Pluriel"
  end
  for _, case in ipairs(DISPLAY_ORDER) do
    local flexions = forms
    code = code .. mw.ustring.format("\n|-\n! %s", CASE_NAMES)
    if showSing then
      code = code .. "\n|" .. m_bases.lien_modele(flexions, "lv", nil, nil, true)
    end
    if showPlur then
      code = code .. "\n|" .. m_bases.lien_modele(flexions, "lv", nil, nil, true)
    end
  end
  code = code .. "\n|}"
  return code
end

--- Generate all forms for the given noun.
--- @param word string The nominative singular form of the noun.
--- @param declension number The declension number (1-6).
--- @param modify boolean If true, the `modifierLetter` will replace the letter before the suffix, otherwise it will be inserted after it.
--- @param palatal string|nil The palatal letter that will modify the one preceding the suffix. Leave `nil` to keep it.
--- @param vocativeKeepsEnding boolean Whether to keep the last letter of the vocative for the 1st, 5th, and 6th declensions.
--- @param specifiedForms table A table specifying values to use for different cases instead of default ones.
--- @return table A table containing all forms of the word.
local function generateNounForms(word, declension, modify, palatal, vocativeKeepsEnding, specifiedForms)
  local key = tostring(declension)
  if declension == 2 or declension == 3 then
    key = key .. "-" .. mw.ustring.sub(word, -2)
  else
    key = key .. "-" .. mw.ustring.sub(word, -1)
  end
  local decl = DECLENSIONS
  if not decl then
    error({ message = NO_DECL_ERROR, key = key })
  end
  if modify and not palatal then
    error({ message = USELESS_PARAM_ERROR, param = "remplacer" })
  end
  if vocativeKeepsEnding and not decl.vsMayDropEnding then
    error({ message = USELESS_PARAM_ERROR, param = "vs-complet" })
  end

  local root = mw.ustring.sub(word, 1, -mw.ustring.len(decl.endings.n) - 1)
  local forms = {}
  local anyPalatal = false
  for case, endings in pairs(decl.endings) do
    local sing = root .. endings
    local plur = root .. endings

    if palatal and endings.palatal and m_table.length(endings.palatal) ~= 0 then
      local mutatedRoot = mutate(root, modify, palatal)
      if m_table.contains(endings.palatal, 1) then
        sing = mutatedRoot .. endings
        anyPalatal = true
      end
      if m_table.contains(endings.palatal, 2) then
        plur = mutatedRoot .. endings
        anyPalatal = true
      end
    end

    if case == "v" and not vocativeKeepsEnding and decl.vsMayDropEnding then
      sing = root
    end

    -- Special case for "suns" for the genitive singular
    if word == "suns" and declension == 2 and case == "g" then
      sing = "suņa"
    end

    forms = { specifiedForms or sing, specifiedForms or plur }
  end

  if palatal and not anyPalatal then
    error({ message = USELESS_PARAM_ERROR, param = "palatale" })
  end

  return forms
end

local function errorMessage(message)
  return mw.ustring.format("<span style='color: red'>%s</span>]", message)
end

function p.generateNounTable(frame)
  local spec = {
     = {},
     = { required = true, type = m_params.INT, checker = function(decl)
      return decl >= 1 and decl <= 6
    end },
     = { type = m_params.BOOLEAN, default = false },
     = {},
     = { type = m_params.BOOLEAN, default = false },
     = { enum = { "sing", "plur" }, default = nil },
  }
  for case, _ in pairs(CASE_NAMES) do
    spec = {}
    spec = {}
  end
  local args, validArgs = m_params.process(frame:getParent().args, spec, true) -- Silent errors

  if not validArgs then
    return errorMessage(mw.ustring.format(
        "Paramètre « %s » incorrect : %s",
        tostring(args),
        args
    ))
  end

  local pageTitle = mw.title.getCurrentTitle().text
  local word = args or pageTitle
  local declension = args
  local vocativeKeepsEnding = args
  local palatal = args
  local modify = args
  local numberMode
  if args == "sing" then
    numberMode = SINGULAR
  elseif args == "plur" then
    numberMode = PLURAL
  else
    numberMode = bit32.bor(SINGULAR, PLURAL)
  end
  local specifiedForms = {}
  for case, _ in pairs(CASE_NAMES) do
    local keySing = case .. "s"
    specifiedForms = args
    local keyPlur = case .. "p"
    specifiedForms = args
  end

  local success, data = pcall(function()
    local forms = generateNounForms(word, declension, modify, palatal, vocativeKeepsEnding, specifiedForms)
    local text = generateNounTable(forms, declension, numberMode)
    -- If args is specified, we are most likely on a flexion page, so no categorization
    -- But if the current page corresponds to the nominative plural and the mode is plural only, do categorize
    if not args or (pageTitle == forms.n and numberMode == PLURAL) then
      local catName = mw.ustring.format("Noms communs de la %s déclinaison en letton", mw.ustring.lower(DECl_TITLES))
      text = text .. m_bases.fait_categorie_contenu(catName)
    end
    return text
  end)
  if not success then
    if data.message == NO_DECL_ERROR then
      return errorMessage("Déclinaison incorrecte : " .. tostring(declension))
    elseif data.message == USELESS_PARAM_ERROR then
      return errorMessage(mw.ustring.format("Paramètre « %s » superflu, veuillez le retirer.", data.param))
    end
    return errorMessage("Une erreur est survenue : " .. tostring(data))
  end
  return data
end

return p