require('strict')
local p = local templateArgs = --local info = ----------------------------------AUTOMATIC TAXONOMY (module and wikidata versions) -----------function p.addModuleTaxonomy(frame, taxoboxTable, templateArgs) -- use invoke of module function
local moduleData = require("Module:Sandbox/trappist the monk/taxonomy") local tree_t = ; local taxon = templateArgs['taxon'] or templateArgs['parent'] tree_t = moduleData._crawl_tree(taxon, tree_t) --local output = '\n|-\n|' .. table.concat (tree_t, '
') -- dump the whole table local output = for k,v in pairs (tree_t) do local parts = mw.text.split(v, ": ", true) if string.sub(parts[1],1,3)
Ancestral taxa taken from Wikidata.
Bold taxa show those that will be displayed in taxobox.
-\n | ' .. comment -- outer table .. '\n
| ' -- cell for automated taxonomy table .. automatedTaxonomyList .. '\n |
function p.addWikidataTaxonomy(frame, taxoboxTable, args) -- use invoke of module function templateArgs = args return p._addWikidataTaxonomy(frame) endfunction p._addWikidataTaxonomy(frame) -- use invoke of module function local qid local taxon = templateArgs['taxon'] or templateArgs['parent'] -- parent set for species and subspeciesbox if templateArgs['qid'] then qid = templateArgs['qid'] -- get qid from parameter else qid = mw.wikibase.getEntityIdForTitle (taxon) -- get qid from Wikipedia page on taxon end if not qid then return "The taxon name must be the Wikipedia page title. Alternatively provide the Wikidata qid (qid=)." end local rows = "" local row = "| rank || taxon" local count = 0 while qid and count < 100 do local taxonInfo = p.getTaxonInfo(qid) if not taxonInfo.rank then taxonInfo.rank = "unranked" end if not taxonInfo.taxon then taxonInfo.taxon = "no taxon name" end if p.showTaxonRow(taxonInfo.rank, taxonInfo.taxon, count) then -- display required rows local link = "" local italics = "" if taxonInfo.rank
return rowsendlocal majorRanks = function p.showTaxonRow(rank, taxon, count) local majorRank = false for k, v in pairs(majorRanks) do if rank
if count < (tonumber(templateArgs['display_parents']) or 2) then return true end if templateArgs['display_parents']
mw.text.trim(v) then return true end end end return falseendfunction p.getTaxonInfo(qid)
--local rank, taxon, parent local taxonInfo =
-- local statements = mw.wikibase.getBestStatements(qid, 'P105')[1] --taxon rank if statements and statements.mainsnak and statements.mainsnak.datavalue then taxonInfo.rank = mw.wikibase.getLabel(statements.mainsnak.datavalue.value.id) end local statements = mw.wikibase.getBestStatements(qid, 'P225')[1] -- taxon name if statements and statements.mainsnak and statements.mainsnak.datavalue then taxonInfo.taxon = statements.mainsnak.datavalue.value end
local statements = mw.wikibase.getBestStatements(qid, 'P171') -- taxon parent local statement = statements[1] if statement and statement.mainsnak and statement.mainsnak.datavalue then taxonInfo.parent = statement.mainsnak.datavalue.value.id -- use first value end for index, statement in pairs(statements) do local id if statement and statement.mainsnak and statement.mainsnak.datavalue then id = statement.mainsnak.datavalue.value.id end if id then local label = mw.wikibase.getLabel(id) local parentString = label .. " (" .. id .. ")" if taxonInfo.altParents then taxonInfo.altParents = taxonInfo.altParents .. "
" .. parentString else taxonInfo.altParents = parentString end local selectParent = templateArgs['select_parent'] or "1" -- template parameters read as strings if selectParent
"last" then taxonInfo.parent = id end end end local label = mw.wikibase.getLabel(qid) if label then taxonInfo.label = label end local siteLink = mw.wikibase.getSitelink(qid) if siteLink then taxonInfo.siteLink = siteLink end return taxonInfo --rank, taxon, parent
endfunction p.firstToUpper(str) return (str:gsub("^%l", string.upper))end
return p