Project:SPARQL/examples: Difference between revisions

Line 2,812: Line 2,812:
<sparql tryit="1">
<sparql tryit="1">
# a union query to fetch stuff for multiple properties, in this case dates recorded in EDTF which need slightly different handling from PIT dates
# a union query to fetch stuff for multiple properties, in this case dates recorded in EDTF which need slightly different handling from PIT dates
# TODO: this excludes any EDTF dates in qualifiers; not sure if there are any.  
# main dates only; pretty sure there are no EDTF in qualifiers.  
# updated to get date property labels


PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
Line 2,822: Line 2,823:
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>


SELECT  ?person ?personLabel ?date_edtf ?date_type
SELECT  ?person ?personLabel ?date_edtf ?date_prop ?date_label ?s


WHERE { ?person bnwdt:P3 bnwd:Q3 .  
WHERE { ?person bnwdt:P3 bnwd:Q3 .  
       FILTER NOT EXISTS { ?person bnwdt:P4 bnwd:Q12 . }  
       FILTER NOT EXISTS { ?person bnwdt:P4 bnwd:Q12 . }  
     
    ## short form of UNION using | 
      ?person ( bnwdt:P131 | bnwdt:P132 | bnwdt:P133  ) ?date_edtf .
## cf. full length UNION
## {?person bnwdt:P131 ?date_edtf } union {?person bnwdt:P132 ?date_edtf } union {?person bnwdt:P133 ?date_edtf } 
      
      
    ## need to know what kind of date it is
      ## can do this union first but makes no difference to results except possibly a bit slower.
    ?person ?date_type ?date_edtf .
      #?person ( bnp:P131 | bnp:P132 | bnp:P133  ) ?s .
        
      #  ?s ( bnps:P131 | bnps:P132 | bnps:P133  ) ?date_edtf .
 
       ?person ?p ?s . # so you can get the statement id and date prop label
          ?claim wikibase:claim ?p;     
                rdfs:label ?date_label. filter(lang(?date_label)="en") .       
 
          ?s ?date_prop ?date_edtf .
             
     ## filter for edtf dates
     ## filter for edtf dates
     ## docs: https://github.com/ProfessionalWiki/WikibaseEdtf
     ## docs: https://github.com/ProfessionalWiki/WikibaseEdtf
586

edits