Project:SPARQL/examples: Difference between revisions

From Beyond Notability
Line 2,708: Line 2,708:
<sparql tryit="1">
<sparql tryit="1">
#title:fishing for dates for FSAs
#title:fishing for dates for FSAs
# union query to get [hopefully] every date associated with women FSAs including main dates and qualifier dates, with date precision
# union query to get [hopefully] every date associated with women FSAs including main dates and qualifier dates
# updated query for qualifiers


PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
Line 2,721: Line 2,720:
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>
PREFIX bnpqv: <https://beyond-notability.wikibase.cloud/prop/qualifier/value/>


 
SELECT distinct ?person ?personLabel ?prop_label ?qualLabel ?qual_dateLabel ?date_value ?s    
SELECT distinct ?person ?personLabel ?prop_label ?prop_valueLabel ?qual_dateLabel ?date_value ?date_precision   ?s
#?prop ?qual
#?prop ?prop_value ?qual_date
 


WHERE {
WHERE {
 
{  # main dates
 
   ?person bnwdt:P3 bnwd:Q3 . #select women
   ?person bnwdt:P3 bnwd:Q3 . #select women
   ?person bnwdt:P75 bnwd:Q8. # find only BN subjects having a FSA  
   ?person bnwdt:P75 bnwd:Q8. # find only BN subjects having a FSA  
Line 2,736: Line 2,731:
   ?person ?p ?s .   
   ?person ?p ?s .   
    
    
    # get stuff about ?p .
      # get stuff about ?p .
       ?prop wikibase:claim ?p;     
       ?prop wikibase:claim ?p;     
         wikibase:statementProperty ?ps ;   
         wikibase:statementProperty ?ps ;   
Line 2,742: Line 2,737:
       ?prop wikibase:propertyType ?date_prop_type .
       ?prop wikibase:propertyType ?date_prop_type .
       ?prop rdfs:label ?prop_label. filter(lang(?prop_label)="en-gb") .  
       ?prop rdfs:label ?prop_label. filter(lang(?prop_label)="en-gb") .  
 
{  # main dates
    
    
   # get dates detail via ?s and psv
   # get dates detail via ?s and psv
   # gets edtf dates in simplified std wiki date format.  are you sure?
   # gets edtf dates in simplified std wiki date format?
   # https://github.com/ProfessionalWiki/WikibaseEdtf
   # https://github.com/ProfessionalWiki/WikibaseEdtf  
 
       ?s ?psv ?wdv .
       ?s ?psv ?wdv .
         ?wdv wikibase:timeValue ?date_value ;
         ?wdv wikibase:timeValue ?date_value .
          wikibase:timePrecision ?date_precision .
 
   } # /main dates
   } # /main dates
    
    
Line 2,755: Line 2,752:
    
    
   { # qualifier dates
   { # qualifier dates
   
      
    ?person bnwdt:P3 bnwd:Q3 . # women
    ?person bnwdt:P75 bnwd:Q8. # only BN subjects having a FSA
 
    # get stuff about ?person 
    ?person ?p ?s . 
 
    # get stuff for ?p . 
      ?prop wikibase:claim ?p;      
        wikibase:statementProperty ?ps;   
        wikibase:statementValue ?psv.
      ?prop rdfs:label ?prop_label. filter(lang(?prop_label)="en") .  # spoke at etc
   # direct value (usually item) for the property
   # direct value (usually item) for the property
         ?s ?ps ?prop_value.
         ?s ?ps ?qual.
      
      
   # get date qualifiers. [assumes no edtf in quals. ]
   # date qualifiers. [assumes no edtf in quals. ]
         ?s ?pq ?date_value . #
         ?s ?pq ?date_value .  
           ?qual_date wikibase:qualifier ?pq .
           ?qual_date wikibase:qualifier ?pq .
           ?qual_date wikibase:propertyType wikibase:Time.  
           ?qual_date wikibase:propertyType wikibase:Time.  
           ?qual_date rdfs:label ?date_qual_label . filter(lang(?date_qual_label)="en") .  
           ?qual_date rdfs:label ?date_qual_label . filter(lang(?date_qual_label)="en") .  
  # qualifier time precision. requires bnpqv: prefix
  # pit/start/end/earliest/latest
      ?s (bnpqv:P1 | bnpqv:P27 | bnpqv:P28 | bnpqv:P51 | bnpqv:P53 ) ?pqv.
          #?pqv wikibase:timeValue ?time_qual . #don't need this as well as date_qual.
          ?pqv wikibase:timePrecision ?date_precision .
        
        
   }  # /qual dates
   }  # /qual dates
    
    
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb". }  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en-gb". }  
    
    
} # /where
} # /where


ORDER BY ?person ?date_value
ORDER BY ?person ?prop_label ?date_value


</sparql>
</sparql>
3,427

edits