模組:Taxobox wikidata
外观

require('strict')
local l = {}
local gFrame
local rankList = {
regnum = '',
phylum = '',
classis = '',
ordo = '',
familia = '',
genus = '',
subgenus = '',
sectio = '',
species = '',
divisio = ''
}
local binomial = ''
local binomialAuthority = ''
local acceptableRank = {
['Q35409'] = 'familia',
['Q7432'] = 'species',
['Q3181348'] = 'sectio',
['Q3238261'] = 'subgenus',
['Q34740'] = 'genus',
['Q36602'] = 'ordo',
['Q37517'] = 'classis',
['Q38348'] = 'phylum',
['Q36732'] = 'regnum',
['Q334460'] = 'divisio'
}
local p = {}
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, args['authority'] or '')
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 parent == '' or parentRank == currRank or (preRank ~= '' and parentRank == preRank)
then
break
end
if parentRank == ''
then
gen = false
else
-- 种
if currRank == 'Q7432'
then
-- 总科(Q2136103)、亚目(Q5867959)、系(Q21061732)、亚类(Q30093105)、类(Q30093070)、亚派(Q10861375)
-- 派(Q10861426)、下群(Q4226087)、亚群(Q6541077)、群(Q2981883)、总群(Q6054425)、高群(Q60445775)
-- 下纲(Q2007442)、亚纲(Q5867051)、总纲(Q3504061)、高纲(Q60922428)、下门(Q2361851)、亚门(Q1153785)
-- 下界(Q3150876)、亚界(Q2752679)、族(Q227936)、亚科(Q164280)、超门(Q23760204)
--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' or 'Q227936' or 'Q164280' or 'Q23760204')
--then
-- gen = false
--end
end
if l.isNilOrEmpty(acceptableRank[parentRank])
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)'
elseif parentTaxonName == 'Plantae'
then
colour = 'rgb(180,250,180)'
end
end
-- 界
if parentRank == 'Q36732' or step > maxStep
then
break
end
preRank = parentRank
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,
divisio = rankList.divisio,
binomial = binomial,
binomial_authority = binomialAuthority,
status = l.transIUCN(l.getData({'property', 'raw', from, 'P141'})) or '',
status_system = 'iucn3.1',
range_map = l.getData({'property', 'raw', from, 'P181'}),
range_map_caption = l.getData({'qualifier', from, 'P181', 'P2096'}),
synonyms = args['synonyms'] or '',
}
}
return res
end
function l.getData(args)
return gFrame:expandTemplate{ title = 'Wikidata', args = args }
end
function l.setRank(qid, article, taxonName, curr, authority)
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
local displayTaxonName = l.ltalic(string.gsub(taxonName, '([%u])[%l]+ ', '%1. '))
if curr == true
then
rankList['species'] = l.bold(link .. ' ' .. displayTaxonName)
binomial = l.ltalic(taxonName)
binomialAuthority = authority
else
rankList['species'] = link .. ' ' .. displayTaxonName
end
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
elseif qid == 'Q334460'
then
if(rankList['divisio'] ~= '')
then
return
end
rankList['divisio'] = normal
end
end
function l.bold(str)
return "'''" .. str .. "'''"
end
function l.ltalic(str)
return "''" .. str .. "''"
end
function l.transIUCN(qid)
if qid == 'Q3350324'
then
return 'NE'
elseif qid == 'Q3245245'
then
return 'DD'
elseif qid == 'Q211005'
then
return 'LC'
elseif qid == 'Q719675'
then
return 'NT'
elseif qid == 'Q278113'
then
return 'VU'
elseif qid == 'Q11394'
then
return 'EN'
elseif qid == 'Q219127'
then
return 'CR'
elseif qid == 'Q239509'
then
return 'EW'
elseif qid == 'Q123509'
then
return 'EX'
end
end
function l.isNilOrEmpty( thing )
if thing == nil or thing == '' then
return true
end
return nil
end
return p