Wednesday, 29 March 2023

Commons Query

 To Get file names that are not available in your languae

Link


Codes

SELECT ?file ?title ?captionEn ?captionMl ?img_

WITH

{

  SELECT ?file ?title

  WHERE

  {

    SERVICE wikibase:mwapi

    {

      bd:serviceParam wikibase:api "Search" .

      bd:serviceParam wikibase:endpoint "commons.wikimedia.org" .

      bd:serviceParam mwapi:srsearch "deepcategory:\"Otto von Bismarck by year\" prefix:File:" .

      bd:serviceParam mwapi:srlimit "max" .

      ?title wikibase:apiOutput mwapi:title .

      ?pageid wikibase:apiOutput "@pageid" .

    }

    BIND (URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)

  }

} AS %get_files

WHERE

{

  INCLUDE %get_files

  # ?file wdt:P180 ?depicts ?img_.

  # service <https://query.wikidata.org/sparql> {

  #   OPTIONAL {?depicts rdfs:label ?depicts_label FILTER (lang(?depicts_label) = 'en') } 

  # }

  OPTIONAL { ?file rdfs:label ?captionEn FILTER (lang(?captionEn) = 'en') }

  OPTIONAL { ?file rdfs:label ?captionMl FILTER (lang(?captionMl) = 'ml') }

    optional {

    ?item wdt:P18 ?img_ .

  }

  bind (if(bound(?img_), 

           ?img_, 

           <http://commons.wikimedia.org/wiki/Special:FilePath/File:Profile_avatar_placeholder_large.png>) as ?image)

} order by desc(?date)