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

De alcolois
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Modification pour extraire aussi les numéros de dossier qui ont la forme dd-ddd, ddd-ddd et dddd-ddd en plus de dd-ddddddd qui ne sont pas des numéros de décision (cas entre 2000 et 1er juin 2004)
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


-- Extrait un identifiant de la forme : dd-500xxxx ou sinon dd-ddddddd
-- Extrait un identifiant de type dd-500xxxx (prioritaire), sinon dd-ddddddd
function p.extraireNoDeDecision(frame)
function p.extraireNoDeDecision(frame)
     local texte = frame.args[1] or ""
     local texte = frame.args[1] or ""


     -- 1. Match un identifiant de type 40-500xxxx
     -- 1. Priorité à ceux dont les 3 premiers chiffres après le tiret sont 500
     local identifiant = string.match(texte, "(%d%d%-500%d%d%d%d)")
     local identifiant = string.match(texte, "(%d%d%-500%d%d%d%d)")
     if identifiant then
     if identifiant then
Ligne 11 : Ligne 11 :
     end
     end


     -- 2. Sinon, match un identifiant générique de type dd-ddddddd (ex: 40-0009775)
     -- 2. Sinon, match un identifiant générique de type dd-ddddddd
     identifiant = string.match(texte, "(%d%d%-%d%d%d%d%d%d%d)")
     identifiant = string.match(texte, "(%d%d%-%d%d%d%d%d%d%d)")
     return identifiant or ""
     return identifiant or ""
end
end


-- Extrait un identifiant de la forme : dd-ddddddd-ddd (ex: 40-0733535-004)
-- Si un dd-500xxxx est présent, retourne tous les autres identifiants (sauf lui)
-- parmi les formats : dd-ddddddd, dd-ddd, ddd-ddd, dddd-ddd
function p.extraireNoDeDossier(frame)
function p.extraireNoDeDossier(frame)
     local texte = frame.args[1] or ""
     local texte = frame.args[1] or ""
     local identifiant = string.match(texte, "(%d%d%-%d%d%d%d%d%d%d%-%d%d%d)")
     local decision = string.match(texte, "(%d%d%-500%d%d%d%d)")
     return identifiant or ""
 
    local identifiants = {}
 
    if decision then
        local deja = {}
        deja[decision] = true
 
        -- Collecter les identifiants de formats variés
        for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do
            if not deja[id] then
                deja[id] = true
                table.insert(identifiants, id)
            end
        end
        for id in string.gmatch(texte, "(%d%d%-%d%d%d)") do
            if not deja[id] then
                deja[id] = true
                table.insert(identifiants, id)
            end
        end
        for id in string.gmatch(texte, "(%d%d%d%-%d%d%d)") do
            if not deja[id] then
                deja[id] = true
                table.insert(identifiants, id)
            end
        end
        for id in string.gmatch(texte, "(%d%d%d%d%-%d%d%d)") do
            if not deja[id] then
                deja[id] = true
                table.insert(identifiants, id)
            end
        end
    end
 
     return table.concat(identifiants, ", ")
end
end


return p
return p

Version du 2 juin 2025 à 17:58


local p = {}

-- Extrait un identifiant de type dd-500xxxx (prioritaire), sinon dd-ddddddd
function p.extraireNoDeDecision(frame)
    local texte = frame.args[1] or ""

    -- 1. Priorité à ceux dont les 3 premiers chiffres après le tiret sont 500
    local identifiant = string.match(texte, "(%d%d%-500%d%d%d%d)")
    if identifiant then
        return identifiant
    end

    -- 2. Sinon, match un identifiant générique de type dd-ddddddd
    identifiant = string.match(texte, "(%d%d%-%d%d%d%d%d%d%d)")
    return identifiant or ""
end

-- Si un dd-500xxxx est présent, retourne tous les autres identifiants (sauf lui)
-- parmi les formats : dd-ddddddd, dd-ddd, ddd-ddd, dddd-ddd
function p.extraireNoDeDossier(frame)
    local texte = frame.args[1] or ""
    local decision = string.match(texte, "(%d%d%-500%d%d%d%d)")

    local identifiants = {}

    if decision then
        local deja = {}
        deja[decision] = true

        -- Collecter les identifiants de formats variés
        for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do
            if not deja[id] then
                deja[id] = true
                table.insert(identifiants, id)
            end
        end
        for id in string.gmatch(texte, "(%d%d%-%d%d%d)") do
            if not deja[id] then
                deja[id] = true
                table.insert(identifiants, id)
            end
        end
        for id in string.gmatch(texte, "(%d%d%d%-%d%d%d)") do
            if not deja[id] then
                deja[id] = true
                table.insert(identifiants, id)
            end
        end
        for id in string.gmatch(texte, "(%d%d%d%d%-%d%d%d)") do
            if not deja[id] then
                deja[id] = true
                table.insert(identifiants, id)
            end
        end
    end

    return table.concat(identifiants, ", ")
end

return p