Semantic MediaWikiDit bericht verdwijnt nadat alle relevante taken zijn afgerond.

Er is één onvoltooide of openstaande taak, die nodig is om het bijwerken van Semantic MediaWiki te voltooien. Een beheerder of gebruiker met voldoende rechten kan deze uitvoeren. Dit moet worden gedaan voordat nieuwe gegevens worden toegevoegd om tegenstrijdigheden te voorkomen.

Geen bewerkingssamenvatting
Geen bewerkingssamenvatting
Regel 21: Regel 21:


-- fuzzysep (need a better name) lets you use a series of single characters (OR not AND)
-- fuzzysep (need a better name) lets you use a series of single characters (OR not AND)
--[[
local fuzzy = frame.args.fuzzysep or mw.text.trim(frame.args[6]) or "false"
local fuzzy = frame.args.fuzzysep or mw.text.trim(frame.args[6]) or "false"
--[[
if fuzzy == "true" then
if fuzzy == "true" then
local sepPattern = '[^' .. sep .. ')+'
local sepPattern = '[^' .. sep .. ')+'

Versie van 5 sep 2023 19:49

Module:Arraymap

Summary
Module similar in functionality to PageForms's arraymap.


==Simple==
{{#invoke:Arraymap |map 
|vals=Álvar,Núñez ,, Cabeza,de Vaca,,|sep=,,
|varstr=xxx |map=(xxx) |outputsep=;\s
}}

[Álvar,Núñez]; [Cabeza, de Vaca]; []

Or, using unnamed, sequential approach:

{{#invoke:Arraymap |map |Álvar,Núñez ,, Cabeza, de Vaca,, |, |xxx |[xxx] |;\s}}

[Álvar]; [Núñez]; []; [Cabeza]; [de Vaca]; []; []

Special use cases

If sep needs to be a space, use %s?

Escaped syntax for curly braces and pipes

Escape {{... }} as %{%{ ...  %}%}
Escape | as %

{{#invoke:Arraymap |map
|vals=Persoon/-1002367743,Persoon/400
|sep=,
|varstr=xxx
|map=%{%{#ask: [[xxx]] %mainlabel=- %?Has name= %}%} 
|outputsep=;\s
|escaped=true
|fuzzy=false
}}
%{%{#ask: Nelly Kruize %mainlabel=- %?Has name= %}%}; %{%{#ask: Ralph Blum %mainlabel=- %?Has name= %}%}

--[[
{{#invoke:Arraymap
|vals=
|sep=
|varstr=
|map=
|outputsep=
}}

]]--

local p = {}

p.map = function(frame)
	local vals = frame.args.vals or mw.text.trim(frame.args[1]) or ""
	local sep = frame.args.sep or mw.text.trim(frame.args[2]) or ","
	local varstr = frame.args.varstr or mw.text.trim(frame.args[3]) or "@@@"
	local map = frame.args.map or mw.text.trim(frame.args[4]) or ""
	local outputsep = frame.args.outputsep or mw.text.trim(frame.args[5]) or ""
	local outputsep = string.gsub( outputsep, [[\s]], " " ) --allow for spaces with \s

	-- fuzzysep (need a better name) lets you use a series of single characters (OR not AND)
	--[[
	local fuzzy = frame.args.fuzzysep or mw.text.trim(frame.args[6]) or "false"
	if fuzzy == "true" then
		local sepPattern = '[^' .. sep .. ')+'
		local valTable = {}
		for val in string.gmatch( vals, sepPattern ) do
			-- replace varstr in map with val
			local val = mw.text.trim( val )
			local newVal = string.gsub( map, varstr, val )
			table.insert( valTable, newVal )
		end
		local newVals = table.concat( valTable, outputsep )
		return newVals
	end
	--]]
	
	--Standard approach
	local valTable = {}
	local valTable = mw.text.split( vals, sep )
	local mappedTable = {}
	for k,v in pairs(valTable) do
		local v = mw.text.trim( v )
		local newVal = string.gsub( map, varstr, v )
		table.insert( mappedTable, newVal )
	end
	
	local newVals = table.concat( mappedTable, outputsep )
	return newVals
	
end

return p