Jump to content

Module:Taxonbar/whitelist: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
adj args
Simplify & remove all duplication: make table order == display order
Line 7: Line 7:
local listType = frame.args[1]
local listType = frame.args[1]
local documentation = frame.args[2]
local documentation = frame.args[2]
local acceptableInstanceOf_Strict = {
local outList = {}
local acceptableInstanceOf_Strict = { --table order == display order
['Q16521'] = 'taxon',
['Q310890'] = 'monotypic taxon',
'Q16521', --taxon
['Q98961713'] = 'extinct taxon',
'Q310890', --monotypic taxon
'Q47487597', --monotypic fossil taxon
['Q2568288'] = 'ichnotaxon',
'Q2568288', --ichnotaxon
['Q23038290'] = 'fossil taxon',
['Q47487597'] = 'monotypic fossil taxon',
'Q23038290', --fossil taxon
'Q59278506', --ootaxon
['Q58051350'] = 'paraphyletic group', --subclass of taxon
'Q98961713', --extinct taxon
['Q59278506'] = 'ootaxon',
'Q58051350', --paraphyletic group (subclass of taxon)
}
}
local acceptableInstanceOf_Lax = {
local acceptableInstanceOf_Lax = { --table order == display order
['Q42621'] = 'hybrid',
'Q42621', --hybrid
['Q235536'] = 'incertae sedis',
'Q235536', --incertae sedis
['Q713623'] = 'clade',
'Q713623', --clade
['Q848328'] = 'serotype',
'Q848328', --serotype
['Q857968'] = 'candidatus',
'Q857968', --candidatus
['Q17487588'] = 'unavailable combination',
'Q17487588', --unavailable combination
}
}
local acceptableInstanceOf_All = {} --create IFF requested
if listType == 'all' then
if listType == 'strict' then outList = acceptableInstanceOf_Strict
elseif listType == 'lax' then outList = acceptableInstanceOf_Lax
for k, v in pairs( acceptableInstanceOf_Strict ) do
elseif listType == 'all' then --concatenate strict + lax IIF requested
acceptableInstanceOf_All[k] = v
local acceptableInstanceOf_All = {}
local i = 0
for _, v in pairs( acceptableInstanceOf_Strict ) do
i = i + 1
acceptableInstanceOf_All[i] = v
end
end
for k, v in pairs( acceptableInstanceOf_Lax ) do
for _, v in pairs( acceptableInstanceOf_Lax ) do
acceptableInstanceOf_All[k] = v
i = i + 1
acceptableInstanceOf_All[i] = v
end
end
outList = acceptableInstanceOf_All
end
end
if (documentation == nil) or --module-use only; order & format irrelevant
if (documentation == nil) or --module only
(documentation and documentation == '') then
(documentation and documentation == '') then
local out = {} --output Q's as keys for easier searching within Module:Taxonbar
local out = {}
for k, v in pairs( outList ) do
if listType == 'strict' then out = acceptableInstanceOf_Strict
out[v] = k
elseif listType == 'lax' then out = acceptableInstanceOf_Lax
elseif listType == 'all' then out = acceptableInstanceOf_All
end
end
return out
return out
else
local displayOrder_Strict = {
'Q16521', --taxon
'Q310890', --monotypic taxon
'Q47487597', --monotypic fossil taxon
'Q2568288', --ichnotaxon
'Q23038290', --fossil taxon
'Q59278506', --ootaxon
'Q98961713', --extinct taxon
'Q58051350', --paraphyletic group
}
local displayOrder_Lax = {
'Q42621', --hybrid
'Q235536', --incertae sedis
'Q713623', --clade
'Q848328', --serotype
'Q857968', --candidatus
'Q17487588', --unavailable combination
}
local displayOrder_All = {} --create IFF requested
if listType == 'all' then
--concatenate strict + lax display order tables
local i = 0
for _, v in pairs( displayOrder_Strict ) do
i = i + 1
displayOrder_All[i] = v
end
for _, v in pairs( displayOrder_Lax ) do
i = i + 1
displayOrder_All[i] = v
end
end
local outOrder = {}
if listType == 'strict' then outOrder = displayOrder_Strict
elseif listType == 'lax' then outOrder = displayOrder_Lax
elseif listType == 'all' then outOrder = displayOrder_All
end
else --documentation only
local out = ''
local out = ''
for _, q in pairs( outOrder ) do
for _, q in pairs( outList ) do
local Q = frame:expandTemplate{ title = 'Q', args = { q } }
local Q = frame:expandTemplate{ title = 'Q', args = { q } }
out = out..'# '..Q..'\n'
out = out..'# '..Q..'\n'

Revision as of 19:13, 20 August 2023

local p = {}

-- returns any combination of strict/lax/all acceptable instance-of's,
-- either for use inside [[Module:Taxonbar]] or another module,
-- or for use in documentation as an ordered list
function p.whitelist( frame )
	local listType = frame.args[1]
	local documentation = frame.args[2]
	local outList = {}
	local acceptableInstanceOf_Strict = { --table order == display order
		'Q16521',		--taxon
		'Q310890',		--monotypic taxon
		'Q47487597',	--monotypic fossil taxon
		'Q2568288',		--ichnotaxon
		'Q23038290',	--fossil taxon
		'Q59278506',	--ootaxon
		'Q98961713',	--extinct taxon
		'Q58051350',	--paraphyletic group (subclass of taxon)
	}
	local acceptableInstanceOf_Lax = { --table order == display order
		'Q42621',		--hybrid
		'Q235536',		--incertae sedis
		'Q713623',		--clade
		'Q848328',		--serotype
		'Q857968',		--candidatus
		'Q17487588',	--unavailable combination
	}
	
	if listType == 'strict'  then outList = acceptableInstanceOf_Strict
	elseif listType == 'lax' then outList = acceptableInstanceOf_Lax
	elseif listType == 'all' then --concatenate strict + lax IIF requested
		local acceptableInstanceOf_All = {}
		local i = 0
		for _, v in pairs( acceptableInstanceOf_Strict ) do
			i = i + 1
			acceptableInstanceOf_All[i] = v
		end
		for _, v in pairs( acceptableInstanceOf_Lax ) do
			i = i + 1
			acceptableInstanceOf_All[i] = v
		end
		outList = acceptableInstanceOf_All
	end
	
	if (documentation == nil) or --module only
	   (documentation and documentation == '') then
		local out = {} --output Q's as keys for easier searching within Module:Taxonbar
		for k, v in pairs( outList ) do
			out[v] = k
		end
		return out
		
	else --documentation only
		local out = ''
		for _, q in pairs( outList ) do
			local Q = frame:expandTemplate{ title = 'Q', args = { q } }
			out = out..'# '..Q..'\n'
		end
		return out
	end
	
end

return p