Project:SPARQL/examples: Difference between revisions

m
Line 3,230: Line 3,230:
<sparql tryit="1">
<sparql tryit="1">


# query to find small number of items/properties which don't have "en" labels
# query to check for any items/properties which don't have "en" labels. [currently not an issue but retained for reference.]
# this causes problems when needing to get labels without using SERVICE, or can't rely on AUTO_LANGUAGE
# update: changing default to "en" rather than "en-gb" to reflect recommended practice, which I'd overlooked in the Maartens' report. There should be even fewer missing.


PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
Line 3,245: Line 3,243:


SELECT  
SELECT  
   ?item ?en ?itemLabel
   ?item ?itemLabel
   (group_concat(distinct ?language) as ?languages)  
   (group_concat(distinct ?language) as ?languages)  
   (count(distinct ?rdfs_label) as ?count) # TIL: where you put distinct matters!   
   (count(distinct ?rdfs_label) as ?count) # TIL: where you put distinct matters!   
Line 3,251: Line 3,249:
WHERE {
WHERE {
    
    
   ?item bnwdt:P12 ?s. # limit to items with instance of. speeds up the query a lot cf. fetching anything.  
   #?item bnwdt:P12 ?s. # limit to items with instance of. speeds up the query a lot cf. fetching anything.  
 
 
   #?item ?p ?s. #  anything. takes a while, adds ~20 not found in the instance of version
   ?item ?p ?s. #  anything. takes a while, adds ~20 not found in the instance of version
  #filter not exists { ?item bnwdt:P12 ?s  . } # errrm why doesn't this do anything?
 
   ?item rdfs:label ?rdfs_label .  # rdfs item label (1 per language).  
   ?item rdfs:label ?rdfs_label .  # rdfs item label (1 per language).  
    
    
   BIND(LANG(?rdfs_label) as ?language) .  # get 2 letter language codes
   BIND(LANG(?rdfs_label) as ?language) .  # get 2 letter language codes


  # optional to fetch en (and/or) en-gb separately. if you change this, you need to also change the group by.
   #optional { ?item rdfs:label ?engb . filter(lang(?engb)="en-gb").  }  
   #optional { ?item rdfs:label ?engb . filter(lang(?engb)="en-gb").  }  
   optional { ?item rdfs:label ?en . filter(lang(?en)="en").  } # blank if item only has en-gb label  
   #optional { ?item rdfs:label ?en . filter(lang(?en)="en").  }   
    
    
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en-gb, en". }  
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en-gb, en". }  
}
}
group by ?item ?en ?itemLabel
group by ?item ?itemLabel
HAVING (?count<2)  
HAVING (?count<2)  
order by ?item  
order by ?item  
586

edits