Ce module définit des fonctions pour manipuler les types de mots (nom, adjectif, etc.).
La définition des types de mots standardisés et des alias autorisés est écrite dans Module:types de mots/data.
isValidWordType()
Indique si la valeur passée est un type de mot standardisé valide.
code
(string) : La valeur à tester.isWordTypeAlias()
Indique si la valeur passée est un alias de type de mot standardisé.
code
(string) : La valeur à tester.getWordTypeName()
Retourne le nom formaté d’un type de mot standardisé.
code
(string) : Le type de mot standardisé à formater.isLocution
(boolean) : Indique si le nom doit être une locution.isFlexion
(boolean) : Indique si le nom doit être une flexion.isPlural
(boolean) : Indique si le nom doit être au pluriel.getWordTypeNameSingular()
Alias de getWordTypeName()
qui retourne le nom au singulier.
code
(string) : Le type de mot standardisé à formater.isLocution
(boolean) : Indique si le nom doit être une locution.isFlexion
(boolean) : Indique si le nom doit être une flexion.getWordTypeNamePlural()
Alias de getWordTypeName()
qui retourne le nom au pluriel.
code
(string) : Le type de mot standardisé à formater.isLocution
(boolean) : Indique si le nom doit être une locution.isFlexion
(boolean) : Indique si le nom doit être une flexion.getWordTypeAbbr()
Retourne le nom abrégé d’un type de mot standardisé.
code
(string) : Le type de mot standardisé à formater.isFlexion
(boolean) : Indique si le nom abrégé doit être préfixé de flex-
.La documentation de ce module est générée par le modèle {{Documentation module}}.
Elle est incluse depuis la page Module:types de mots/Documentation. Veuillez placer les catégories sur cette page-là.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
-- Page de test : Utilisateur:Darkdadaah/Test:Sections
local m_bases = require("Module:bases")
local p = {}
-- Expose data
p.types = mw.loadData("Module:types de mots/data")
--- Check whether the given value is a valid word type code from ].
--- @param code string The string to check.
--- @return boolean True if the argument is a valid word type code, false otherwise.
function p.isValidWordType(code)
return code ~= nil and p.types or p.types
end
--- Check whether the given value is a valid word type code alias from ].
--- @param code string The string to check.
--- @return boolean True if the argument is a valid word type code alias, false otherwise.
function p.isWordTypeAlias(code)
return code ~= nil and p.types
end
--- Get the phrase for the flexion of the given word type.
--- @param wordType string The word type.
--- @param isPlural boolean Whether to return the plural form instead of the singular.
--- @return string A string in the form `"forme d{’|e }<wordType>"`.
local function getFlexionType(wordType, isPlural)
return mw.ustring.format(
"forme%s d%s%s",
isPlural and "s" or "",
m_bases.is_elidable(wordType) and "’" or "e ",
wordType
)
end
--- Get the name of the given word type code.
--- @param code string A word type from ].
--- @param isLocution boolean Whether the word is a locution.
--- @param isFlexion boolean Whether the word is a flexion.
--- @param isPlural boolean Whether to return the plural form instead of the singular.
--- @return string|nil A string containing the name for the code, `nil` if the code is `nil` or invalid.
function p.getWordTypeName(code, isLocution, isFlexion, isPlural)
if code == nil then
return nil
end
if p.types then
code = p.types
end
if p.types then
local key
if isLocution and p.types then
key = "locution"
else
key = "mot"
end
if isPlural then
key = key .. "_pl"
end
local name = p.types
if isFlexion then
name = getFlexionType(name, isPlural)
end
return name;
end
return nil
end
--- Get the singular name of the given word type code.
--- Same as calling `p.getWordTypeName(code, isLocution, isFlexion, false)`.
--- @param code string A word type from ].
--- @param isLocution boolean Whether the word is a locution.
--- @param isFlexion boolean Whether the word is a flexion.
--- @return string|nil A string containing the name for the code, `nil` if the code is `nil` or invalid.
function p.getWordTypeNameSingular(code, isLocution, isFlexion)
return p.getWordTypeName(code, isLocution, isFlexion, false)
end
--- Get the plural name of the given word type code.
--- Same as calling `p.getWordTypeName(code, isLocution, isFlexion, true)`.
--- @param code string A word type from ].
--- @param isLocution boolean Whether the word is a locution.
--- @param isFlexion boolean Whether the word is a flexion.
--- @return string|nil A string containing the name for the code, `nil` if the code is `nil` or invalid.
function p.getWordTypeNamePlural(code, isLocution, isFlexion)
return p.getWordTypeName(code, isLocution, isFlexion, true)
end
--- Return the abbreviated name of the given word type code.
--- @param code string A word type from ].
--- @param isFlexion boolean Whether the word is a flexion.
--- @return string|nil A string in the form `<abbr name>`, or `nil` if the code is `nil` or invalid.
function p.getWordTypeAbbr(code, isFlexion)
if code == nil then
return nil
end
if p.types then
code = p.types
end
if p.types then
local abbrName = p.types
if isFlexion then
abbrName = "flex-" .. abbrName
end
return abbrName
end
return nil
end
return p