query-beadf548ecfa6ea39eac5a82b1b40e1f
Items where a Commons cat is the only sitelinkCan anyone think of a way to optimise this to within the time-limit? (Or, alternatively, an SQL query to do the same thing?) I've tried a couple of thoughts, but both time out:
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT (COUNT(DISTINCT(?item)) AS ?count)
WHERE {
?sitelink schema:isPartOf <https://commons.wikimedia.org/>.
FILTER (STRSTARTS(str(?sitelink), "https://commons.wikimedia.org/wiki/Category:")) .
?sitelink schema:about ?item .
OPTIONAL {
?sitelink2 schema:about ?item .
FILTER(?sitelink2 != ?sitelink) .
}
FILTER(!bound(?sitelink2))
# SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?count")
v3("?item"):::projected
v2("?sitelink")
v1("?sitelink2")
c3([https://commons.wikimedia.org/]):::iri
f0[["not bound(?sitelink2)"]]
f0 --> v1
f1[["starts-with(str(?sitelink),'https://commons.wikimedia.org/wiki/Category:')"]]
f1 --> v2
v2 --"schema:isPartOf"--> c3
v2 --"schema:about"--> v3
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
v1 -."schema:about".-> v3
end
bind3[/"count(?item)"/]
v3 --o bind3
bind3 --as--o v4