query-2c31df6adb75822b30d9b20582598d53

rq turtle/ttl

Looking for items where there is category saved in sitelink to Commons but we have no P373I was thinking:

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
SELECT ?item ?category WHERE {
  MINUS { ?item wdt:P373 [] } .          # no P373 (commons category)
  MINUS { ?item wdt:P31  wd:Q4167836 . } # not a commons item
  ?commonsSitelink schema:about ?item; schema:isPartOf <https://commons.wikimedia.org/>; schema:name ?sitelink_label .
  FILTER(STRSTARTS(STR(?commonsSitelink), "https://commons.wikimedia.org/wiki/Category")) . # sitelink to a category
  BIND(str(substr(?sitelink_label,10)) as ?category) . # strip "Category:" part
} LIMIT 10

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?category"):::projected v1("?commonsSitelink") v2("?item"):::projected v3("?sitelink_label") a1((" ")) c7([https://commons.wikimedia.org/]):::iri c4(["wd:Q4167836"]):::iri f0[["starts-with(str(?commonsSitelink),'https://commons.wikimedia.org/wiki/Category')"]] f0 --> v1 subgraph minus1["MINUS"] style minus1 stroke-width:6px,fill:pink,stroke:red; v2 --"wdt:P373"--> a1 end subgraph minus2["MINUS"] style minus2 stroke-width:6px,fill:pink,stroke:red; v2 --"wdt:P31"--> c4 end v1 --"schema:about"--> v2 v1 --"schema:isPartOf"--> c7 v1 --"schema:name"--> v3 bind3[/"str(substring(?sitelink_label,'10^^xsd:integer'))"/] v3 --o bind3 bind3 --as--o v4