Ugrás a tartalomhoz

„Modul:CactaceaeTaxonok” változatai közötti eltérés

Innen: MKOE wiki
Nincs szerkesztési összefoglaló
Nincs szerkesztési összefoglaló
1. sor: 1. sor:
local p = {}
local p = {}


-- Szupergyors tisztító: csak sima string műveleteket használ
-- Gyors formázó a szinonimákhoz és típusfajokhoz
local function gyorsTisztitas(szoveg)
local function formazSzinonimak(sor)
     if not szoveg or szoveg == "" then return "" end
     if not sor or sor == "" then return "" end
     -- Eltávolítjuk a speciális bájtokat, amik a đ, ÷, ¤ jeleket alkotják
 
     -- đ = \196\145, ÷ = \195\183, ¤ = \194\164
     local lista = {}
    local tiszta = szoveg:gsub("\196\145", ""):gsub("\195\183", ""):gsub("\194\164", "")
    -- A 3-as és 4-es jelölők mentén darabolunk
    tiszta = tiszta:gsub(">%-", ""):gsub(">≡", ""):gsub(">=", "=")
     -- Minták: 3 ≡≡ ... 3# vagy 3 == ... 3# vagy 4 ≡ ... 4#
     return tiszta
    for szint, jel, tartalom in sor:gmatch("(%d)%s*([^%d%s#]+)%s*([^#]+)%s*%d#") do
        local tiszta_tartalom = mw.text.trim(tartalom)
        if tiszta_tartalom ~= "" then
            -- Botanikai rövidítések (var., subsp., f.) állóvá tétele a dőlt szövegben
            local f = "''" .. tiszta_tartalom .. "''"
            f = f:gsub("var%.", "''var.''"):gsub("subsp%.", "''subsp.''"):gsub("f%.", "''f.''")
            -- Speciális jelek (≡, ==, −) ne legyenek dőltek
            local sor_elem = "''" .. jel .. "'' " .. f
            sor_elem = sor_elem:gsub("''''", "") -- Takarítás
           
            table.insert(lista, "<li>" .. sor_elem .. "</li>")
        end
    end
 
    if #lista == 0 then return "" end
     return '<ul style="margin-left:1.1em; list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>"
end
end


15. sor: 30. sor:
     local szuro = args[1] and mw.text.trim(args[1]) or ""
     local szuro = args[1] and mw.text.trim(args[1]) or ""
      
      
    if szuro == "" then
        return "<div style='color:red;'>Hiba: Adj meg egy nemzetséget!</div>"
    end
     local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     if not status then return "Hiba: Adatmodul hiányzik." end
     if not status then return "Hiba: Modul:CactaceaeTaxonokData nem található." end
     local nyers = dataModul.getAdatok()
     local nyers = dataModul.getAdatok()


26. sor: 37. sor:
     local counter = 0
     local counter = 0
     local isVisible = false
     local isVisible = false
   
 
     -- Soronkénti feldolgozás bájtszinten (ez a leggyorsabb)
     -- Soronkénti feldolgozás az új formátum alapján
     for sor in nyers:gmatch("[^\r\n]+") do
     for sor in nyers:gmatch("[^\r\n]+") do
         local b1 = sor:byte(1)
         local szint = sor:sub(1, 1)
       
 
         -- ß karakter (195 159)
         -- 1-es szint: Nemzetség (pl. 1 Acanthocalycium :: Type: ...)
         if b1 == 195 and sor:byte(2) == 159 then
         if szint == "1" then
             if sor:find(szuro, 1, true) then
             local nemz, extra = sor:match("^1%s+([^%s:]+)%s*(.*)")
                local nemz = sor:match("ß%s*([^:]+)")
            if nemz then
                 if nemz and mw.text.trim(nemz):gsub("\194\164", "") == szuro then
                 if szuro == "" or nemz == szuro then
                     isVisible = true
                     isVisible = true
                     counter = counter + 1
                     counter = counter + 1
                     local tip = sor:match("::%s*(.+)") or ""
                    -- A nemzetség sor végén lévő 1# előtti részt formázzuk
                     table.insert(rows, {counter, "'''[[:Kategória:"..szuro.."|"..szuro.."]]'''", tip})
                     local tipus_info = extra:match("::%s*(.-)%s*1#") or ""
                 else isVisible = false end
                   
             else isVisible = false end
                     table.insert(rows, "|-\n| " .. counter .. "\n| '''[[:Kategória:" .. nemz .. "|" .. nemz .. "]]'''\n| " .. formazSzinonimak(tipus_info))
           
                 else
         -- Ł karakter (197 129)
                    isVisible = false
         elseif isVisible and b1 == 197 and sor:byte(2) == 129 then
                end
             local t, sz = sor:match("Ł%s*([^¤]+)¤¤¤(.*)")
             end
             if t then
 
         -- 2-es szint: Faj (pl. 2 Acanthocalycium glaucum 2# 3 ...)
         elseif szint == "2" and isVisible then
             local fajnev, maradek = sor:match("^2%s+([^2#]+)2#%s*(.*)")
             if fajnev then
                 counter = counter + 1
                 counter = counter + 1
                 table.insert(rows, {counter, "''[["..mw.text.trim(t).."]]''", sz})
                local tiszta_fajnev = mw.text.trim(fajnev)
                 table.insert(rows, "|-\n| " .. counter .. "\n| ''[[" .. tiszta_fajnev .. "]]''\n| " .. formazSzinonimak(maradek))
             end
             end
         end
         end
        if counter >= 1000 then break end
     end
     end


     if #rows == 0 then return "Nincs találat: " .. szuro end
     if #rows == 0 then  
 
        return szuro ~= "" and "Nincs találat a következő nemzetségre: " .. szuro or "Nincs megjeleníthető adat."
    -- TÁBLÁZAT ÖSSZEÁLLÍTÁSA (Csak itt formázunk, hogy spóroljunk a CPU-val)
    local finalRows = {}
    for i, data in ipairs(rows) do
        local szinonimak = ""
        if data[3] ~= "" then
            local t = gyorsTisztitas(data[3])
            local lista = {}
            -- Egyszerű darabolás
            for r in t:gmatch("[^|≡=−]+") do
                local tr = mw.text.trim(r)
                if tr ~= "" and tr ~= "''" then
                    table.insert(lista, "<li>''" .. tr .. "''</li>")
                end
            end
            if #lista > 0 then
                szinonimak = '<ul style="margin-left:1.1em; list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>"
            end
        end
        table.insert(finalRows, "|-\n| " .. data[1] .. "\n| " .. data[2] .. "\n| " .. szinonimak)
     end
     end


     local head = '{| class="wikitable sortable datatable-hook stripe hover compact" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonima\n'
     local head = '{| class="wikitable sortable datatable-hook stripe hover compact" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonimák\n'
     return frame:preprocess(head .. table.concat(finalRows, "\n") .. "\n|}")
     return frame:preprocess(head .. table.concat(rows, "\n") .. "\n|}")
end
end


return p
return p

A lap 2026. január 9., 18:33-kori változata

A modult a Modul:CactaceaeTaxonok/doc lapon tudod dokumentálni

local p = {}

-- Gyors formázó a szinonimákhoz és típusfajokhoz
local function formazSzinonimak(sor)
    if not sor or sor == "" then return "" end

    local lista = {}
    -- A 3-as és 4-es jelölők mentén darabolunk
    -- Minták: 3 ≡≡ ... 3# vagy 3 == ... 3# vagy 4 ≡ ... 4#
    for szint, jel, tartalom in sor:gmatch("(%d)%s*([^%d%s#]+)%s*([^#]+)%s*%d#") do
        local tiszta_tartalom = mw.text.trim(tartalom)
        if tiszta_tartalom ~= "" then
            -- Botanikai rövidítések (var., subsp., f.) állóvá tétele a dőlt szövegben
            local f = "''" .. tiszta_tartalom .. "''"
            f = f:gsub("var%.", "''var.''"):gsub("subsp%.", "''subsp.''"):gsub("f%.", "''f.''")
            -- Speciális jelek (≡, ==, −) ne legyenek dőltek
            local sor_elem = "''" .. jel .. "'' " .. f
            sor_elem = sor_elem:gsub("''''", "") -- Takarítás
            
            table.insert(lista, "<li>" .. sor_elem .. "</li>")
        end
    end

    if #lista == 0 then return "" end
    return '<ul style="margin-left:1.1em; list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>"
end

function p.tablazat(frame)
    local args = frame:getParent().args
    local szuro = args[1] and mw.text.trim(args[1]) or ""
    
    local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
    if not status then return "Hiba: Modul:CactaceaeTaxonokData nem található." end
    local nyers = dataModul.getAdatok()

    local rows = {}
    local counter = 0
    local isVisible = false

    -- Soronkénti feldolgozás az új formátum alapján
    for sor in nyers:gmatch("[^\r\n]+") do
        local szint = sor:sub(1, 1)

        -- 1-es szint: Nemzetség (pl. 1 Acanthocalycium :: Type: ...)
        if szint == "1" then
            local nemz, extra = sor:match("^1%s+([^%s:]+)%s*(.*)")
            if nemz then
                if szuro == "" or nemz == szuro then
                    isVisible = true
                    counter = counter + 1
                    -- A nemzetség sor végén lévő 1# előtti részt formázzuk
                    local tipus_info = extra:match("::%s*(.-)%s*1#") or ""
                    
                    table.insert(rows, "|-\n| " .. counter .. "\n| '''[[:Kategória:" .. nemz .. "|" .. nemz .. "]]'''\n| " .. formazSzinonimak(tipus_info))
                else
                    isVisible = false
                end
            end

        -- 2-es szint: Faj (pl. 2 Acanthocalycium glaucum 2# 3 ...)
        elseif szint == "2" and isVisible then
            local fajnev, maradek = sor:match("^2%s+([^2#]+)2#%s*(.*)")
            if fajnev then
                counter = counter + 1
                local tiszta_fajnev = mw.text.trim(fajnev)
                table.insert(rows, "|-\n| " .. counter .. "\n| ''[[" .. tiszta_fajnev .. "]]''\n| " .. formazSzinonimak(maradek))
            end
        end
    end

    if #rows == 0 then 
        return szuro ~= "" and "Nincs találat a következő nemzetségre: " .. szuro or "Nincs megjeleníthető adat."
    end

    local head = '{| class="wikitable sortable datatable-hook stripe hover compact" style="width:100%; font-size:90%;"\n! # !! Taxonnév !! Típusfaj, szinonimák\n'
    return frame:preprocess(head .. table.concat(rows, "\n") .. "\n|}")
end

return p