How many {category contains} are to/by {library} ?
What type of categories are there in library?
How many categories are at the library?
SELECT ( COUNT ( ?p ) AS ?t ) { ?p property:category_contains resource:library }
SELECT (COUNT(?sub) AS ?subs ) {
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> ?sub .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <http://www.wikidata.org/entity/P4224> .
?statement <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> http://wikidata.dbpedia.org/resource/Q7075 .
} 

SELECT (COUNT(?sub) AS ?value ) { ?sub wdt:P4224 wd:Q7075 }
49