Module:Biota infobox/data: Difference between revisions

Created page with "require('strict') local p = {} local templateArgs = {} local info = {} local paramData = require( 'Module:Biota infobox/data' ) -- contains the taxon ranks in order -- call parameter checking independently of taxobox display function p.main(frame) p._getArgs(frame) return info.parameterCategory end -- get parameters for calling function function p.getArgs(frame, args, localinfo) templateArgs = args info = localinfo p._getArgs(frame) end -- get the arguments and..."
 
No edit summary
 
Line 1: Line 1:
require('strict')
local params = {}


local p = {}
--[[ list of aliases
local templateArgs = {}
      - no need to specify spaces for underscore as handled by getArg()
local info = {}
]]
 
params.aliasMap = {
local paramData = require( 'Module:Biota infobox/data' ) -- contains the taxon ranks in order
                    ['fossil_range'] = 'temporal_range', -- switch? taxobox used temporal_range
 
                ['colour_as'] = 'color_as',
-- call parameter checking independently of taxobox display
                ['included'] = 'includes',
function p.main(frame)
                ['included_text'] = 'includes_text',
p._getArgs(frame)
                ['included_ref'] = 'includes_ref',
return info.parameterCategory
                ['excluded'] = 'excludes',
end
                ['excluded_text'] = 'excludes_text',
-- get parameters for calling function
                ['excluded_ref'] = 'excludes_ref',
function p.getArgs(frame, args, localinfo)
                ['varietas'] = 'variety',
templateArgs = args
               
info = localinfo
}
p._getArgs(frame)
--[[ list of valid parameters used by calling templates
end
                        automatictaxobox = params.validAutomatictaxobox,
-- get the arguments and check them in vaious ways
speciesbox      = params.validSpeciesbox,
function p._getArgs(frame)
subspeciesbox    = params.validSubspeciesbox,
local parents = mw.getCurrentFrame():getParent()
    infraspeciesbox  = params.validInfraspecies
    local tempArgs={} -- local copy of arguments that will be checked (empty, aliases, invalid)
NOTE: need to add to params.validList below
   
    -- get copy of parent arguments, aliasing spaces for underscores
for k,v in pairs(parents.args) do
if type (k) == 'string' then            -- no positional parameters
--v = v:match('^%s*(.-)%s*$')      -- include trimming (only needed for positional parameters)
if v and (v ~= "") then            -- check for content
local j = k:gsub( " ", "_")    -- substitute spaces with underscore (aliases)
tempArgs[j]=v                  -- parents.args[k]
end
end
end
-- do we need to check frame args?
for k,v in pairs(frame.args) do
if v and v ~= "" then                  --check for content
tempArgs[k]=v
end
end
 
-- parameters that can be set without a value, e.g. |extinct=
if parents.args['extinct'] and parents.args['extinct'] == "" then templateArgs['extinct'] = "" end
 
if parents.args['auto'] or frame.args['auto'] then
info.auto = parents.args['auto'] or frame.args['auto']  -- keep template parameters seperate from control flow arguments
end
if parents.args['db'] or frame.args['db'] then
info.db = parents.args['db'] or frame.args['db']  -- keep template parameters seperate from control flow arguments
end
    p.preprocessArgs(tempArgs) -- check aliases, check valid parameters for calling template
end
 
function p.preprocessArgs(tempArgs) -- handles aliases ajc validates parameters
info.parameterCategory = ""    -- initialise empty string for tracking categories
p.aliasParams(tempArgs)        -- check parameters for aliases
    p.validateParams(tempArgs)      -- check parameters for invalid parameters (from allowed list)
p._checkParameters(tempArgs)    -- check manual taxon ranks, orphaned parameters and invalid combinations
end
--[[ -------------------------------------------------------------------
    function p.aliasParams(tempArgs)
        -- alias of spaces to underscores handled in getArgs()
        -- uses alias list from the data subpage (param.aliasmap)
        -- e.g. local aliasMap = {  ['fossil_range'] = 'temporal_range', 
                            ['colour_as'] = 'color_as', ... }
]]
]]
function p.aliasParams(tempArgs)


    -- change parameters using alias map
params.validList = {
    for k,v in pairs(paramData.aliasMap) do
automatictaxobox = {
if tempArgs[k] then                -- if templateArgs has parameter with alias name
'taxon', 'edit link', 'edit_link', 'db',
tempArgs[v] = tempArgs[k];     -- create new element with alias' value as key
'temporal_range', 'temporal range', 'fossil_range', 'fossil range',
tempArgs[k] = nil;     -- delete the alias
'oldest fossil', 'oldest_fossil', 'youngest fossil', 'youngest_fossil',
end   
'display parents', 'display_parents', 'authority', 'parent authority', 'parent_authority',
end
'grandparent authority', 'grandparent_authority', 'greatgrandparent authority',
 
'greatgrandparent_authority', 'greatgreatgrandparent authority', 'greatgreatgrandparent_authority',  
    --[[ alias: change parameters using spaces instead of underscores
'name', 'italic name', 'italic_name', 'binomial',
local localArgs = {} -- Note: adding new keys while iterating over a table gives unpredictable results
'color_as', 'colour_as', 'color as', 'colour as',
    for k,v in pairs(templateArgs) do
'status', 'status system', 'status_system', 'status ref', 'status_ref',
      if type(k)=='string' then
'status2', 'status2 system', 'status2_system', 'status2 ref', 'status2_ref',
local j,n = string.gsub(k, " ", "_")              -- substitute spaces
'trend', 'extinct',
if n > 0 then --if j ~= k then      -- if substitution made
'image', 'image_width', 'image width', 'image_upright', 'image upright',
localArgs[j] = v             -- create new key with underscore
'image alt', 'image_alt', 'image caption', 'image_caption', 'image caption align', 'image_caption_align',
    localArgs[k] = nil;     -- delete old key with space
'image2', 'image2 width', 'image2_width', 'image2_upright', 'image2 upright',
        else
'image2 alt', 'image2_alt', 'image2 caption', 'image2_caption', 'classification status',
        localArgs[k] = v
'classification_status', 'diversity', 'diversity ref', 'diversity_ref', 'diversity link', 'diversity_link',
        end
'binomial authority', 'binomial_authority', 'trinomial', 'trinomial authority', 'trinomial_authority',
end
'type genus', 'type_genus', 'type genus authority', 'type_genus_authority',
end
'type species', 'type_species', 'type species authority', 'type_species_authority',
    templateArgs = localArgs -- now copy the corrected table
'subdivision', 'subdivision ranks', 'subdivision_ranks',
--templateArgs['debug'] = mw.dumpObject (templateArgs)
'type strain', 'type_strain', 'type strain ref', 'type_strain_ref',
    --]]
'range map', 'range_map', 'range_map_upright', 'range map upright', 'range map width', 'range_map_width',
 
'range map alt', 'range_map_alt', 'range map caption', 'range_map_caption',
end
'binomial2', 'binomial2 authority', 'binomial2_authority',
--[[ -------------------------------------------------------------------------------------------
'range map2', 'range_map2', 'range_map2_upright', 'range map2 upright', 'range map2 width', 'range_map2_width',
function p.validateParams(tempArgs)
'range map2 alt', 'range_map2_alt', 'range map2 caption', 'range_map2_caption',
    - uses list of valid parametere accepted by template (from data subpage)
'binomial3', 'binomial3 authority', 'binomial3_authority',
        params.validList = {
'range map3', 'range_map3', 'range_map3_upright', 'range map3 upright', 'range map3 width', 'range_map3_width',
'range map3 alt', 'range_map3_alt', 'range map3 caption', 'range_map3_caption',
'binomial4', 'binomial4 authority', 'binomial4_authority',
'range map4', 'range_map4', 'range_map4_upright', 'range map4 upright', 'range map4 width', 'range_map4_width',
'range map4 alt', 'range_map4_alt', 'range map4 caption', 'range_map4_caption',
'synonyms ref', 'synonyms_ref', 'synonyms',
},
speciesbox = {
'edit link', 'edit_link', 'db', 'subheader',
'fossil_range', 'fossil range', 'temporal_range', 'temporal range',
'oldest fossil', 'oldest_fossil', 'youngest fossil', 'youngest_fossil',
'parent', 'genus', 'taxon', 'display parents', 'display_parents',
'authority', 'binomial authority', 'binomial_authority', 'subgenus', 'subgenus_authority',
'parent authority', 'parent_authority', 'grandparent authority', 'grandparent_authority',
'greatgrandparent authority', 'greatgrandparent_authority',
'greatgreatgrandparent authority', 'greatgreatgrandparent_authority',
'greatgreatgreatgrandparent authority', 'greatgreatgreatgrandparent_authority',
'greatgreatgreatgreatgrandparent authority', 'greatgreatgreatgreatgrandparent_authority',
'name', 'species', 'italic_title', 'italic title',
'color_as', 'colour_as', 'color as', 'colour as',
'status', 'status system', 'status_system', 'status ref', 'status_ref',
'status2', 'status2 system', 'status2_system', 'status2 ref', 'status2_ref',
'status3', 'status3 system', 'status3_system', 'status3 ref', 'status3_ref',
'trend',
'image', 'image_upright', 'image upright', 'image_width', 'image width',
'image alt', 'image_alt', 'image caption', 'image_caption', 'image caption align', 'image_caption_align',
'image2', 'image2_upright', 'image2 upright', 'image2 width', 'image2_width',
'image2 alt', 'image2_alt', 'image2 caption', 'image2_caption',
'classification status', 'classification_status',
'diversity', 'diversity ref', 'diversity_ref', 'diversity link', 'diversity_link',
'extinct',
'trinomial', 'trinomial authority', 'trinomial_authority',
'subdivision', 'subdivision ranks', 'subdivision_ranks',  
'type strain', 'type_strain', 'type strain ref', 'type_strain_ref',
'range map', 'range_map', 'range_map_upright', 'range map upright', 'range map width', 'range_map_width',
'range map alt', 'range_map_alt', 'range map caption', 'range_map_caption',
'binomial2', 'binomial2 authority', 'binomial2_authority',
'range map2', 'range_map2', 'range_map2_upright', 'range map2 upright', 'range map2 width', 'range_map2_width',
'range map2 alt', 'range_map2_alt', 'range map2 caption', 'range_map2_caption',
'binomial3', 'binomial3 authority', 'binomial3_authority',
'range map3', 'range_map3', 'range_map3_upright', 'range map3 upright', 'range map3 width', 'range_map3_width',
'range map3 alt', 'range_map3_alt', 'range map3 caption', 'range_map3_caption',
'binomial4', 'binomial4 authority', 'binomial4_authority',
'range map4', 'range_map4', 'range_map4_upright', 'range map4 upright', 'range map4 width', 'range_map4_width',
'range map4 alt', 'range_map4_alt', 'range map4 caption', 'range_map4_caption',
'synonyms ref', 'synonyms_ref', 'synonyms',
'infraspecies_rank1', 'infraspecies_rank1_name', 'infraspecies_rank1_abbrev',
'infraspecies_rank2', 'infraspecies_rank2_name', 'infraspecies_rank2_abbrev',
'population',
},
subspeciesbox = {
'edit link', 'edit_link', 'db', 'subheader',
'fossil_range', 'fossil range', 'temporal_range', 'temporal range',
'oldest fossil', 'oldest_fossil', 'youngest fossil', 'youngest_fossil',
'genus',
'display parents', 'display_parents', 'parent_authority', 'parent authority',
'binomial authority', 'binomial_authority',
'subgenus', 'subgenus_authority',
'grandparent_authority', 'grandparent authority', 'greatgrandparent authority', 'greatgrandparent_authority',
'greatgreatgrandparent authority', 'greatgreatgrandparent_authority',
'greatgreatgreatgrandparent authority', 'greatgreatgreatgrandparent_authority',
'greatgreatgreatgreatgrandparent authority', 'greatgreatgreatgreatgrandparent_authority',
'species', 'subspecies', 'name',
'color_as', 'colour_as', 'color as', 'colour as',
'status', 'status system', 'status_system', 'status ref', 'status_ref',
'status2', 'status2 system', 'status2_system', 'status2 ref', 'status2_ref',
'trend',
'image', 'image_width', 'image width', 'image_upright', 'image upright',
'image alt', 'image_alt', 'image caption', 'image_caption', 'image caption align', 'image_caption_align',
'image2', 'image2 width', 'image2_width', 'image2_upright', 'image2 upright',
'image2 alt', 'image2_alt', 'image2 caption', 'image2_caption',
'classification status', 'classification_status',
'diversity', 'diversity link', 'diversity_link',
'extinct', 'species extinct', 'species_extinct',
'species link', 'species_link', 'authority', 'subspecies link', 'subspecies_link',
'trinomial authority', 'trinomial_authority',
'subdivision', 'subdivision ranks', 'subdivision_ranks',  
'type strain', 'type_strain', 'type strain ref', 'type_strain_ref',
'range map', 'range_map', 'range_map_upright', 'range map upright', 'range map width', 'range_map_width',
'range map alt', 'range_map_alt', 'range map caption', 'range_map_caption',
'synonyms ref', 'synonyms_ref', 'synonyms',
'infraspecies_rank1', 'infraspecies_rank1_name', 'infraspecies_rank1_abbrev',
'infraspecies_rank2', 'infraspecies_rank2_name', 'infraspecies_rank2_abbrev',
'population', 'population_rank_name', 'population_rank_abbrev',
},
infraspeciesbox = {
'edit link', 'edit_link', 'db',
'fossil_range', 'fossil range', 'temporal_range', 'temporal range',
'oldest fossil', 'oldest_fossil', 'youngest fossil', 'youngest_fossil',
'genus', 'display parents', 'display_parents', 'authority',
'trinomial authority', 'trinomial_authority', 'parent authority', 'parent_authority',
'binomial authority', 'binomial_authority',
'subgenus', 'subgenus_authority',
'grandparent_authority', 'grandparent authority',
'greatgrandparent authority', 'greatgrandparent_authority',
'greatgreatgrandparent authority', 'greatgreatgrandparent_authority',
'greatgreatgreatgrandparent authority', 'greatgreatgreatgrandparent_authority',
'greatgreatgreatgreatgrandparent authority', 'greatgreatgreatgreatgrandparent_authority',
'color_as', 'colour_as', 'color as', 'colour as',
'status', 'status system', 'status_system', 'status ref', 'status_ref',
'status2', 'status2 system', 'status2_system', 'status2 ref', 'status2_ref',
'image', 'image_width', 'image width', 'image_upright', 'image upright',
'image alt', 'image_alt', 'image caption', 'image_caption', 'image caption align', 'image_caption_align',
'image2', 'image2 width', 'image2_width', 'image2_upright', 'image2 upright',
'image2 alt', 'image2_alt', 'image2 caption', 'image2_caption',
'classification status', 'classification_status',
'diversity', 'diversity link', 'diversity_link', 'species_link', 'species link',
'species', 'subspecies', 'variety', 'varietas', 'subspecies_link',
'trinomial', 'name',
'subdivision', 'subdivision ranks', 'subdivision_ranks',
'type strain', 'type_strain', 'type strain ref', 'type_strain_ref',
'range map', 'range_map', 'range_map_upright', 'range map upright', 'range map width', 'range_map_width',
'range map alt', 'range_map_alt', 'range map caption', 'range_map_caption',
'synonyms ref', 'synonyms_ref', 'synonyms',
'infraspecies_rank1', 'infraspecies_rank1_name', 'infraspecies_rank1_abbrev',
'infraspecies_rank2', 'infraspecies_rank2_name', 'infraspecies_rank2_abbrev',
'population',
},
}
-- list of  
params.validList2 = {
automatictaxobox = params.validAutomatictaxobox,
automatictaxobox = params.validAutomatictaxobox,
speciesbox      = params.validSpeciesbox,
speciesbox      = params.validSpeciesbox,
subspeciesbox    = params.validSubspeciesbox,
subspeciesbox    = params.validSubspeciesbox,
    infraspeciesbox  = params.validInfraspeciesbox, }
    infraspeciesbox  = params.validInfraspeciesbox,
    - invalid parameters are retaining in tempArgs
}
 
--[[ list of taxon ranks used by manual taxobox
]]
]]
function p.validateParams(tempArgs)
params.taxonRanks = {
 
        "virus_group",
local validParamsList = paramData.validList[info.auto]
        "unranked_superdomain",
        "superdomain",
    if type(validParamsList) == 'table' then      -- if checklist for valid parameters
        "unranked_domain",
    for k,v in pairs(validParamsList) do
        "domain",
      if tempArgs[v] then                    -- v contains the name of valid parameter key
        "unranked_superregnum",
        templateArgs[v] = tempArgs[v]
        "superregnum",
        tempArgs[v] = nil                  -- delete so only invalid arguments left in tempArgs
        "unranked_regnum",
      end                                    -- TODO use these for tracking categories (partially done)
        "regnum",
    end
        "unranked_subregnum",
   
        "subregnum",
    tempArgs['auto'] = nil                    -- this if not on tracking list but used internally
        "unranked_infraregnum",
    if #tempArgs  then                        -- table  not empty -- if next(tempArgs) ~= nil then
        "infraregnum",
    templateArgs['debug'] =  mw.dumpObject(tempArgs)
        "unranked_superdivisio",
    info.parameterCategory = info.parameterCategory .. "[[Category:Automatic taxobox with unsupported parameters]]"
        "superdivisio",
end
        "unranked_superphylum",
 
        "superphylum",
  else -- checklist for valid parameters not available for this option
        "unranked_divisio",
    for k,v in pairs(tempArgs) do
         "divisio",
    templateArgs[k] = v
        "unranked_phylum",
         end
        "phylum",
end
        "unranked_subdivisio",
        "subdivisio",
        "unranked_subphylum",
    --DISABLE the parameter checking is currently being call from the template (this is temporary)
        "subphylum",
    -- this function checks for bad combinations (e.g. genus without species)
        "unranked_infraphylum",
    --info.parameterCategory = p._checkParameters(frame)
        "infraphylum",
end
        "unranked_microphylum",
 
        "microphylum",
-------------------------------------- CATEGORY FUNCTIONS --------------------------------
        "unranked_nanophylum",
-- function for external invoke
        "nanophylum",
function p.checkParameters(frame)
        "unranked_superclassis",
    p.getArgs(frame) -- populates templateArgs[] with parameters, after alias checking and validation of supported parameters
        "superclassis",
                    -- then calls p._checkParameters for addition parameter checking
        "unranked_classis",
   
        "classis",
    return info.parameterCategory -- return tracking categories
        "unranked_subclassis",
end
        "subclassis",
-- function that checks for extraneous parameters
        "unranked_infraclassis",
function p._checkParameters(tempArgs)
        "infraclassis",
   
        "unranked_subterclassis",
    local categoryString = ""
        "subterclassis",
   
        "unranked_magnordo",
    -- (1) check for speciesbox with taxon and (genus or species)
        "magnordo",
    if info.auto == "speciesbox" then
        "unranked_superordo",
    if templateArgs['taxon'] and (templateArgs['genus'] or templateArgs['species']) then
        "superordo",
    categoryString = categoryString .. "[[Category:Speciesboxes using taxon with genus or species parameters]]"
        "unranked_ordo",
    end
        "ordo",
    end
        "unranked_subordo",
   
        "subordo",
    -- (2) check for manual taxobox parameters
        "unranked_infraordo",
for k,v in pairs(paramData.taxonRanks) do --run through manual taxobox parameter list
        "infraordo",
        "unranked_parvordo",
if v == 'genus' then break end -- don't check at genus and below
        "parvordo",
        "unranked_zoodivisio",
if tempArgs[v] then -- use tempArgs as these won't have been validated (produces redundant category?)
        "zoodivisio",
  categoryString = categoryString .. "[[Category:Automatic taxoboxes using manual rank parameters]]"
        "unranked_zoosectio",
end
        "zoosectio",
end
        "unranked_zoosubsectio",
        "zoosubsectio",
local orphan = false
        "unranked_superfamilia",
local dependentParams = {
        "superfamilia",
image_caption =  'image',   image_alt = 'image',   image_upright = 'image', image_width = 'image',
        "unranked_familia",
image2_caption =  'image2', image2_alt = 'image2', image2_upright = 'image2', image2_width = 'image2',
        "familia",
range_map_caption = 'range_map', range_map_alt = 'range_map',   range_map_upright = 'range_map', range_map_width = 'range_map',
        "unranked_subfamilia",
range_map2_caption = 'range_map2', range_map2_alt = 'range_map2',   range_map2_upright = 'range_map2', range_map2_width = 'range_map2',
        "subfamilia",
range_map3_caption = 'range_map3', range_map3_alt = 'range_map3',   range_map3_upright = 'range_map3', range_map3_width = 'range_map3',
        "unranked_supertribus",
range_map4_caption = 'range_map4', range_map4_alt = 'range_map4',   range_map4_upright = 'range_map4', range_map4_width = 'range_map4',
        "supertribus",
}
        "unranked_tribus",
for k,v in pairs(dependentParams) do
        "tribus",
    if templateArgs[k] and not templateArgs[v] then orphan = true end
        "unranked_subtribus",
    --templateArgs[k] = nil -- delete orphaned variable
        "subtribus",
end
        "unranked_alliance",
if orphan then
        "alliance",
categoryString = categoryString .. "[[Category:Automatic taxoboxes with orphaned dependent parameters]]"
        "unranked_genus",
end
        "genus",
        "unranked_subgenus",
-- paraphyletic groups using manual taxonomy
        "subgenus",
--categoryString = categoryString .. "[[Category:" .. mw.getCurrentFrame():getParent():getTitle()  .."]]"
        "unranked_sectio",
if mw.getCurrentFrame():getParent():getTitle() == "Template:Paraphyletic group" then
        "sectio",
if info.auto ~= "yes" and info.auto ~= "virus" and info.auto ~= "virusbox" and info.auto ~= "hybridbox"
        "unranked_subsectio",
      and info.auto ~= "speciesbox" and info.auto ~= "subspeciesbox" and info.auto ~= "infraspeciesbox" then
        "subsectio",
categoryString = categoryString .. "[[Category:Paraphyletic group infoboxes with manual taxonomy]]"  
        "unranked_series",
end
        "series",
--categoryString = categoryString .. "[[Category:Paraphyletic group infoboxes]]"
        "unranked_subseries",
 
        "subseries",
end
        "unranked_species_group",
        "species_group",
-- add to category list
        "unranked_species_subgroup",
info.parameterCategory = info.parameterCategory .. categoryString
        "species_subgroup",
        "unranked_species_complex",
--return  categoryString
        "species_complex",
end
        "unranked_species",
        "species",
        "unranked_subspecies",
        "subspecies",
        "variety",
        "forma"
}


return p
return params