Ugrás a tartalomhoz

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

Innen: MKOE wiki
Nincs szerkesztési összefoglaló
Nincs szerkesztési összefoglaló
305. sor: 305. sor:
         local _, synEpithetFull = synonymName:match("^([%a%-]+)%s+([%a%-]+)")
         local _, synEpithetFull = synonymName:match("^([%a%-]+)%s+([%a%-]+)")


         local synType = "taxonómiai (heterotipikus)"  -- Alapértelmezett
         local synType = "Taxonómiai (heterotipikus)"  -- Alapértelmezett
         local synHeteroBoo = true                    -- Alapértelmezett
         local synHeteroBoo = true                    -- Alapértelmezett


316. sor: 316. sor:
             -- 3. Ha a szótövek egyeznek, akkor nomenklatúrális
             -- 3. Ha a szótövek egyeznek, akkor nomenklatúrális
             if accStem == synStem then
             if accStem == synStem then
                 synType        = "nomenklatúrális (homotipikus)"
                 synType        = "Nomenklatúrális (homotipikus)"
                 synHeteroBoo    = false
                 synHeteroBoo    = false
             end
             end
331. sor: 331. sor:
         output = output .. "|-\n"
         output = output .. "|-\n"
         if synHeteroBoo then
         if synHeteroBoo then
             output = output .. '! class="suha-svg" colspan="2"|[[Fájl:syn.svg|x160px|link=]]<br>Ez egy ' .. synType .. ' szinonima név.<br>Az érvényes leírást lásd itt:<br>[[" .. clean_plain_acceptedName .. "|" .. clean_formatted_acceptedName .. "]]\n'
             output = output .. '! class="suha-svg" colspan="2"|[[Fájl:syn.svg|x160px|link=]]<br>' .. synType .. ' szinonima.<br>Az érvényes leírást lásd itt:<br>[[" .. clean_plain_acceptedName .. "|" .. clean_formatted_acceptedName .. "]]\n'
         else
         else
             output = output .. '! class="suha-svg" colspan="2"|[[Fájl:syn.svg|x160px|link=]]<br>Ez egy ' .. synType .. ' szinonima név.\n'
             output = output .. '! class="suha-svg" colspan="2"|[[Fájl:syn.svg|x160px|link=]]<br>' .. synType .. ' szinonima\n'
         end
         end



A lap 2026. február 16., 17:42-kori változata

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

-- ==========================================================
-- TaxonokRawData.lua > TaxonokRawDataConvert.lua > Taxonbox.lua > Sablon:Taxonbox.wiki
-- ==========================================================

local p = {}

-- Betölti a központi adatmodult, amiben a hierarchia szerepel.
local TaxonData = require('Modul:TaxonokData')

-- Segédfüggvény: Kinyeri a nemzetség nevét a fajnévből
local function extract_genus(full_species_name)
    if not full_species_name then return "" end
    local genus_name = full_species_name:match("([^%s]+)")
    return genus_name or ""
end

-- Segédfüggvény: Dőlt betűs taxonnév alapformázása (szükséges a clean funkcióhoz is)
local function format_name(name)
    if not name or name == '' then return "" end
    local formattedName = name

    -- Rangjelzők dőltté tétele (a rangjelző sp., var. stb. álló marad)
    if string.match(name, "subsp%.") or string.match(name, "var%.") or string.match(name, "f%.") then
        local minta = "([%a%-]+)%s+([%a%-]+)%s+([%a%.]+)%s+([%a%-]+)"
        local csere = "''%1 %2'' %3 ''%4''"
        formattedName = string.gsub(name, minta, csere)
    elseif string.match(name, "[%a%-]+%s+[%a%-]+") then
        local minta = "([%a%-]+)%s+([%a%-]+)"
        local csere = "''%1 %2''"
        formattedName = string.gsub(name, minta, csere)
    else
        formattedName = "''" .. name .. "''"
    end
    return formattedName
end

-- Segédfüggvény: Teljes formázás rangokkal és sec. megjegyzésekkel (A FEJLÉCHEZ)
local function format_taxon_full(text, rank)
    if not text or text == "" then return "" end

    local main_part = text
    local sec_part = ""

    -- 1. "sec." rész leválasztása
    local lower_text = text:lower()
    local start_index = lower_text:find("sec%.")

    if start_index then
        local syn_index = lower_text:find("syn%.%s+sec%.")
        if syn_index then start_index = syn_index end
        main_part = text:sub(1, start_index - 1):gsub("%s+$", "")
        sec_part = text:sub(start_index)
    end

    local sec_formatted = (sec_part ~= "") and (' <span class="sec">' .. sec_part .. '</span>') or ""

    -- 2. Automatikus rang-felismerés végződések alapján (ha nincs megadva)
    if not rank or rank == "" then
        local first_word = main_part:match("^([%a%-]+)")
        if first_word then
            if     first_word:match("ales$")   then rank = "Rend"
            elseif first_word:match("aceae$")  then rank = "Család"
            elseif first_word:match("oideae$") then rank = "Alcsalád"
            elseif first_word:match("eae$")    then rank = "Nemzetségcsoport"
            elseif first_word:match("inae$")   then rank = "Alnemzetség-csoport"
            end
        end
    end

    -- 3. Magasabb rangok formázása (csak félkövér, nem dőlt)
    local high_ranks = { ["Rend"]=true, ["Család"]=true, ["Alcsalád"]=true, ["Nemzetségcsoport"]=true, ["Alnemzetség-csoport"]=true }
    if rank and high_ranks[rank] then
        local name, rest = main_part:match("^([%a%-]+)%s*(.*)$")
        return "'''" .. (name or main_part) .. "''' " .. (rest or "") .. sec_formatted
    end

    -- 4. Infraspecifikus taxonok (subsp., var., f.) kezelése
    -- Itt a minta: Genus species rank epithet rest
    local low_ranks = { "subsp%.", "var%.", "f%." }
    for _, r_pattern in ipairs(low_ranks) do
        local g, s, r_found, e, rest = main_part:match("^([%a%-]+)%s+([%a%-]+)%s+("..r_pattern..")%s+([%a%-]+)%s*(.*)$")
        if g then
            return "'''''" .. g .. " " .. s .. "'' " .. r_found .. " ''" .. e .. "''''' " .. (rest or "") .. sec_formatted
        end
    end

    -- 5. Infragenerikus taxonok (sect., ser. stb.) kezelése
    local infra_gen_ranks = { "gen%.", "subgen%.", "sect%.", "subsect%.", "ser%.", "subser%.", "sp%." }
    for _, r_pattern in ipairs(infra_gen_ranks) do
        local g, r_found, e, rest = main_part:match("^([%a%-]+)%s+("..r_pattern..")%s+([%a%-]+)%s*(.*)$")
        if g then
            return "'''''" .. g .. "'' " .. r_found .. " ''" .. e .. "''''' " .. (rest or "") .. sec_formatted
        end
    end

    -- 6. Binomiális név (Faj) vs. Monomiális név (Nemzetség + Szerző)
    -- Logika: Ha a második szó kisbetűvel kezdődik, az faji jelző (species epithet) -> dőlt.
    -- Ha nagybetűvel, zárójellel vagy ponttal kezdődik, az szerző -> nem dőlt.
    local first, second, rest = main_part:match("^([%a%-]+)%s+([^%s]+)%s*(.*)$")

    if first and second then
        -- Ellenőrizzük, hogy a második szó kisbetűvel kezdődik-e
        if second:match("^[a-z]") then
            -- Faj: '''''Genus species'''''
            return "'''''" .. first .. " " .. second .. "''''' " .. (rest or "") .. sec_formatted
        else
            -- Nemzetség + Szerző: '''''Genus''''' Szerző
            return "'''''" .. first .. "''''' " .. second .. " " .. (rest or "") .. sec_formatted
        end
    end

    -- 7. Alapeset (egy szó): '''''Taxon'''''
    local single_name, rest2 = main_part:match("^([%a%-]+)%s*(.*)$")
    return "'''''" .. (single_name or "") .. "''''' " .. (rest2 or "") .. sec_formatted
end

-- Segédfüggvény: Csak a tiszta, dőlt nevet adja vissza sallangok nélkül (A TÁBLÁZATHOZ)
local function format_taxon_clean(text)
    if not text or text == "" then return "", "" end

    -- 1. Sec. rész eltávolítása (megőrizve az eredeti kisbetű-nagybetű formát!)
local raw_clean = text
    local lower_text = text:lower()
    local sec_start = lower_text:find("sec%.")
    if sec_start then
        raw_clean = text:sub(1, sec_start - 1):gsub("%s+$", "")
    end

    -- Speciális eset: Ha a név benne van az adatbázisban úgy, ahogy van (pl. "Core Eudicots")
    -- akkor ne próbáljuk meg szétszedni szerzőre és nemzetségre!
    if TaxonData[raw_clean] then
        return "''" .. raw_clean .. "''", raw_clean
    end

    local formatted = ""
    local plain = ""

    -- 2. Infraspecifikus rangok (subsp., var., f.) kezelése
    local infra_ranks = {"subsp%.", "var%.", "f%."}
    local found = false

    for _, r in ipairs(infra_ranks) do
        -- Minta: Genus species rank epithet
        local g, s, r_found, e = raw_clean:match("^([%a%-]+)%s+([%a%-]+)%s+("..r..")%s+([%a%-]+)")
        if g then
            formatted = "''" .. g .. " " .. s .. "'' " .. r_found .. " ''" .. e .. "''"
            plain = g .. " " .. s .. " " .. r_found .. " " .. e
            found = true
            break
        end
    end

    -- 3. Binomiális (faj) vs. Monomiális (nemzetség + szerző) felismerése
    if not found then
        -- Két szót és a maradékot keressük (nem tesszük kisbetűssé!)
        local first, second = raw_clean:match("^([%a%-]+)%s+([^%s]+)")

        if first and second then
            -- Ha a második szó kisbetűvel kezdődik -> Fajnév
            if second:match("^[a-z]") then
                formatted = "''" .. first .. " " .. second .. "''"
                plain = first .. " " .. second
            else
                -- Ha nagybetűvel vagy zárójellel kezdődik -> Szerző (csak a nemzetség dőlt)
                formatted = "''" .. first .. "''"
                plain = first
            end
        else
            -- Ha csak egy szó (magasabb szint vagy csak genus)
            local single = raw_clean:match("^([%a%-]+)") or raw_clean
            formatted = "''" .. single .. "''"
            plain = single
        end
    end

    -- Két értékkel térünk vissza: 1. Formázott (wikitext), 2. Nyers (linkhez)
    return formatted, plain
end

function p.buildTaxonbox(frame)
    local args = frame:getParent().args

    local acceptedName   = (args.accepted   ~= '' and args.accepted) or nil
    local synonymName    = (args.synonym    ~= '' and args.synonym) or nil
    local unresolvedName = (args.unresolved ~= '' and args.unresolved) or nil
    local hybridName     = (args.hybrid     ~= '' and args.hybrid) or nil
    local parentName     = (args.parent     ~= '' and args.parent) or nil
    local taxonImage     = args.image or ''
    local imageTitle     = args.imageTitle or ''

    local output = ""

    -- if not acceptedName then
    --     return '<div style="color:red;">Taxonbox hiba: Hiányzó taxon név.</div>'
    -- end

    -- acceptedName ----------------------------------
    if acceptedName then
        local hierarchy = {}
        local taxonName = acceptedName
        -- local parentOverride = args.parent
        local parentOverride = parentName

        while taxonName and taxonName ~= "" and taxonName ~= "nil" do
            -- JAVÍTÁS: Mindig a tisztított (sallangmentes) névvel keressünk az adatmodulban
            local _, cleanNameForLookup = format_taxon_clean(taxonName)
            local data = TaxonData[cleanNameForLookup]

            if data then
                table.insert(hierarchy, { rank = data.rank, name = taxonName })
                taxonName = data.parent
            else
                -- Ha nincs az adatbázisban, ellenőrizzük, hogy faj-e
                -- (Csak akkor, ha a második szó kisbetűs)
                local first, second = taxonName:match("^([%a%-]+)%s+([^%s]+)")

                if taxonName == taxonName and first and second and second:match("^[a-z]") then
                    local actual_parent = (parentOverride ~= '' and parentOverride) or extract_genus(taxonName)
                    table.insert(hierarchy, { rank = "Faj", name = taxonName })
                    taxonName = actual_parent
                else
                    -- Ha nem faj és nincs az adatbázisban, megállunk
                    break
                end
            end
        end

        if #hierarchy == 0 then
            return '<div style="color:red;">Taxonbox hiba: Nem található adat a "' .. tostring(acceptedName) .. '" taxonhoz.</div>'
        end

        -- Itt kapja meg a két értéket
        local clean_formatted_acceptedName, clean_plain_acceptedName = format_taxon_clean(acceptedName)

        output = output ..'{| class="infobox biota acc"\n'
        output = output .. "|-\n"
        output = output .. '! class="taxonnev" colspan="2" | ' .. clean_formatted_acceptedName .. "\n"

        output = output .. "|-\n"
        output = output .. '! class="suha-svg" colspan="2"|[[Fájl:acc.svg|x160px|link=]]<br>Érvényes, elfogadott név.\n'

        if taxonImage ~= '' then
            output = output .. '|-\n'
            output = output .. '! class="suha-svg" colspan="2"|[[Fájl:' .. taxonImage .. '|340px|' .. imageTitle .. ']]\n'
        end

        output = output .. '|-\n'
        output = output .. '! class="besorolas" colspan="2"|Rendszertani besorolás\n'

        for i = #hierarchy, 1, -1 do
            local item = hierarchy[i]
            local rank_display = item.rank

            -- Itt kapja meg a két értéket
            local clean_formatted, clean_plain = format_taxon_clean(item.name)

            local name_display = ""

            -- Kategória hivatkozás tisztított névvel
            if item.rank == "Faj" then
                name_display = clean_formatted
            else
                -- Megkeressük az alapnevet a kategória linkhez (szerzők nélkül)
                local category_target = item.name:match("^([%a%-%.%s]+)") or item.name
                if item.rank == "Nemzetség" then
                    -- A nemzetség kategória linkhez a clean_formatted változót használjuk
                    name_display = "[[:Kategória:" .. clean_plain .. "|" .. clean_formatted .. "]]"
                else
                    -- A kategória linkhez a plain (formázás mentes) változót használjuk
                    name_display = "[[:Kategória:" .. clean_plain .. "|" .. clean_plain .. "]]"
                end
            end

            if rank_display == "Nemzetségcsoport" then rank_display = "Nemzetség-<br>csoport" end
            if rank_display == "Alnemzetségcsoport" then rank_display = "Alnemzetség-<br>csoport" end

            output = output .. '|-\n'
            output = output .. '| class = "left" | ' .. rank_display .. '\n'
            output = output .. '| class = "right" | ' .. name_display .. '\n'
        end

        if hierarchy[1] and hierarchy[1].rank == "Faj" then
            local encodedTerm = mw.uri.encode(acceptedName)
            output = output .. '|-\n'
            output = output .. '!colspan="2" class="taxobox-icons" |'
            output = output .. '[[Fájl:Google logo gyz.svg|x30px|link=http://images.google.com/search?tbm=isch&q=' .. encodedTerm .. '|Google képek]] '
            output = output .. '[[Fájl:Bing fluent logo gyz.svg|x30px|link=https://www.bing.com/images/search?q=' .. encodedTerm .. '|Bing képek]]\n'
        end

        output = output .. '|}\n'
    end

    -- synonymName ----------------------------------
    if synonymName then
        local syn_hierarchy = {}
        local taxonName2 = synonymName
        table.insert(syn_hierarchy, { rank = "Faj", name = taxonName2 })

        if #syn_hierarchy == 0 then
            return '<div style="color:red;">Taxonbox hiba: Nem található adat a "' .. tostring(synonymName) .. '" taxonhoz.</div>'
        end

        -- 1. Kinyerjük a faji jelzőket (pl. "leucanthum" és "leucantha")
        local _, accEpithetFull = acceptedName:match("^([%a%-]+)%s+([%a%-]+)")
        local _, synEpithetFull = synonymName:match("^([%a%-]+)%s+([%a%-]+)")

        local synType = "Taxonómiai (heterotipikus)"  -- Alapértelmezett
        local synHeteroBoo = true                     -- Alapértelmezett

        if accEpithetFull and synEpithetFull then
            -- 2. Levágjuk a végződéseket (szótő kinyerése: pl. "leucanth")
            -- A minta levágja az -um, -a, -us, -is végződéseket
            local accStem = accEpithetFull:gsub("[uais][ms%a]*$", "")
            local synStem = synEpithetFull:gsub("[uais][ms%a]*$", "")

            -- 3. Ha a szótövek egyeznek, akkor nomenklatúrális
            if accStem == synStem then
                synType         = "Nomenklatúrális (homotipikus)"
                synHeteroBoo    = false
            end
        end

        -- Itt kapja meg a két értéket
        local clean_formatted_synonymName, clean_plain_synonymName = format_taxon_clean(synonymName)

        -- Folytatjuk az acceptedName output-ot
        output = output .. '{| class="infobox biota syn"\n'
        output = output .. "|-\n"
        output = output .. '! class="taxonnev" colspan="2" | ' .. clean_formatted_synonymName .. "\n"

        output = output .. "|-\n"
        if synHeteroBoo then
            output = output .. '! class="suha-svg" colspan="2"|[[Fájl:syn.svg|x160px|link=]]<br>' .. synType .. ' szinonima.<br>Az érvényes leírást lásd itt:<br>[[" .. clean_plain_acceptedName .. "|" .. clean_formatted_acceptedName .. "]]\n'
        else
            output = output .. '! class="suha-svg" colspan="2"|[[Fájl:syn.svg|x160px|link=]]<br>' .. synType .. ' szinonima\n'
        end

        output = output .. '|-\n'
        output = output .. '! class="besorolas" colspan="2"|Rendszertani besorolás\n'

        for i = #syn_hierarchy, 1, -1 do
            local item = syn_hierarchy[i]
            local rank_display = item.rank

            -- Itt kapja meg a két értéket
            local clean_formatted, clean_plain = format_taxon_clean(item.name)

            local name_display = ""

            -- Kategória hivatkozás tisztított névvel
            if item.rank == "Faj" then
                name_display = clean_formatted
                output = output .. '|-\n'
                output = output .. '| class = "left" | ' .. rank_display .. '\n'
                output = output .. '| class = "right" | ' .. name_display .. '\n'
            end
        end

        -- if syn_hierarchy[1] and syn_hierarchy[1].rank == "Faj" then
        --     local encodedTerm = mw.uri.encode(synonymName)
        --     output = output .. '|-\n'
        --     output = output .. '!colspan="2" class="taxobox-icons" |'
        --     output = output .. '[[Fájl:Google logo gyz.svg|x30px|link=http://images.google.com/search?tbm=isch&q=' .. encodedTerm .. '|Google képek]] '
        --     output = output .. '[[Fájl:Bing fluent logo gyz.svg|x30px|link=https://www.bing.com/images/search?q=' .. encodedTerm .. '|Bing képek]]\n'
        -- end

        output = output .. '|}\n'
    end

    -- unresolvedName ----------------------------------
    if unresolvedName then
        local unres_hierarchy = {}
        local taxonName3 = unresolvedName
        table.insert(unres_hierarchy, { rank = "Faj", name = taxonName3 })

        if #unres_hierarchy == 0 then
            return '<div style="color:red;">Taxonbox hiba: Nem található adat a "' .. tostring(unresolvedName) .. '" taxonhoz.</div>'
        end

        -- Itt kapja meg a két értéket
        local clean_formatted_unresolvedName, clean_plain_unresolvedName = format_taxon_clean(unresolvedName)

        -- Folytatjuk az acceptedName output-ot
        output = output .. '{| class="infobox biota unres"\n'
        output = output .. "|-\n"
        output = output .. '! class="taxonnev" colspan="2" | ' .. clean_formatted_unresolvedName .. "\n"

        output = output .. "|-\n"
        output = output .. '! class="suha-svg" colspan="2"|[[Fájl:unres.svg|x160px|link=]]<br>Feloldatlan név\n'

        output = output .. '|-\n'
        output = output .. '! class="besorolas" colspan="2"|Rendszertani besorolás\n'

        for i = #unres_hierarchy, 1, -1 do
            local item = unres_hierarchy[i]
            local rank_display = item.rank

            -- Itt kapja meg a két értéket
            local clean_formatted, clean_plain = format_taxon_clean(item.name)

            local name_display = ""

            -- Kategória hivatkozás tisztított névvel
            if item.rank == "Faj" then
                name_display = clean_formatted
                output = output .. '|-\n'
                output = output .. '| class = "left" | ' .. rank_display .. '\n'
                output = output .. '| class = "right" | ' .. name_display .. '\n'
            end
        end

        if unres_hierarchy[1] and unres_hierarchy[1].rank == "Faj" then
            local encodedTerm = mw.uri.encode(unresolvedName)
            output = output .. '|-\n'
            output = output .. '!colspan="2" class="taxobox-icons" |'
            output = output .. '[[Fájl:Google logo gyz.svg|x30px|link=http://images.google.com/search?tbm=isch&q=' .. encodedTerm .. '|Google képek]] '
            output = output .. '[[Fájl:Bing fluent logo gyz.svg|x30px|link=https://www.bing.com/images/search?q=' .. encodedTerm .. '|Bing képek]]\n'
        end

        output = output .. '|}\n'
    end
    return output
end

function p.format_tudomanyos_nev(frame)
    local args = frame:getParent().args
    local names = {
        { val = args.accepted,   class = "tnb tnb-acc",     class2 = "tns tns-acc",     txt= "elfogadott, érvényes név"},
        { val = args.synonym,    class = "tnb tnb-syn",     class2 = "tns tns-syn",     txt= "szinonima név"},
        { val = args.unresolved, class = "tnb tnb-unres",   class2 = "tns tns-unres",   txt= "feloldatlan név"},
        { val = args.hybrid,     class = "tnb tnb-hyb",     class2 = "tns tns-hyb",     txt= "hibrid név"}
    }

    output = '== Tudományos név ==\n'
    output = output .. '<div class="tn">\n'
    for _, n in ipairs(names) do
        if n.val and n.val ~= '' then
            output = output .. '* <span class="' .. n.class .. '">' .. format_taxon_full(n.val) .. '</span><br><span class="' .. n.class2 .. '">' .. (n.txt) .. '</span>\n'
        end
    end
    output = output .. '</div>\n'
    return output
end

-- ==========================================================
-- OFFLINE TESZTELŐ SZAKASZ
-- ==========================================================
if arg then
    mw = { uri = { encode = function(s) return s:gsub(" ", "%%20") end } }
    local mock_frame = {
        getParent = function()
            return {
                args = {
                    -- accepted    = arg[1] or "Acanthocalycium leucanthum (Gillies ex Salm-Dyck) Schlumpb. in Cactaceae Syst. Init. 28: 29. 2012. Sec. Schlumpberger (2012)",
                    -- synonym     = arg[2] or "Echinopsis leucantha (Gillies ex Salm-Dyck) Walp., Repert. Bot. Syst. 2: 324. 1843",
                    unresolved  = arg[3] or "Lobivia kuehhasii Rausch in Kakteen And. Sukk. 60: 320. 2009. Sec. WFO 2019",
                    image       = "test.jpg",
                    imageTitle  = "Teszt kép"
                }
            }
        end
    }

    print("\n--- TAXONBOX GENERÁLT WIKITEXT ---")
    local success, result = pcall(p.buildTaxonbox, mock_frame)
    print(success and result or "HIBA: " .. result)

    print("\n--- TUDOMÁNYOS NÉV SZAKASZ ---")
    local success2, result2 = pcall(p.format_tudomanyos_nev, mock_frame)
    print(success2 and result2 or "HIBA: " .. result2)
end

return p