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ó
(6 közbenső módosítás ugyanattól a felhasználótól nincs mutatva)
1. sor: 1. sor:
local p = {}
local p = {}


-- Gyors formázó: az mw.ustring-et csak ott használjuk, ahol elengedhetetlen
-- 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
    -- đ = \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


     -- Unicode takarítás és jelek előkészítése
function p.tablazat(frame)
     local tiszta = mw.ustring.gsub(szoveg, "[đ÷]", "")
     local args = frame:getParent().args
    tiszta = tiszta:gsub("¤+", ""):gsub(">−", "−"):gsub(">≡", "≡"):gsub(">=", "=")
     local szuro = args[1] and mw.text.trim(args[1]) or ""
      
      
     -- Elválasztók
     if szuro == "" then
    tiszta = tiszta:gsub("≡≡", "|≡"):gsub("==", "|="):gsub("−−", "|−"):gsub("%%-%%-", "|−")
        return "<div style='color:red;'>Hiba: Adj meg egy nemzetséget!</div>"
    end


     local lista_elemek = {}
     local status, dataModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     local reszek = mw.text.split(tiszta, "|", true)
    if not status then return "Hiba: Adatmodul hiányzik." end
     local nyers = dataModul.getAdatok()
 
    local rows = {}
    local counter = 0
    local isVisible = false
      
      
     for i=1, #reszek do
    -- Soronkénti feldolgozás bájtszinten (ez a leggyorsabb)
         local tiszta_resz = mw.text.trim(reszek[i])
     for sor in nyers:gmatch("[^\r\n]+") do
         if tiszta_resz ~= "" then
         local b1 = sor:byte(1)
             -- Dőltetés trükk: alapból dőlt, a jeleknél megszakítjuk
       
            local formazott = "''" .. tiszta_resz .. "''"
        -- ß karakter (195 159)
            formazott = formazott:gsub("", "''≡''"):gsub("=", "''=''"):gsub("−", "''−''")
         if b1 == 195 and sor:byte(2) == 159 then
            formazott = formazott:gsub("Type:", "''Type:''"):gsub("var%.", "''var.''")
             if sor:find(szuro, 1, true) then
             formazott = formazott:gsub("subsp%.", "''subsp.''"):gsub("f%.", "''f.''")
                local nemz = sor:match("ß%s*([^:]+)")
             formazott = formazott:gsub("''''", "")
                if nemz and mw.text.trim(nemz):gsub("\194\164", "") == szuro then
             table.insert(lista_elemek, "<li>" .. formazott .. "</li>")
                    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
         end
        if counter >= 1000 then break end
     end
     end
   
    if #lista_elemek == 0 then return "" end
    return '<ul style="margin-left: 1.1em; list-style-type: disc; padding: 0; margin: 0;">' .. table.concat(lista_elemek) .. "</ul>"
end


function p.tablazat(frame)
     if #rows == 0 then return "Nincs találat: " .. szuro end
    local args = frame.args[1] and frame.args or frame:getParent().args
    local szuroNemzettseg = args[1] and mw.text.trim(args[1]) or nil
     if szuroNemzettseg == "" then szuroNemzettseg = nil end


     local status, adatModul = pcall(require, 'Modul:CactaceaeTaxonokData')
     -- TÁBLÁZAT ÖSSZEÁLLÍTÁSA (Csak itt formázunk, hogy spóroljunk a CPU-val)
    if not status then return "Hiba: Adatmodul nem található!" end
     local finalRows = {}
   
     for i, data in ipairs(rows) do
    -- BEOLVASÁS ÉS CSERE: Itt trükközünk a sebességért
         local szinonimak = ""
    local nyers_adat = adatModul.getAdatok()
         if data[3] ~= "" then
    -- Lecseréljük a kezdőkaraktereket belső ASCII kódokra
            local t = gyorsTisztitas(data[3])
    nyers_adat = nyers_adat:gsub("ß", "GENUS_MARKER")
             local lista = {}
    nyers_adat = nyers_adat:gsub("Ł", "SPECIES_MARKER")
            -- Egyszerű darabolás
 
            for r in t:gmatch("[^|≡=−]+") do
     local rows = {}
                 local tr = mw.text.trim(r)
     local sorszam = 0
                 if tr ~= "" and tr ~= "''" then
    local jelenlegiNemzettseg = ""
                     table.insert(lista, "<li>''" .. tr .. "''</li>")
    local megjelenit = true
 
    -- Mivel már nincsenek az elején "furcsa" karakterek, a sima gmatch is stabilabb
    for sor in nyers_adat:gmatch("[^\r\n]+") do
         local taxon_link = ""
         local szinonimak_nyers = ""
 
        -- Nemzetség detektálása
        if sor:find("^GENUS_MARKER") then
             local nemz, tip = sor:match("^GENUS_MARKER%s*([^:]+)::%s*(.+)")
            if nemz then
                 jelenlegiNemzettseg = mw.text.trim(nemz):gsub("¤+", "")
                 if not szuroNemzettseg or szuroNemzettseg == jelenlegiNemzettseg then
                     taxon_link = "'''[[:Kategória:" .. jelenlegiNemzettseg .. "|" .. jelenlegiNemzettseg .. "]]'''"
                    szinonimak_nyers = tip
                    megjelenit = true
                else
                    megjelenit = false
                 end
                 end
             end
             end
        -- Faj detektálása
            if #lista > 0 then
        elseif sor:find("^SPECIES_MARKER") and megjelenit then
                szinonimak = '<ul style="margin-left:1.1em; list-style-type:disc; padding:0; margin:0;">' .. table.concat(lista) .. "</ul>"
            local tiszta_sor = sor:gsub("^SPECIES_MARKER%s*", "")
            local t, sz = tiszta_sor:match("([^¤]+)¤¤¤(.*)")
            if t then
                local tiszta_nev = mw.text.trim(t)
                taxon_link = "''[[" .. tiszta_nev .. "]]''"
                szinonimak_nyers = sz
             end
             end
         end
         end
 
         table.insert(finalRows, "|-\n| " .. data[1] .. "\n| " .. data[2] .. "\n| " .. szinonimak)
         if taxon_link ~= "" then
            sorszam = sorszam + 1
            table.insert(rows, "|-\n| " .. sorszam .. "\n| " .. taxon_link .. "\n| " .. formazSzinonimak(szinonimak_nyers))
        end
     end
     end


     local header = '{| class="wikitable sortable datatable-hook stripe hover compact" data-page-length="50" 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(header .. 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