Module:Taxonbar/candidate

local p = {}function p.check(frame)local taxonbarExists = require('Module:Taxonbar/exists').checkif taxonbarExists(frame) == true 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 *definitely* missing, *possibly* missing, or not missing at alllocal whitelist = require( 'Module:Taxonbar/whitelist' ).whitelistlocal blacklist = require( 'Module:Taxonbar/blacklist' ).blacklistlocal acceptableInstanceOf_All = whitelist{ args = { 'all' } }local unacceptableInstanceOf = blacklist{ args = {} }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