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: | ||
-- | --[[ | ||
* Name: SemanticCategoryHelpers | |||
* Author: Mark W. Datysgeld | |||
* Description: Utilities for semantic property and category handling in templates, extracted from TemplateHelpers for improved modularity | |||
* 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 | |||
]] | |||
local p = {} | local p = {} | ||
| Line 122: | Line 116: | ||
p.SEMICOLON_PATTERN = {{pattern = ";%s*", replacement = ";"}} | p.SEMICOLON_PATTERN = {{pattern = ";%s*", replacement = ";"}} | ||
-- 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 = | 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 | return TemplateHelpers.splitMultiValueString(regionValue) | ||
end | end | ||
| Line 289: | Line 277: | ||
else | else | ||
-- Default to splitting the string | -- Default to splitting the string | ||
items = | 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 = | 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 = | 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) | ||