query-791c55642120c10571b499d81fec759a

rq turtle/ttl

try to determine the license of an image SELECT ?item ?image ?categoryName WHERE { BIND(wd:Q9188 AS ?item) # example ?item wdt:P18 ?image. BIND(REPLACE(wikibase:decodeUri(CONCAT("File:", STRAFTER(STR(?image), "/wiki/Special:FilePath/"))), " ", "_") AS ?imageTitle) SERVICE wikibase:mwapi { bd:serviceParam wikibase:api "Categories"; wikibase:endpoint "commons.wikimedia.org"; mwapi:titles ?imageTitle. ?categoryTitle wikibase:apiOutput mwapi:category. } BIND(STRAFTER(?categoryTitle, "Category:") AS ?categoryName) FILTER(STRSTARTS(?categoryName, "CC-") || REGEX(?categoryName, "^PD[- ]")) }

Use at

PREFIX mwapi: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# try to determine the license of an image
SELECT ?item ?image ?categoryName WHERE {
  BIND(wd:Q9188 AS ?item) # example
  ?item wdt:P18 ?image.
  BIND(REPLACE(wikibase:decodeUri(CONCAT("File:", STRAFTER(STR(?image), "/wiki/Special:FilePath/"))), " ", "_") AS ?imageTitle)
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:api "Categories";
                    wikibase:endpoint "commons.wikimedia.org";
                    mwapi:titles ?imageTitle.
    ?categoryTitle wikibase:apiOutput mwapi:category.
  }
  BIND(STRAFTER(?categoryTitle, "Category:") AS ?categoryName)
  FILTER(STRSTARTS(?categoryName, "CC-") || REGEX(?categoryName, "^PD[- ]"))
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v6("?categoryName"):::projected v5("?categoryTitle") v3("?image"):::projected v4("?imageTitle") v2("?item"):::projected c5(["bd:serviceParam"]):::iri c7(["Categories"]):::literal c12(["mwapi:category"]):::iri c9(["commons.wikimedia.org"]):::literal f0[["(starts-with(?categoryName,'CC-') || regex(?categoryName,'^PD#91;- #93;'))"]] f0 --> v6 bind1[/"'wd:Q9188'"/] bind1 --as--o v2 v2 --"wdt:P18"--> v3 bind2[/"replace(http://wikiba.se/ontology#decodeUri(concat('File:',substring-after(str(?image),'/wiki/Special:FilePath/'))),' ','_')"/] v3 --o bind2 bind2 --as--o v4 subgraph s1["http://wikiba.se/ontology#mwapi"] style s1 stroke-width:4px; c5 --"mwapi:api"--> c7 c5 --"mwapi:endpoint"--> c9 c5 --"mwapi:titles"--> v4 v5 --"mwapi:apiOutput"--> c12 end bind3[/"substring-after(?categoryTitle,'Category:')"/] v5 --o bind3 bind3 --as--o v6