Module:racine-étymologie

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

La documentation pour ce module peut être créée à Module:racine-étymologie/Documentation

local m_bases = require("Module:bases")
local m_params = require("Module:paramètres")
local m_langs = require("Module:langues")

local p = {}

local ROOT = 0
local PREFIX = 1
local SUFFIX = 2
local FINAL = 3
local VOYELLE_APPUI = 4

--[[
Get the type of a word element.
@param element string A word element.
@return string The element’s type, either ROOT, PREFIX, SUFFIX or FINAL.]]
local function getType(element)
  if mw.ustring.match(element, "^.+/$") then
    return ROOT
  elseif mw.ustring.match(element, "^+-$") then
    return PREFIX
  elseif mw.ustring.match(element, "^-+-$") then
    if element == "-o-" then
      return VOYELLE_APPUI
    else
      return SUFFIX
    end
  elseif mw.ustring.match(element, "^-+$") then
    return FINAL
  else
    error("Élément de type inconnu : " .. element)
  end
end

--[[
Create a link to the given root.
@param root string The word to link to.
@param languageName string The language name.
@return string The link.]]
local function formatRoot(root, languageName)
  local roots = mw.loadData(mw.ustring.format("Module:racine-étymologie/data/%s/roots", languageName))
  local formatedRoot = mw.ustring.format("'']''", languageName, root, root)
  if roots ~= nil then
    formatedRoot = formatedRoot .. mw.ustring.format(" (« %s »)", roots)
  end
  return formatedRoot
end

--[[
Create a link to the given affix and language section.
@param word string The affix to link to.
@param languageCode string The language code.
@return string The link.]]
local function formatAffix(word, type, languageName, languageCode)
  local affixes = mw.loadData(mw.ustring.format("Module:racine-étymologie/data/%s/affixes", languageName))
  local formattedAffix = ""
  local withoutDash = mw.ustring.gsub(word, "-", "")
  if type == PREFIX and affixes then
    formattedAffix = mw.ustring.format("'']'' (« %s »)", withoutDash, languageCode, word, affixes)
  elseif type == FINAL and affixes then
    formattedAffix = mw.ustring.format("'']'' (%s)", word, languageCode, word, affixes)
  elseif affixes then
    formattedAffix = mw.ustring.format("'']'' (« %s »)", word, languageCode, word, affixes)
  else
    formattedAffix = mw.ustring.format("'']''", word, languageCode, word)
  end
  return formattedAffix
end

--[[
Format a list of word elements of a given type.
@param etymology string The current etymology text to append to.
@param categories string The categories to append to.
@param list table The list of elements to format.
@param languageName string The name of the language.
@param languageCode string The code of the language.
@param type number The type of the elements, either ROOT, PREFIX or SUFFIX.
@return table A table containing the updated etymology and categories.]]
local function formatList(etymology, categories, list, languageName, languageCode, type)
  local types = {
     = { "du préfixe", "des préfixes", "préfixés avec" },
     = { "du suffixe", "des suffixes", "suffixés avec" },
     = { "de la racine", "des racines", "comportant la racine" },
     = { "de la finale", "des finales", "avec la terminaison" },
     = { "de la voyelle d’appui", "des voyelles d’appui", "comportant la voyelle d’appui" },
  }
  local singular, plural, category = unpack(types)

  local function formatItem(item)
    if type == ROOT then
      return formatRoot(item, languageName)
    else
      return formatAffix(item, type, languageName, languageCode)
    end
  end

  if #list == 1 then
    etymology = etymology .. " " .. singular .. " " .. formatItem(list)
    categories = categories .. mw.ustring.format("]", languageName, category, list)
  elseif #list > 1 then
    etymology = etymology .. " " .. plural .. " "
    local i = 1
    while i <= #list do
      if i ~= #list then
        etymology = etymology .. formatItem(list)
        if i ~= #list - 1 then
          etymology = etymology .. ", "
        end
      else
        etymology = etymology .. " et " .. formatItem(list)
      end
      categories = categories .. mw.ustring.format("]", languageName, category, list)
      i = i + 1
    end
  end
  
  return etymology, categories
end

--[[
Generate the etymology for the given word elements and language code.
@param elements table The word elements.
@param languageCode string The language code.
@return string The formatted etymology.]]
function p._generateEtymology(elements, languageCode)
  local etymology = "Composé"
  local morphemes = {}
  local categories = ""
  local languageName = m_langs.get_nom(languageCode)

  for _, element in ipairs(elements) do
    local type = getType(element)
    if type == ROOT then
      element = mw.ustring.gsub(element, "/", "")
    end
    table.insert(morphemes, {  = element,  = type } )
  end

  local i = 1
  while i <= #morphemes do
    local group = {}
    local type = morphemes
    if morphemes ~= nil then
      while morphemes == type do
        table.insert(group, morphemes)
        i = i + 1
      end
    end

    table.insert(group, morphemes)
    if i == #morphemes then
      etymology = etymology .. " et "
    end
    etymology, categories = formatList(etymology, categories, group, languageName, languageCode, type)
    if i < #morphemes - 1 then
      etymology = etymology .. ", "
    end
    i=i+1
  end
  if m_bases.page_de_contenu() then
    return etymology, categories
  else
    return etymology
  end
end

--[[
Generates an etymology for an Esperanto word.
frame.args (string): The language code.
parent.args (list of strings): The word elements (roots, affixes and final).
@return string The formatted etymology. ]]
function p.generateEtymology(frame)
  local langCode = m_params.process(frame.args, {
     = {
      required = true,
      checker = function(v)
        return m_langs.get_nom(v) ~= nil
      end
    },
  })
  return p._generateEtymology(frame:getParent().args, langCode)
end

return p