query-1a3a2ec8d619dca090d379958cae3b55
help with timing out query and where P373 links to the same page as the Commons sitelink. I come up with: Unique_value Constraint that violate (P373)Commons category I am new to SPARQL so to learn more about it I was experimenting with the following query to count number of category items with
Use at
- https://query.wikidata.org/sparql
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
SELECT (count(DISTINCT ?categoryItem ) as ?total)
WHERE {
# ?article and ?category share the same P373 ("Commons Category")
?articleItem wdt:P373 ?commonsCategory .
?categoryItem wdt:P373 ?commonsCategory .
#FILTER(?categoryItem != ?articleItem)
# ?article is an "article" item and ?category is an "category" item
?category wdt:P31 wd:Q4167836 .
MINUS {?articleItem wdt:P31 wd:Q4167836 } .
# P301 and P910 are set properly
?articleItem wdt:P910 ?categoryItem .
?categoryItem wdt:P301 ?articleItem .
# sitelink to Commons points to the same category as property P373
?commonsSitelink schema:about ?categoryItem .
BIND (REPLACE(REPLACE(REPLACE(SUBSTR(str(?commonsSitelink),47,200), "%20", " ", "i"), "%28", "(", "i"), "%29", ")", "i") AS ?commonslink)
FILTER(STRSTARTS(str(?commonsSitelink), "https://commons.wikimedia.org/wiki/Category"))
FILTER(?commonslink = ?commonsCategory)
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v4("?articleItem")
v6("?category")
v5("?categoryItem"):::projected
v2("?commonsCategory")
v3("?commonsSitelink")
v7("?commonslink")
v7("?total")
c4(["wd:Q4167836"]):::iri
f0[["?commonslink = ?commonsCategory"]]
f0 --> v7
f0 --> v2
f1[["starts-with(str(?commonsSitelink),'https://commons.wikimedia.org/wiki/Category')"]]
f1 --> v3
v4 --"wdt:P373"--> v2
v5 --"wdt:P373"--> v2
v6 --"wdt:P31"--> c4
subgraph minus2["MINUS"]
style minus2 stroke-width:6px,fill:pink,stroke:red;
v4 --"wdt:P31"--> c4
end
v4 --"wdt:P910"--> v5
v5 --"wdt:P301"--> v4
v3 --"schema:about"--> v5
bind3[/"replace(replace(replace(substring(str(?commonsSitelink),'47^^xsd:integer','200^^xsd:integer'),'%20',' ','i'),'%28','(','i'),'%29',')','i')"/]
v3 --o bind3
bind3 --as--o v7
bind5[/"count(?categoryItem)"/]
v5 --o bind5
bind5 --as--o v7