Module:LuaTemplateBlueprint: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Manual revert
// via Wikitext Extension for VSCode
Line 875: Line 875:
      
      
     return transformedValue or ''
     return transformedValue or ''
end
-- Validate property value to prevent SMW parser issues
-- @param value string The value to validate
-- @param property string The property name (for context)
-- @return string The validated value
local function validatePropertyValue(value, property)
    if not value or value == '' then
        return ''
    end
   
    -- Convert to string if needed
    value = tostring(value)
   
    -- Remove potentially problematic wiki markup
    value = value:gsub('{{.-}}', '')  -- Remove template calls
    value = value:gsub('%[%[Category:.-]]', '')  -- Remove categories
   
    -- Escape pipe characters that might break SMW
    value = value:gsub('|', '{{!}}')
   
    return value
end
-- Property deduplication helper
-- Maintains a signature-based deduplication system
-- @param collector table The collector object with seen and properties tables
-- @param property string The property name
-- @param value string The property value
local function deduplicateProperty(collector, property, value)
    if not value or value == '' then return end
   
    -- Validate the value first
    value = validatePropertyValue(value, property)
    if value == '' then return end
   
    -- Create signature for this property-value pair
    local signature = property .. ":" .. tostring(value)
   
    -- Initialize collector structure if needed
    collector.seen = collector.seen or {}
    collector.properties = collector.properties or {}
    collector.count = collector.count or 0
   
    -- Skip if we've seen this exact property-value pair
    if collector.seen[signature] then return end
   
    -- Mark as seen
    collector.seen[signature] = true
    collector.count = collector.count + 1
   
    -- Add to properties
    if not collector.properties[property] then
        collector.properties[property] = value
    else
        -- Convert to array if needed
        if type(collector.properties[property]) ~= "table" then
            collector.properties[property] = {collector.properties[property]}
        end
        -- Add unique value
        table.insert(collector.properties[property], value)
    end
end
end


Line 902: Line 964:
     }
     }
      
      
     -- Collect all properties in a single batch for complete deduplication
     -- Create collector with early deduplication
     local allProperties = {}
     local collector = {
        seen = {},        -- Track property:value signatures
        properties = {},  -- Final deduplicated properties
        count = 0        -- Track total property count
    }
      
      
     -- Add basic properties with transforms handled by SemanticAnnotations
     -- Process basic properties with early deduplication
     for property, param in pairs(properties) do
     for property, param in pairs(properties) do
         -- Perform case-insensitive lookup for the parameter key
         if not skipProperties[property] then
        local keyName, _ = TemplateHelpers.getFieldValue(args, { key = param })
            -- Perform case-insensitive lookup for the parameter key
        allProperties[property] = keyName or param
            local keyName, value = TemplateHelpers.getFieldValue(args, { key = param })
            if value and value ~= '' then
                -- Apply transform if needed
                if transforms[property] then
                    value = applyTransform(value, property, transforms[property], args, template)
                end
                deduplicateProperty(collector, property, value)
            end
        end
     end
     end