query-41ec9ee867a6d3961b6b518c40626699

rq turtle/ttl

Instead of for the MWAPI makes no sense since there is a hard limit at 10000 results from MWAPI (there are about 8300 results so that limit isn't reached)LIMIT 15000The is extracted from the API call but not used and could be deleted.?pageid ) instead of "insource" because the words "infobox newspaper" could be in the wikitext without transcluding the template, and because "hastemplate" also includes redirects to the template.en:Help:Searching#hastemplate: It would be better to use "hastemplate" (see bd:serviceParam mwapi:gsrsearch "insource:\"infobox newspaper\"" .In the MWAPI call you use : I have some comments about optimizing the original query: Peteforsyth@ 01:40, 7 November 2020 (UTC)) talk (Pete FFantastic -- you've made my day! I'm pleased with the results, and I'll dig through it gradually as I'm learning, to see how principles apply. Super helpful. -: This is great. I have played with this a bunch, and reviewed some instructions on building SPARQL queries. My next project, now that I know how to do it, is to customize this query to every state, and add a link to each relevant WikiProject page. I've also successfully made a variant to show all African American newspapers, though very few of those have been properly marked so far. I made a couple tiny improvements (I think): 99of9, Tagishsimon, Dipsacus fullonum @Removed the line about USNPL IDs (I don't think this serves any purpose, maybe a vestige from the initial scrape and associated queries?) Removed the line requiring that it's a US-based paper (which is redundant in the cases above)A few questions I'm still trying to figure out: bit.hint:Prior hint:gearing "forward"I'd like to figure out the ?that feature is going to be developedIt would be awesome to be able to directly embed the results instead of manually uploading to Commons. Maybe It seems impossible to generate a link directly to the map. The "short link" fails every time (I guess because it's such a long query). So, I copy the URL bar, but that goes to the SPARQL code instead of the rendered result. Maybe I can figure out the syntax to do this manually. And/or, might be worthwhile to create separate maps for "exists on English Wikipedia with/without an infobox" and "does not exist on English Wikipedia". I'd like to figure out a way to have green override yellow and red, and yellow override red. That part of the code will require a bit more study. The recent import increased the number of items from under 10,000 to more like 25,000. Much of the data is now bad (duplicates), and overall it's cumbersome to do US-wide searches (verrrrrry laggy). For a few states in the middle of the country, the import did substantially increase the number of good items though. If anybody has ideas about how to resolve duplicates at scale, I'd love to hear 'em.Anyway, here's the code I have so far (staying with Washington as example):

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 a specific state, or is in a place that is in that state,
                                              # or is in a place which is within a place which is within that state, &c
                                               #(replace the wd: value on this line for other states)
  ?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 the state)
  ?item wdt:P31 / wdt:P279* wd:Q11032 . hint:Prior hint:gearing "forward".
                                              # get all items on the subclass tree of newspaper (I don't understand this part)
  ?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