Project:SPARQL/examples: Difference between revisions

mNo edit summary
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-gb labels
# query to find small number of items/properties which don't have "en" labels
# this causes problems when needing to get labels without using SERVICE, or can't rely on AUTO_LANGUAGE
# 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,244: Line 3,245:


SELECT  
SELECT  
   ?item ?engb ?itemLabel
   ?item ?en ?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,259: Line 3,260:
   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-gb (and/or) en separately
   # 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").  } # blank if item only has en label 
   #optional { ?item rdfs:label ?engb . filter(lang(?engb)="en-gb").  }  
   #optional { ?item rdfs:label ?en . filter(lang(?en)="en").  }  
   optional { ?item rdfs:label ?en . filter(lang(?en)="en").  } # blank if item only has en-gb label 
    
    
   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 ?engb ?itemLabel
group by ?item ?en ?itemLabel
HAVING (?count<2)  
HAVING (?count<2)  
order by ?item  
order by ?item  


</sparql>
</sparql>


=== Statements that contain both a date *and* an unknown value date===
=== Statements that contain both a date *and* an unknown value date===
586

edits