Aller au contenu

« Module:Episode » : différence entre les versions

De Stargate Wiki Sémantique
Contenu supprimé Contenu ajouté
Aucun résumé des modifications
Aucun résumé des modifications
 
(Une version intermédiaire par le même utilisateur non affichée)
Ligne 13 : Ligne 13 :
s = mw.ustring.lower(s)
s = mw.ustring.lower(s)


-- 0) Supprimer les apostrophes HTML
-- Remplacement des accents
s = mw.ustring.gsub(s, "'", "")
s = mw.ustring.gsub(s, "'", "")
s = mw.ustring.gsub(s, "’", "")
s = mw.ustring.gsub(s, "‘", "")

-- 1) Supprimer les apostrophes simples et typographiques
s = mw.ustring.gsub(s, "[’']", "")

-- 2) Supprimer les virgules sans laisser d'espace
s = mw.ustring.gsub(s, ",", "")

-- 3) Remplacement des accents
local accents = {
local accents = {
["à"]="a", ["á"]="a", ["â"]="a", ["ä"]="a", ["ã"]="a", ["å"]="a",
["à"]="a", ["á"]="a", ["â"]="a", ["ä"]="a", ["ã"]="a", ["å"]="a",
Ligne 26 : Ligne 38 :
s = mw.ustring.gsub(s, ".", accents)
s = mw.ustring.gsub(s, ".", accents)


-- 1) Supprimer apostrophes et virgules SANS laisser d'espace
-- 4) Remplacer les autres caractères non alphanumériques par un espace
s = mw.ustring.gsub(s, "[’',]", "")

-- 2) Remplacer les autres caractères non alphanumériques par un espace
s = mw.ustring.gsub(s, "[^%w]", " ")
s = mw.ustring.gsub(s, "[^%w]", " ")


-- 3) Compresser les espaces
-- 5) Compresser les espaces
s = mw.ustring.gsub(s, "%s+", " ")
s = mw.ustring.gsub(s, "%s+", " ")


-- 4) Trim
-- 6) Trim
s = mw.text.trim(s)
s = mw.text.trim(s)


return s
return s
end
end



-- Exécution des parseurs MediaWiki
-- Exécution des parseurs MediaWiki
Ligne 198 : Ligne 208 :
end
end



-- Affichage des alias en conflit (alias → plusieurs pages)
function p.showAliasConflicts()
function p.debugAllAliases()
local map = p.aliasToPages()
local out = {}
local out = {}
table.insert(out, "== Vérification complète des alias ==")


for alias, entry in pairs(data) do
table.insert(out, "== Alias pointant vers plusieurs pages ==")
local norm = normalizeAlias(alias)
local ok = data[norm] and "✔" or "✘"


table.insert(out,
local found = false
string.format(

"* %s <code>%s</code> → <code>%s</code>%s",
for alias, pages in pairs(map) do
if #pages > 1 then
ok,
found = true
alias,
table.insert(out,
norm,
"* <code>" .. alias .. "</code> " .. table.concat(pages, " / ")
ok == "✘" and " (introuvable)" or ""
)
)
end
)
end

if not found then
table.insert(out, "* Aucun conflit détecté")
end
end


Ligne 223 : Ligne 231 :
end
end


function p.debugListNormalized()
function p.testTitle(frame)
local input = frame.args[1] or ""
local norm = normalizeAlias(input)
local exists = data[norm] ~= nil

local out = {}
local out = {}
table.insert(out, "== Liste des alias normalisés ==")
table.insert(out, "== Test de normalisation ==")
table.insert(out, "* Entrée : <code>" .. input .. "</code>")

table.insert(out, "* Normalisé : <code>" .. norm .. "</code>")
for alias, entry in pairs(data) do
table.insert(out, "* Trouvé : " .. (exists and "✔ oui" or "✘ non"))
local norm = normalizeAlias(alias)
table.insert(out,
"* <code>" .. alias .. "</code> → <code>" .. norm .. "</code>"
)
end


return table.concat(out, "\n")
return table.concat(out, "\n")

Dernière version du 7 juin 2026 à 14:25

Documentation icon Documentation module[créer]
local data = mw.loadData("Module:Episode/data")
local p = {}

-- Sécurisation des valeurs nil
local function safe(v)
    return v or ""
end

-- Normalisation robuste des alias
local function normalizeAlias(s)
    if not s then return "" end

    s = mw.ustring.lower(s)

    -- 0) Supprimer les apostrophes HTML
    s = mw.ustring.gsub(s, "&#39;", "")
    s = mw.ustring.gsub(s, "&apos;", "")
    s = mw.ustring.gsub(s, "&rsquo;", "")
    s = mw.ustring.gsub(s, "&lsquo;", "")

    -- 1) Supprimer les apostrophes simples et typographiques
    s = mw.ustring.gsub(s, "[’']", "")

    -- 2) Supprimer les virgules sans laisser d'espace
    s = mw.ustring.gsub(s, ",", "")

    -- 3) Remplacement des accents
    local accents = {
        ["à"]="a", ["á"]="a", ["â"]="a", ["ä"]="a", ["ã"]="a", ["å"]="a",
        ["ç"]="c",
        ["è"]="e", ["é"]="e", ["ê"]="e", ["ë"]="e",
        ["ì"]="i", ["í"]="i", ["î"]="i", ["ï"]="i",
        ["ñ"]="n",
        ["ò"]="o", ["ó"]="o", ["ô"]="o", ["ö"]="o", ["õ"]="o",
        ["ù"]="u", ["ú"]="u", ["û"]="u", ["ü"]="u",
        ["ý"]="y", ["ÿ"]="y"
    }
    s = mw.ustring.gsub(s, ".", accents)

    -- 4) Remplacer les autres caractères non alphanumériques par un espace
    s = mw.ustring.gsub(s, "[^%w]", " ")

    -- 5) Compresser les espaces
    s = mw.ustring.gsub(s, "%s+", " ")

    -- 6) Trim
    s = mw.text.trim(s)

    return s
end


-- Exécution des parseurs MediaWiki
local function parse(wikitext)
    return mw.getCurrentFrame():preprocess(wikitext)
end

-- Function 1: Get full episode link from key
function p.getEpisode(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local ns  = safe(entry[1])
    local link = safe(entry[2])
    local title = safe(entry[3])

    local wikitext
    if ns == "" then
        wikitext = string.format("[[%s|%s]]", link, title)
    else
        wikitext = string.format("[[%s:%s|%s]]", ns, link, title)
    end

    return parse(wikitext)
end

-- Function 2: Force namespace to "Credits:"
function p.getCreditsLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local link = safe(entry[2])
    local title = safe(entry[3])

    return parse(string.format("[[Crédits:%s|%s]]", link, title))
end

-- Function 3: Force namespace to "Transcript:"
function p.getTranscriptLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local link = safe(entry[2])
    local title = safe(entry[3])

    return parse(string.format("[[Retranscription:%s|%s]]", link, title))
end

-- Function 4: Force namespace to "Quotes:"
function p.getQuotesLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local link = safe(entry[2])
    local title = safe(entry[3])

    return parse(string.format("[[Citations:%s|%s]]", link, title))
end

-- Function 5: Force namespace to "Category:Images from"
function p.getImagesLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local link = safe(entry[2])
    local title = safe(entry[3])

    return parse(string.format("[[:Catégorie:Images de %s|%s]]", link, title))
end

-- Function 6: Retrieve from link
function p.getEpisodeLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    return safe(entry[2])
end

-- Function 7: Get full episode link only from key
function p.getEpisodeFullLink(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Épisode non référencé"
    end

    local ns = safe(entry[1])
    local link = safe(entry[2])

    if ns == "" then
        return link
    else
        return ns .. ":" .. link
    end
end

-- Function 8: Get episode title only from key
function p.getEpisodeTitle(frame)
    local key = normalizeAlias(frame.args[1])
    local entry = data[key]

    if not entry then
        return "Episode not found"
    end

    return safe(entry[3])
end

-- Alias → pages
function p.aliasToPages()
    local map = {}

    for alias, entry in pairs(data) do
        local link = entry[2]

        if not map[alias] then
            map[alias] = { link }
        else
            local exists = false
            for _, v in ipairs(map[alias]) do
                if v == link then
                    exists = true
                    break
                end
            end
            if not exists then
                table.insert(map[alias], link)
            end
        end
    end

    return map
end


function p.debugAllAliases()
    local out = {}
    table.insert(out, "== Vérification complète des alias ==")

    for alias, entry in pairs(data) do
        local norm = normalizeAlias(alias)
        local ok = data[norm] and "✔" or "✘"

        table.insert(out,
            string.format(
                "* %s <code>%s</code> → <code>%s</code>%s",
                ok,
                alias,
                norm,
                ok == "✘" and " (introuvable)" or ""
            )
        )
    end

    return table.concat(out, "\n")
end

function p.testTitle(frame)
    local input = frame.args[1] or ""
    local norm = normalizeAlias(input)
    local exists = data[norm] ~= nil

    local out = {}
    table.insert(out, "== Test de normalisation ==")
    table.insert(out, "* Entrée : <code>" .. input .. "</code>")
    table.insert(out, "* Normalisé : <code>" .. norm .. "</code>")
    table.insert(out, "* Trouvé : " .. (exists and "✔ oui" or "✘ non"))

    return table.concat(out, "\n")
end

return p