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

De alcolois
Aller à la navigation Aller à la recherche
Nouvelle mouture qui conserve les numéros de dossier qui ont la forme dd-ddddddd-ddd
Nouvelle version
 
(4 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
local p = {}
local p = {}


-- Extrait un identifiant de type dd-500xxxx (prioritaire), sinon dd-ddddddd
-- Extrait : dd-500xxxx prioritairement, sinon dd-ddddddd qui n’est pas suivi de -ddd
function p.extraireNoDeDecision(frame)
function p.extraireNoDeDecision(frame)
     local texte = frame.args[1] or ""
     local texte = frame.args[1] or ""
     local identifiant = string.match(texte, "(%d%d%-500%d%d%d%d)")
 
    -- 1. Essayer de capturer un identifiant 500xxxx
     local identifiant = string.match(texte, "(%f[%d]%d%d%-500%d%d%d%d%f[%D])")
     if identifiant then
     if identifiant then
         return identifiant
         return identifiant
     end
     end
     identifiant = string.match(texte, "(%d%d%-%d%d%d%d%d%d%d)")
 
     return identifiant or ""
     -- 2. Sinon, chercher un identifiant dd-ddddddd NON suivi de -ddd
    for id in string.gmatch(texte, "%d%d%-%d%d%d%d%d%d%d") do
        local startPos, endPos = string.find(texte, id, 1, true)
        if startPos then
            local suivant = string.sub(texte, endPos + 1, endPos + 4)
            if not suivant:match("^%-%d%d%d") then
                return id
            end
        end
    end
 
     return ""
end
end


-- Si un dd-500xxxx est présent, retourne les identifiants secondaires :
-- Extrait tous les identifiants sauf celui de décision
-- dd-ddddddd, dd-ddddddd-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 decision = string.match(texte, "(%d%d%-500%d%d%d%d)")
 
     local deja = {}
    -- Utilise la fonction précédente pour déterminer ce qui doit être exclu
     local decision = p.extraireNoDeDecision{ args = { texte } }
     local deja = { [decision] = true }
    local prefixesExclus = {}
     local identifiants = {}
     local identifiants = {}


     if decision then
     -- 1. dd-ddddddd-ddd
        deja[decision] = true
    for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d%-%d%d%d)") do
 
        if not deja[id] then
        -- 1. dd-ddddddd
            deja[id] = true
        for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do
            prefixesExclus[string.match(id, "^(%d%d%-%d%d%d%d%d%d%d)")] = true
            if not deja[id] then
            table.insert(identifiants, id)
                deja[id] = true
                table.insert(identifiants, id)
            end
         end
         end
    end


        -- 2. dd-ddddddd-ddd
    -- 2. dd-ddddddd (sauf préfixes déjà capturés)
        for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d%-%d%d%d)") do
    for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do
            if not deja[id] then
        if not deja[id] and not prefixesExclus[id] then
                deja[id] = true
            deja[id] = true
                table.insert(identifiants, id)
            table.insert(identifiants, id)
            end
         end
         end
    end


        -- 3. ddd-ddd
    -- 3. ddd-ddd
        for id in string.gmatch(texte, "(%f[%d]%d%d%d%-%d%d%d%f[%D])") do
    for id in string.gmatch(texte, "(%f[%d]%d%d%d%-%d%d%d%f[%D])") do
            if not deja[id] then
        if not deja[id] then
                deja[id] = true
            deja[id] = true
                table.insert(identifiants, id)
            table.insert(identifiants, id)
            end
         end
         end
    end


        -- 4. dddd-ddd
    -- 4. dddd-ddd
        for id in string.gmatch(texte, "(%f[%d]%d%d%d%d%-%d%d%d%f[%D])") do
    for id in string.gmatch(texte, "(%f[%d]%d%d%d%d%-%d%d%d%f[%D])") do
            if not deja[id] then
        if not deja[id] then
                deja[id] = true
            deja[id] = true
                table.insert(identifiants, id)
            table.insert(identifiants, id)
            end
         end
         end
     end
     end

Dernière version du 2 juin 2025 à 19:00


local p = {}

-- Extrait : dd-500xxxx prioritairement, sinon dd-ddddddd qui n’est pas suivi de -ddd
function p.extraireNoDeDecision(frame)
    local texte = frame.args[1] or ""

    -- 1. Essayer de capturer un identifiant 500xxxx
    local identifiant = string.match(texte, "(%f[%d]%d%d%-500%d%d%d%d%f[%D])")
    if identifiant then
        return identifiant
    end

    -- 2. Sinon, chercher un identifiant dd-ddddddd NON suivi de -ddd
    for id in string.gmatch(texte, "%d%d%-%d%d%d%d%d%d%d") do
        local startPos, endPos = string.find(texte, id, 1, true)
        if startPos then
            local suivant = string.sub(texte, endPos + 1, endPos + 4)
            if not suivant:match("^%-%d%d%d") then
                return id
            end
        end
    end

    return ""
end

-- Extrait tous les identifiants sauf celui de décision
function p.extraireNoDeDossier(frame)
    local texte = frame.args[1] or ""

    -- Utilise la fonction précédente pour déterminer ce qui doit être exclu
    local decision = p.extraireNoDeDecision{ args = { texte } }
    local deja = { [decision] = true }
    local prefixesExclus = {}
    local identifiants = {}

    -- 1. dd-ddddddd-ddd
    for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d%-%d%d%d)") do
        if not deja[id] then
            deja[id] = true
            prefixesExclus[string.match(id, "^(%d%d%-%d%d%d%d%d%d%d)")] = true
            table.insert(identifiants, id)
        end
    end

    -- 2. dd-ddddddd (sauf préfixes déjà capturés)
    for id in string.gmatch(texte, "(%d%d%-%d%d%d%d%d%d%d)") do
        if not deja[id] and not prefixesExclus[id] then
            deja[id] = true
            table.insert(identifiants, id)
        end
    end

    -- 3. ddd-ddd
    for id in string.gmatch(texte, "(%f[%d]%d%d%d%-%d%d%d%f[%D])") do
        if not deja[id] then
            deja[id] = true
            table.insert(identifiants, id)
        end
    end

    -- 4. dddd-ddd
    for id in string.gmatch(texte, "(%f[%d]%d%d%d%d%-%d%d%d%f[%D])") do
        if not deja[id] then
            deja[id] = true
            table.insert(identifiants, id)
        end
    end

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

return p