Jump to content

Module:Taxonbar/candidate: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Ignore 'group of organisms known by one particular common name' d:Q55983715 & 'property' d:Q937228
Keep track of good & bad
Line 10: Line 10:
local currentItem = nil
local currentItem = nil
local categories = {
local categories = {
'[[Category:Taxobox articles possibly missing a taxonbar]]' --unset if acceptable found
'[[Category:Taxobox articles possibly missing a taxonbar]]' --unset if acceptable or unacceptable found
}
}
Line 49: Line 49:
['Q937228'] = 'property',
['Q937228'] = 'property',
}
}
local acceptableCount = 0
local unacceptableCount = 0
for _, instanceOfState in pairs ( currentItem:getBestStatements('P31') ) do --instance of
for _, instanceOfState in pairs ( currentItem:getBestStatements('P31') ) do --instance of
local instanceOf = instanceOfState.mainsnak.datavalue.value.id
local instanceOf = instanceOfState.mainsnak.datavalue.value.id
if acceptableInstanceOf_All[instanceOf] then
if acceptableInstanceOf_All[instanceOf] then
acceptableCount = acceptableCount + 1
categories[1] = ''
elseif unacceptableInstanceOf[instanceOf] then
categories[2] = '[[Category:Taxobox articles missing a taxonbar]]'
unacceptableCount = unacceptableCount + 1
break
end
if unacceptableInstanceOf[instanceOf] then
return ''
end
end
end
end
if acceptableCount > 0 then
categories[1] = ''
categories[2] = '[[Category:Taxobox articles missing a taxonbar]]'
elseif unacceptableCount > 0 then
categories[1] = ''
categories[2] = ''
end
return table.concat(categories)
return table.concat(categories)
else
else
return ''
return ''

Revision as of 02:20, 5 September 2019

local p = {}

function p.check(frame)
	local taxonbarExists = require('Module:Taxonbar/exists').check
	if taxonbarExists(frame) then
		return ''
	else
		local resolveEntity = require( 'Module:ResolveEntityId' )
		local currentTitle = mw.title.getCurrentTitle()
		local currentItem = nil
		local categories = {
			'[[Category:Taxobox articles possibly missing a taxonbar]]' --unset if acceptable or unacceptable found
		}
		
		--preliminary exclusion criteria
		if string.match( currentTitle.text, '^List of ') then
			return ''
		end
		
		--find Wikidata item
		if currentTitle.namespace == 0 then --mainspace
			local currentEntityId = mw.wikibase.getEntityIdForCurrentPage()
			if resolveEntity._id(currentEntityId) then
				currentItem = mw.wikibase.getEntity(currentEntityId)
			else --currentEntityId == nil/unresolvable
				return categories[1]
			end
		else
			return ''
		end
		
		if currentItem then --currentItem should not be nil here, but check just in case
			--determine if {{Taxonbar}} is *possibly* missing, or *definitely* missing
			local 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 = {
				['Q55983715'] = 'group of organisms known by one particular common name',
				['Q937228'] = 'property',
			}
			
			local acceptableCount = 0
			local unacceptableCount = 0
			for _, instanceOfState in pairs ( currentItem:getBestStatements('P31') ) do --instance of
				local instanceOf = instanceOfState.mainsnak.datavalue.value.id
				if acceptableInstanceOf_All[instanceOf] then
					acceptableCount = acceptableCount + 1
				elseif unacceptableInstanceOf[instanceOf] then
					unacceptableCount = unacceptableCount + 1
				end
			end
			
			if acceptableCount > 0 then
				categories[1] = ''
				categories[2] = '[[Category:Taxobox articles missing a taxonbar]]'
			elseif unacceptableCount > 0 then
				categories[1] = ''
				categories[2] = ''
			end
			
			return table.concat(categories)
			
		else
			return ''
		end
	end
end

return p