Module:SemanticCategoryHelpers: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Manual revert
// via Wikitext Extension for VSCode
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
-- Module:SemanticCategoryHelpers
--[[
-- Provides utilities for semantic property and category handling in templates.
* Name: SemanticCategoryHelpers
-- Extracted from TemplateHelpers to improve modularity and focus.
* Author: Mark W. Datysgeld
--
* Description: Utilities for semantic property and category handling in templates, extracted from TemplateHelpers for improved modularity
-- This module combines semantic property and category utilities that are
* Notes: Splitting multi-value strings; building category tags; adding categories based on canonical mappings; processing multi-value semantic properties; generating semantic properties based on configuration; retrieving property descriptions from property pages; includes property description caching and type registry
-- frequently used together in templates. It provides functions for:
]]
-- * Splitting multi-value strings (e.g., "value1; value2 and value3")
-- * Building category tags from category names
-- * Adding categories based on canonical mappings
-- * Processing multi-value semantic properties with a unified approach
-- * Generating semantic properties based on configuration
-- * Retrieving property descriptions from property pages


local p = {}
local p = {}
Line 122: Line 116:
p.SEMICOLON_PATTERN = {{pattern = ";%s*", replacement = ";"}}
p.SEMICOLON_PATTERN = {{pattern = ";%s*", replacement = ";"}}


-- Generic function to split multi-value strings with various delimiters
-- Returns an array of individual values
-- This is now a wrapper around TemplateHelpers.splitMultiValueString
function p.splitMultiValueString(...)
    return require('Module:TemplateHelpers').splitMultiValueString(...)
end


-- Helper function to check if a field contains multiple values
-- Helper function to check if a field contains multiple values
Line 208: Line 196:
     else
     else
         -- Default to splitting the string
         -- Default to splitting the string
         items = p.splitMultiValueString(value)
         items = TemplateHelpers.splitMultiValueString(value)
     end
     end
      
      
Line 239: Line 227:
-- This is now a wrapper around splitMultiValueString for backward compatibility
-- This is now a wrapper around splitMultiValueString for backward compatibility
function p.splitRegionCategories(regionValue)
function p.splitRegionCategories(regionValue)
     return p.splitMultiValueString(regionValue)
     return TemplateHelpers.splitMultiValueString(regionValue)
end
end


Line 289: Line 277:
     else
     else
         -- Default to splitting the string
         -- Default to splitting the string
         items = p.splitMultiValueString(value)
         items = TemplateHelpers.splitMultiValueString(value)
     end
     end
      
      
Line 400: Line 388:
                 if value and value ~= "" then
                 if value and value ~= "" then
                     -- Split multi-value fields
                     -- Split multi-value fields
                     local values = p.splitMultiValueString(value)
                     local values = TemplateHelpers.splitMultiValueString(value)
                      
                      
                     -- For each value, transform if needed and add to property collection
                     -- For each value, transform if needed and add to property collection
Line 517: Line 505:
                             local transform = semanticConfig.transforms[property]
                             local transform = semanticConfig.transforms[property]
                             if transform and type(transform) == "function" then
                             if transform and type(transform) == "function" then
                                 local items = p.splitMultiValueString(value)
                                 local items = TemplateHelpers.splitMultiValueString(value)
                                 for _, item in ipairs(items) do
                                 for _, item in ipairs(items) do
                                     local transformed = transform(item)
                                     local transformed = transform(item)