Module:CanonicalForms: Difference between revisions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
-- | --[[ | ||
* Name: CanonicalForms | |||
* Author: Mark W. Datysgeld | |||
* Description: Text normalization utility that removes wiki markup and maps user input to canonical values using configurable lookup tables | |||
* Notes: Example usage: local mapping = { { canonical = "gTLD", synonyms = {"generic", "g"} }, { canonical = "ccTLD", synonyms = {"country", "cc"} } }; local canonical, css, category = require('Module:CanonicalForms').normalize(inputString, mapping) | |||
]] | |||
local CanonicalForms = {} | local CanonicalForms = {} | ||
-- Normalize an input string | |||
-- Removes wiki markup, converts to lowercase, and maps to canonical form | -- Removes wiki markup, converts to lowercase, and maps to canonical form | ||
function CanonicalForms.normalize(input, mappingTable) | function CanonicalForms.normalize(input, mappingTable) | ||
if not input or input == "" then | if not input or input == "" then | ||
| Line 30: | Line 15: | ||
end | end | ||
-- Remove wiki | -- Remove wiki internal link markup (e.g., "[[Brand TLD]]" → "Brand TLD") | ||
local cleanInput = input:gsub("%[%[([^|%]]+)|?[^%]]*%]%]", "%1"):lower() | local cleanInput = input:gsub("%[%[([^|%]]+)|?[^%]]*%]%]", "%1"):lower() | ||