query-535255e8f4569d0188be7459a20452a9

rq turtle/ttl

PropertiesCommons category (P373)topic's main category (P910)category's main topic (P301)

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX schema: <http://schema.org/>
SELECT DISTINCT ?categoryItem WHERE {
    # ?article and ?category share the same P373 ("Commons Category")
    ?articleItem  wdt:P373 ?commonsCategory .
    ?categoryItem wdt:P373 ?commonsCategory .

    # 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 .
    FILTER(STRSTARTS(STR(?commonsSitelink), "https://commons.wikimedia.org/wiki/Category"))
    FILTER(STRENDS(STR(?commonsSitelink), ENCODE_FOR_URI(?commonsCategory)))
} limit 100

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?articleItem") v4("?categoryItem"):::projected v2("?commonsCategory") v1("?commonsSitelink") f0[["ends-with(str(?commonsSitelink),encode-for-uri(?commonsCategory))"]] f0 --> v1 f0 --> v2 f1[["starts-with(str(?commonsSitelink),'https://commons.wikimedia.org/wiki/Category')"]] f1 --> v1 v3 --"wdt:P373"--> v2 v4 --"wdt:P373"--> v2 v3 --"wdt:P910"--> v4 v4 --"wdt:P301"--> v3 v1 --"schema:about"--> v4