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 = {}


-- Gyors, de alapos formázó
-- Szupergyors tisztító: csak sima string műveleteket használ
local function formazSzinonimak(szoveg)
local function gyorsTisztitas(szoveg)
     if not szoveg or szoveg == "" then return "" end
     if not szoveg or szoveg == "" then return "" end
 
     -- Eltávolítjuk a speciális bájtokat, amik a đ, ÷, ¤ jeleket alkotják
     -- 1. Takarítás: töröljük a felesleges karaktereket (Unicode-biztosan)
     -- đ = \196\145, ÷ = \195\183, ¤ = \194\164
    local tiszta = mw.ustring.gsub(szoveg, "[đ÷¤]", "")
     local tiszta = szoveg:gsub("\196\145", ""):gsub("\195\183", ""):gsub("\194\164", "")
   
     tiszta = tiszta:gsub(">%-", ""):gsub(">≡", "≡"):gsub(">=", "=")
     -- 2. Jelek egységesítése
     return tiszta
    tiszta = tiszta:gsub(">−", "−"):gsub(">≡", "≡"):gsub(">=", "=")
   
    -- 3. Darabolás (a jelek mentén törünk új sorba)
     local lista = {}
    -- Unicode-biztos split alternatíva
    tiszta = mw.ustring.gsub(tiszta, "≡≡", "###")
    tiszta = mw.ustring.gsub(tiszta, "==", "###")
    tiszta = mw.ustring.gsub(tiszta, "−−", "###")
     tiszta = mw.ustring.gsub(tiszta, "%%-%%-", "###")
    tiszta = mw.ustring.gsub(tiszta, "|", "###")
 
    for r in mw.ustring.gmatch(tiszta, "[^#]+") do
        local tr = mw.text.trim(r)
        if tr ~= "" and tr ~= "''" then
            -- Dőltetés és speciális szavak javítása
            local f = "''" .. tr .. "''"
            f = f:gsub("≡", "''''"):gsub("=", "''=''"):gsub("−", "''−''")
            f = f:gsub("var%.", "''var.''"):gsub("subsp%.", "''subsp.''"):gsub("f%.", "''f.''")
            f = f:gsub("''''", "")
            table.insert(lista, "<li>" .. f .. "</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


41. sor: 16. sor:
      
      
     if szuro == "" then
     if szuro == "" then
         return "<div style='color:red; font-weight:bold; padding:10px; border:1px solid;'>Hiba: Adj meg egy nemzetséget szűrőként! (pl. {{CactaceaeTaxonokTáblázat|Opuntia}})</div>"
         return "<div style='color:red;'>Hiba: Adj meg egy nemzetséget!</div>"
     end
     end


     local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     if not status then return "Hiba: Adatmodul nem található." end
     if not status then return "Hiba: Adatmodul hiányzik." end
     local nyers = dataModul.getAdatok()
     local nyers = dataModul.getAdatok()


52. sor: 27. sor:
     local isVisible = false
     local isVisible = false
      
      
     -- Soronkénti feldolgozás
     -- Soronkénti feldolgozás bájtszinten (ez a leggyorsabb)
     for sor in mw.ustring.gmatch(nyers, "[^\r\n]+") do
     for sor in nyers:gmatch("[^\r\n]+") do
         local prefix = mw.ustring.sub(sor, 1, 1)
         local b1 = sor:byte(1)
          
          
         if prefix == "ß" then
        -- ß karakter (195 159)
             -- Megnézzük, hogy ez a kért nemzetség-e
         if b1 == 195 and sor:byte(2) == 159 then
            local nemz, tip = mw.ustring.match(sor, "^ß%s*([^:]+)::%s*(.+)")
             if sor:find(szuro, 1, true) then
            if nemz then
                local nemz = sor:match("ß%s*([^:]+)")
                local tisztaNemz = mw.text.trim(mw.ustring.gsub(nemz, "¤", ""))
                if nemz and mw.text.trim(nemz):gsub("\194\164", "") == szuro then
                if tisztaNemz == szuro then
                     isVisible = true
                     isVisible = true
                     counter = counter + 1
                     counter = counter + 1
                     table.insert(rows, "|-\n| " .. counter .. "\n| '''[[:Kategória:" .. tisztaNemz .. "|" .. tisztaNemz .. "]]'''\n| " .. formazSzinonimak(tip))
                    local tip = sor:match("::%s*(.+)") or ""
                 else
                     table.insert(rows, {counter, "'''[[:Kategória:"..szuro.."|"..szuro.."]]'''", tip})
                    isVisible = false
                 else isVisible = false end
                end
            else isVisible = false end
             end
              
         elseif isVisible and prefix == "Ł" then
        -- Ł karakter (197 129)
            -- Csak ha a szűrt nemzetségen belül vagyunk
         elseif isVisible and b1 == 197 and sor:byte(2) == 129 then
             local t, sz = mw.ustring.match(sor, "^Ł%s*([^¤]+)¤¤¤(.*)")
             local t, sz = sor:match("Ł%s*([^¤]+)¤¤¤(.*)")
             if t then
             if t then
                 counter = counter + 1
                 counter = counter + 1
                 table.insert(rows, "|-\n| " .. counter .. "\n| ''[[" .. mw.text.trim(t) .. "]]''\n| " .. formazSzinonimak(sz))
                 table.insert(rows, {counter, "''[["..mw.text.trim(t).."]]''", sz})
             end
             end
         end
         end
       
        -- Biztonsági korlát
         if counter >= 1000 then break end
         if counter >= 1000 then break end
     end
     end


     if #rows == 0 then return "Nincs találat a következő nemzetségre: " .. szuro end
     if #rows == 0 then return "Nincs találat: " .. szuro end
 
    -- 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


     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, szinonima\n'
     return frame:preprocess(head .. table.concat(rows, "\n") .. "\n|}")
     return frame:preprocess(head .. table.concat(finalRows, "\n") .. "\n|}")
end
end


return p
return p

A lap 2026. január 7., 10:36-kori változata

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

local p = {}

-- Szupergyors tisztító: csak sima string műveleteket használ
local function gyorsTisztitas(szoveg)
    if not szoveg or szoveg == "" then return "" end
    -- Eltávolítjuk a speciális bájtokat, amik a đ, ÷, ¤ jeleket alkotják
    -- đ = \196\145, ÷ = \195\183, ¤ = \194\164
    local tiszta = szoveg:gsub("\196\145", ""):gsub("\195\183", ""):gsub("\194\164", "")
    tiszta = tiszta:gsub(">%-", "−"):gsub(">≡", "≡"):gsub(">=", "=")
    return tiszta
end

function p.tablazat(frame)
    local args = frame:getParent().args
    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')
    if not status then return "Hiba: Adatmodul hiányzik." end
    local nyers = dataModul.getAdatok()

    local rows = {}
    local counter = 0
    local isVisible = false
    
    -- Soronkénti feldolgozás bájtszinten (ez a leggyorsabb)
    for sor in nyers:gmatch("[^\r\n]+") do
        local b1 = sor:byte(1)
        
        -- ß karakter (195 159)
        if b1 == 195 and sor:byte(2) == 159 then
            if sor:find(szuro, 1, true) then
                local nemz = sor:match("ß%s*([^:]+)")
                if nemz and mw.text.trim(nemz):gsub("\194\164", "") == szuro then
                    isVisible = true
                    counter = counter + 1
                    local tip = sor:match("::%s*(.+)") or ""
                    table.insert(rows, {counter, "'''[[:Kategória:"..szuro.."|"..szuro.."]]'''", tip})
                else isVisible = false end
            else isVisible = false end
            
        -- Ł karakter (197 129)
        elseif isVisible and b1 == 197 and sor:byte(2) == 129 then
            local t, sz = sor:match("Ł%s*([^¤]+)¤¤¤(.*)")
            if t then
                counter = counter + 1
                table.insert(rows, {counter, "''[["..mw.text.trim(t).."]]''", sz})
            end
        end
        if counter >= 1000 then break end
    end

    if #rows == 0 then return "Nincs találat: " .. szuro end

    -- 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

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

return p