Query works on wikidata query service but not on Apache Jena copy

263 Views Asked by At

The query below is the accepted answer for my question Getting only english property value. When used on the Wikidata Query service try it! it will show shortNames for countries like Australia -> AUS and Austria -> AUT as requeted. Running the same query on my local Wikidata copy created a few weeks ago based on Apache Jena Fuseki the shortName column stays empty (see screenshot below).

What is the reason for the difference and how could the query be modified to also work with Apache Jena Fuseki?

Apache Jena Fuseki screenshot

    # get a list countries with the corresponding ISO code
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX wd: <http://www.wikidata.org/entity/>
    PREFIX wdt: <http://www.wikidata.org/prop/direct/>
    PREFIX wikibase: <http://wikiba.se/ontology#>
    PREFIX p: <http://www.wikidata.org/prop/>
    PREFIX ps: <http://www.wikidata.org/prop/statement/>
    PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
    SELECT ?country ?countryLabel ?shortName (MAX(?pop) as ?population) ?coord ?isocode
    WHERE 
    {
      # instance of country
      ?country wdt:P31 wd:Q3624078.
      OPTIONAL {
         ?country rdfs:label ?countryLabel filter (lang(?countryLabel) = "en").
       }
      OPTIONAL {
          ?country p:P1813 ?shortNameStmt. # get the short name statement
          ?shortNameStmt ps:P1813 ?shortName # the the short name value from the statement
          filter (lang(?shortName) = "en") # filter for English short names only
          filter not exists {?shortNameStmt pq:P31 wd:Q28840786} # ignore flags (aka emojis)
      }
      OPTIONAL { 
        # get the population
         # https://www.wikidata.org/wiki/Property:P1082
         ?country wdt:P1082 ?pop. 
      }
      # get the iso countryCode
      { ?country wdt:P297 ?isocode }.
      # get the coordinate
      OPTIONAL { ?country wdt:P625 ?coord }.
    } 
    GROUP BY ?country ?countryLabel ?shortName ?population ?coord ?isocode 
    ORDER BY ?countryLabel
1

There are 1 best solutions below

0
On

@UninformedUser's test query:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SELECT ?country ?shortNameStmt ?shortName      WHERE      
{       
  VALUES ?country {wd:Q40} ?country wdt:P31 wd:Q3624078.              
  OPTIONAL {           
    ?country p:P1813 ?shortNameStmt.            
    ?shortNameStmt ps:P1813 ?shortName  filter (lang(?shortName) = "en")            
    filter not exists {?shortNameStmt pq:P31 wd:Q28840786}        
  }       
}

Did not give a result on the truthy-based import of wikidata while it worked on the latest-all import. The same holds true for the full query. Still it would be good to know why the query does not work with the truthy dataset.