query-95fbdbd8a7aa3d6a9f9345a2381cc529

rq turtle/ttl

PeteforsythTagishsimonhint:Query hint:optimizer "None".hint:Prior hint:gearing "forward".hint:Prior hint:gearing "forward".(Q11032)newspaper ?c

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 schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?place ?placeLabel ?id ?coords ?article ?mapflags ?rgb WHERE {
  ?place wdt:P131* wd:Q1223 . hint:Prior hint:gearing "forward".
                                              # ?place is in Washington, or is in a place that is in Washington
                                              # or is in a place which is within a place which is within Washington, &c
  ?item wdt:P291|wdt:P159|wdt:P131 ?place .   # ?item is published in, or has its HQ in, or is located in a ?place 
                                              # (which per the above is within Washington)
  ?item wdt:P31 / wdt:P279* wd:Q11032 . hint:Prior hint:gearing "forward".
                                              # get all items on the subclass tree of newspaper 
  ?item wdt:P17|wdt:P495 wd:Q30 .             # it's in America or has a country of origin of America
  OPTIONAL { ?item wdt:P5454 ?id .}           # might have an ID
  ?place wdt:P625 ?coords.                    # the ?place must have coordinates 
  OPTIONAL {                                  # go off & get articles that have infobox newspaper
    SELECT ?item ?pageid ?ns WHERE {
      SERVICE wikibase:mwapi {
        bd:serviceParam wikibase:endpoint "en.wikipedia.org" .
        bd:serviceParam wikibase:api "Generator" .
        bd:serviceParam mwapi:generator "search" .
        bd:serviceParam mwapi:gsrsearch "hastemplate:"Infobox newspaper"" .
        bd:serviceParam mwapi:gsrlimit "max" .
        ?item wikibase:apiOutputItem mwapi:item .
        ?ns wikibase:apiOutput "@ns" .
       }
    } LIMIT 10000                             # MVAPI gives max 10000 results anyway, and the query seems more
                                              # effiencient if the optimizer knows the maximum number of results.
  }
     OPTIONAL {                               # ?item might have an EN wiki article
      ?article schema:about ?item .
      ?article schema:isPartOf <https://en.wikipedia.org/> .
  }
                                       # Lord knows. Some sort of colour coding logic. Too tired.
  BIND(IF(BOUND(?ns),"_infobox","_noinfobox") AS ?infobox).  # there is or is not an infobox
  BIND(IF(BOUND(?article),"enwiki","noenwiki") AS ?onwiki).  # there is or is not an enwiki article
  BIND(CONCAT(?onwiki,?infobox) as ?layer) .                 # concatenate those twoas a key (?)
                                                             # assign some colours based on state            
  BIND( IF(BOUND(?article),   IF(BOUND(?ns), "009500" , "FFF000" )  ,  "FF0000"   )  AS ?rgb).  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Query found at