Ugrás a tartalomhoz

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

Innen: MKOE wiki
Új oldal, tartalma: „-- ======================================================================================= -- TaxonokRawData.lua > TaxonokRawDataConvert.lua > Taxonbox2.lua > buildCultivarbox.lua -- ======================================================================================= local p = {} -- Betölti a taxonboxmodult. local TaxonBox = require('Modul:Taxonbox2') -----------------------------------------------------------------------------------------------------------…”
 
Nincs szerkesztési összefoglaló
 
63. sor: 63. sor:
                 taxonName = data.parent
                 taxonName = data.parent
             else
             else
                 -- KULTIVÁR/FAJ FELISMERÉS:  
                 -- KULTIVÁR/FAJ FELISMERÉS:
                 -- Keressük a nemzetséget (első szó) és a többit
                 -- Keressük a nemzetséget (első szó) és a többit
                 local genus_part, rest_part = taxonName:match("^([%a%-]+)%s+(.+)$")
                 local genus_part, rest_part = taxonName:match("^([%a%-]+)%s+(.+)$")
71. sor: 71. sor:
                     if rest_part:match("^['\"].+['\"]") or rest_part:match("^[a-z×]") then
                     if rest_part:match("^['\"].+['\"]") or rest_part:match("^[a-z×]") then
                         local actual_parent = (parentOverride ~= '' and parentOverride) or genus_part
                         local actual_parent = (parentOverride ~= '' and parentOverride) or genus_part
                       
 
                         -- Meghatározzuk a rangot: ha van idézőjel, akkor Kultivár, egyébként Faj
                         -- Meghatározzuk a rangot: ha van idézőjel, akkor Kultivár, egyébként Faj
                         local current_rank = rest_part:match("^['\"].+['\"]") and "Kultivár" or "Faj"
                         local current_rank = rest_part:match("^['\"].+['\"]") and "Kultivár" or "Faj"
                       
 
                         table.insert(hierarchy, { rank = current_rank, name = taxonName })
                         table.insert(hierarchy, { rank = current_rank, name = taxonName })
                         taxonName = actual_parent
                         taxonName = actual_parent

A lap jelenlegi, 2026. március 15., 00:26-kori változata

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

-- =======================================================================================
-- TaxonokRawData.lua > TaxonokRawDataConvert.lua > Taxonbox2.lua > buildCultivarbox.lua
-- =======================================================================================

local p = {}

-- Betölti a taxonboxmodult.
local TaxonBox = require('Modul:Taxonbox2')

----------------------------------------------------------------------------------------------------------------
function p.buildCultivarbox(frame)
    local args = frame:getParent().args

    -- Miért nem elég a sima local cultivarName = args.accepted?
    -- A MediaWiki sablonoknál ha a szerkesztő ezt írja: | accepted = , az a Lua számára egy üres karakterlánc (""), nem pedig "semmi".
    -- A sima args.accepted esetén a programod azt hinné, van ott valami, és megpróbálná formázni az ürességet, ami hibához vezetne.
    -- Ezzel a logikával viszont eléred, hogy ha üres a mező, a program úgy kezelje, mintha ott se lenne (nil).
    local cultivarName   = (args.cultivar   ~= '' and args.cultivar) or nil
    local synonymName    = (args.synonym    ~= '' and args.synonym) or nil
    local hybridName     = (args.hybrid     ~= '' and args.hybrid) or nil
    local parentName1    = (args.parent1    ~= '' and args.parent1) or nil
    local parentName2    = (args.parent2    ~= '' and args.parent2) or nil
    local parentName3    = (args.parent3    ~= '' and args.parent3) or nil
    local parentName4    = (args.parent4    ~= '' and args.parent4) or nil
    local origin         = (args.origin     ~= '' and args.origin) or nil
    local taxonImage     = args.image or ''
    local imageTitle     = args.imageTitle or ''

    -- local synHomoBoo     = false
    -- -- Végignézzük az összes paramétert
    -- for k, v in pairs(args) do
    --     -- 1. Csak a szöveges értékeket nézzük (v)
    --     -- 2. Megtisztítjuk az esetleges szóközöktől és újsoroktól
    --     if type(v) == "string" then
    --         local cleanV = v:match("^%s*(.-)%s*$")
    --         if cleanV == 'synhomo' then
    --             synHomoBoo = true
    --             break
    --         elseif cleanV == 'synhetero' then
    --             synHomoBoo = false
    --             break
    --         end
    --     end
    -- end

    local output = ""
    local clean_formatted_cultivarName = ""
    local clean_plain_cultivarName = ""

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

        while taxonName and taxonName ~= "" and taxonName ~= "nil" do
            local _, cleanNameForLookup = TaxonBox.format_taxon_clean(taxonName)
            local data = TaxonBox[cleanNameForLookup]

            if data then
                table.insert(hierarchy, { rank = data.rank, name = taxonName })
                taxonName = data.parent
            else
                -- KULTIVÁR/FAJ FELISMERÉS:
                -- Keressük a nemzetséget (első szó) és a többit
                local genus_part, rest_part = taxonName:match("^([%a%-]+)%s+(.+)$")

                if genus_part and rest_part then
                    -- Ha a maradék idézőjelben van (kultivár) vagy kisbetűvel kezdődik (faj)
                    if rest_part:match("^['\"].+['\"]") or rest_part:match("^[a-z×]") then
                        local actual_parent = (parentOverride ~= '' and parentOverride) or genus_part

                        -- Meghatározzuk a rangot: ha van idézőjel, akkor Kultivár, egyébként Faj
                        local current_rank = rest_part:match("^['\"].+['\"]") and "Kultivár" or "Faj"

                        table.insert(hierarchy, { rank = current_rank, name = taxonName })
                        taxonName = actual_parent
                    else
                        break -- Nem faj, nem kultivár, és nincs az adatbázisban
                    end
                else
                    break
                end
            end
        end

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

        -- Itt kapja meg a két értéket

        -- "if cultivarName then" blokkon kívűl deklarálva, hogy a többi if blokkban is elérhető legyen
        clean_formatted_cultivarName, clean_plain_cultivarName = TaxonBox.format_taxon_clean(cultivarName)

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

        output = output .. "|-\n"
        output = output .. '! class="suha-svg" colspan="2"|[[Fájl:cv.svg|x160px|link=]]<br>Kultivár, termesztett változat.\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 = TaxonBox.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 -- ide nem biztos, hogy kell a × jel
                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(clean_plain_cultivarName)
            -- local encodedTerm = mw.uri.encode(clean_plain)
            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;">Cultivarbox hiba: Nem található adat a "' .. tostring(synonymName) .. '" taxonhoz.</div>'
        end

        -- 1. Kinyerjük a faji jelzőket (pl. "leucanthum" és "leucantha")
        local _, accEpithetFull = cultivarName: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

            if synHomoBoo then
                synType         = "Nomenklatúrális (homotipikus)"
                synHeteroBoo    = false
            else -- synHomoBoo == false
                synType = "Taxonómiai (heterotipikus)"
                synHeteroBoo = true
            end
        end

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

        -- Folytatjuk az cultivarName 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_cultivarName .. '|' .. clean_formatted_cultivarName .. ']]\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 = TaxonBox.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

    return output
end

----------------------------------------------------------------------------------------------------------------
function p.format_tudomanyos_nev(frame)
    local args = frame:getParent().args
    local names = {
        { val = args.cultivar,   class = "tnb tnb-cv",      class2 = "tns tns-cv",      txt= "kultivár"},
        { val = args.synonym,    class = "tnb tnb-syn",     class2 = "tns tns-syn",     txt= "szinonima név"},
        { val = args.hybrid,     class = "tnb tnb-hyb",     class2 = "tns tns-hyb",     txt= "hibrid név"}
    }

    local 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 .. '">' .. TaxonBox.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 = {
                    cultivar    = arg[1] or "Dracaena 'Sammurai'",
                    synonym     = arg[1] or "Sanseviera 'Sammurai'",
                    -- "synhomo",
                    -- "synhetero",
                    -- image       = "test.jpg",
                    -- imageTitle  = "Teszt kép"
                }
            }
        end
    }

    print("\n--- Cultivarbox GENERÁLT WIKITEXT ---")
    local success, result = pcall(p.buildCultivarbox, 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

-- ==========================================================
-- ONLINE HASZNÁLAT
-- ==========================================================

-- {{Cultivarbox
-- | accepted = Astrophytum coahuilense
-- | synonym = Astrophytum myriostigma var. coahuilense
-- | synhomo v. synhetero
-- | image = test.jpg
-- | imageTitle  = "Teszt kép"
-- }}

return p