模組:Taxonbar/candidate

可在模組:Taxonbar/candidate/doc建立此模組的說明文件

local p = {}function p.check(frame)local taxonbarExists = require('Module:Taxonbar/exists').checkif taxonbarExists(frame) thenreturn ''elselocal resolveEntity = require( 'Module:ResolveEntityId' )local currentTitle = mw.title.getCurrentTitle()local currentItem = nillocal categories = {'[[Category:Taxobox articles possibly missing a taxonbar]]' --unset if acceptable or unacceptable found}--preliminary exclusion criteriaif string.match( currentTitle.text, '^List of ') thenreturn ''end--find Wikidata itemif currentTitle.namespace == 0 then --mainspacelocal currentEntityId = mw.wikibase.getEntityIdForCurrentPage()if resolveEntity._id(currentEntityId) thencurrentItem = mw.wikibase.getEntity(currentEntityId)else --currentEntityId == nil/unresolvablereturn categories[1]endelsereturn ''endif currentItem then --currentItem should not be nil here, but check just in case--determine if {{Taxonbar}} is *possibly* missing, or *definitely* missinglocal acceptableInstanceOf_All = { --copied from [[Module:Taxonbar]]['Q16521'] = 'taxon',                      --strict['Q310890'] = 'monotypic taxon',           --strict['Q2568288'] = 'ichnotaxon',               --strict['Q23038290'] = 'fossil taxon',            --strict['Q47487597'] = 'monotypic fossil taxon',  --strict['Q42621'] = 'hybrid',                     --lax['Q235536'] = 'incertae sedis',            --lax['Q713623'] = 'clade',                     --lax['Q848328'] = 'serotype',                  --lax['Q857968'] = 'candidatus',                --lax['Q17487588'] = 'unavailable combination', --lax}local unacceptableInstanceOf = {['Q913170'] = 'trivial name',['Q55983715'] = 'group of organisms known by one particular common name',['Q937228'] = 'property',['Q14712'] = 'drupe',['Q163233'] = 'compound drupe',['Q747463'] = 'compound fruit',}local acceptableCount = 0local unacceptableCount = 0for _, instanceOfState in pairs ( currentItem:getBestStatements('P31') ) do --instance oflocal instanceOf = instanceOfState.mainsnak.datavalue.value.idif acceptableInstanceOf_All[instanceOf] thenacceptableCount = acceptableCount + 1elseif unacceptableInstanceOf[instanceOf] thenunacceptableCount = unacceptableCount + 1endendfor _, subclassOfState in pairs ( currentItem:getBestStatements('P279') ) do --subclass oflocal subclassOf = subclassOfState.mainsnak.datavalue.value.idif acceptableInstanceOf_All[subclassOf] thenacceptableCount = acceptableCount + 1elseif unacceptableInstanceOf[subclassOf] thenunacceptableCount = unacceptableCount + 1endendif acceptableCount > 0 thencategories[1] = ''categories[2] = '[[Category:Taxobox articles missing a taxonbar]]'elseif unacceptableCount > 0 thencategories[1] = ''categories[2] = ''endreturn table.concat(categories)elsereturn ''endendendreturn p