模組:Taxobox wikidata
外观

require('Module:No globals')
local p = {} -- functions made public
local l = {}
local gFrame
local rankList = {
regnum = '',
phylum = '',
classis = '',
ordo = '',
familia = '',
genus = '',
subgenus = '',
sectio = '',
species = '',
}
function p.main(frame)
gFrame = frame
local args
if frame.args['direct'] == 'yes' then args = frame.args
else args = frame:getParent().args end
local from = args['from'] or ''
local currName = l.getData({'label', from})
local currTaxonName = l.getData({'property', from, 'P225'})
local currRank = l.getData({'property', 'raw', from, 'P105'})
local colour = ''
l.setRank(currRank, currName, currTaxonName, true)
local parent = l.getData({'property', 'raw', from, 'P171'})
local parentRank = l.getData({'property', 'raw', parent, 'P105'})
local preRank = currRank
local maxStep = 30
local step = 0
while true
do
step = step + 1
local gen = true
if parentRank == (currRank or preRank)
then
break
end
preRank = parentRank
if parentRank == ''
then
gen = false
end
-- 种
if currRank == 'Q7432'
then
-- 总科(Q2136103)、亚目(Q5867959)、系(Q21061732)、亚类(Q30093105)、类(Q30093070)、亚派(Q10861375)、派(Q10861426)、下群(Q4226087)、亚群(Q6541077)、群(Q2981883)、总群(Q6054425)、高群(Q60445775)、下纲(Q2007442)、亚纲(Q5867051)、总纲(Q3504061)、高纲(Q60922428)、下门(Q2361851)、亚门(Q1153785)、下界(Q3150876)、亚界(Q2752679)
if parentRank == ('Q2136103' or 'Q5867959' or 'Q21061732' or 'Q30093105' or 'Q30093070' or 'Q10861375' or 'Q10861426' or 'Q4226087' or 'Q6541077' or 'Q2981883' or 'Q6054425' or 'Q60445775' or 'Q2007442' or 'Q5867051' or 'Q3504061' or 'Q60922428' or 'Q2361851' or 'Q1153785' or 'Q3150876' or 'Q2752679')
then
gen = false
end
end
if gen == true
then
local parentTaxonName = l.getData({'property', parent, 'P225'})
local parentName = l.getData({'label', parent})
l.setRank(parentRank, parentName, parentTaxonName)
if parentTaxonName == 'Animalia'
then
colour = 'rgb(235,235,210)'
end
end
-- 界
if parentRank == 'Q36732' or step > maxStep
then
break
end
parent = l.getData({'property', 'raw', parent, 'P171'})
parentRank = l.getData({'property', 'raw', parent, 'P105'})
end
local res = frame:expandTemplate{ title = 'Taxobox/core', args = {
name = currName,
image = l.getData({'property', 'raw', from, 'P18'}),
image_caption = l.getData({'qualifier', from, 'P18', 'P2096'}),
colour = colour,
regnum = rankList.regnum,
phylum = rankList.phylum,
classis = rankList.classis,
ordo = rankList.ordo,
familia = rankList.familia,
genus = rankList.genus,
subgenus = rankList.subgenus,
sectio = rankList.sectio,
species = rankList.species,
}
}
return res
end
function l.getData(args)
return gFrame:expandTemplate{ title = 'Wikidata', args = args }
end
function l.setRank(qid, article, taxonName, curr)
local link = "[[" .. article .. "]]"
local partialItalics
local normal
if curr == true
then
partialItalics = l.bold(link .. " " .. l.ltalic(taxonName))
normal = l.bold(link .. " " .. taxonName)
else
partialItalics = link .. " " .. l.ltalic(taxonName)
normal = link .. " " .. taxonName
end
if qid == 'Q35409'
then
rankList['familia'] = normal
elseif qid == 'Q7432'
then
rankList['species'] = link .. ' ' .. l.ltalic(string.format("%1.1s", taxonName))
elseif qid == 'Q3181348'
then
rankList['sectio'] = partialItalics
elseif qid == 'Q3238261'
then
rankList['subgenus'] = partialItalics
elseif qid == 'Q34740'
then
rankList['genus'] = partialItalics
elseif qid == 'Q36602'
then
rankList['ordo'] = normal
elseif qid == 'Q37517'
then
rankList['classis'] = normal
elseif qid == 'Q38348'
then
rankList['phylum'] = normal
elseif qid == 'Q36732'
then
rankList['regnum'] = normal
end
end
function l.bold(str)
return "'''" .. str .. "'''"
end
function l.ltalic(str)
return "''" .. str .. "''"
end
return p