Module:Is instance

local p = {}; require('Module:No globals')

function p.main(frame) local args = frame.args local pargs = frame:getParent.args local qid = args.qid or pargs.qid local value = args.value or pargs.value return p.checkitem(qid,value) end

function p.checkitem(qid,value) local instances = mw.wikibase.getBestStatements( qid, "P31" ) local isInstance = false for i,statement in ipairs(instances) do		if statement.mainsnak.datavalue.value.id == value then isInstance = true break end end if not isInstance then for i,statement in ipairs(instances) do			if p.checksubclass(statement.mainsnak.datavalue.value.id,value) then isInstance = true break end end end return isInstance end

function p.checksubclass(qid,value) local subclasses = mw.wikibase.getBestStatements( qid, "P279" ) local isInstance = false for i,statement in ipairs(subclasses) do		if statement.mainsnak.datavalue.value.id == value then isInstance = true break end end return isInstance end

return p