Project:SPARQL/examples: Difference between revisions

From Beyond Notability
Line 1,776: Line 1,776:
HAVING (?count<2)  
HAVING (?count<2)  
order by ?item  
order by ?item  
</sparql>
=== Statements that contain both a date *and* an unknown value date===
<sparql tryit="1">
# A query to look for statements containing an <unknown value> date *and* a date
# caveat: not yet completely sure if it will work in all cases for main dates
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwdv: <https://beyond-notability.wikibase.cloud/value/>
PREFIX bnwdt: <https://beyond-notability.wikibase.cloud/prop/direct/>
PREFIX bnp: <https://beyond-notability.wikibase.cloud/prop/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
SELECT  ?item ?itemLabel ?main_label ?qualLabel ?subLabel
(group_concat(distinct ?date_prop) as ?dates) 
(count (distinct(isBLANK(?t))) as ?tcount) 
?s
# using isBlank() in select creates true/false, then count distinct finds any in a group having >1.
WHERE
{
  {
  # qualifiers. [qualifiers need to include ?s in the group by]
  ?item ?p ?s.
 
  # labels
  ?s ?subp ?sub .
  ?qual wikibase:claim ?p;
        wikibase:statementProperty ?subp. 
 
    ?s ?pq ?t .
    ?date_prop wikibase:qualifier ?pq ;
            wikibase:propertyType ?date_prop_type .
    filter(?date_prop_type in (wikibase:Time, wikibase:Edtf) ).
  }
  UNION
  {
  # main [excluding ?s from group by this time]
  ?item ?p ?sm.
  ?sm ?ps ?t .
   
  ?date_prop wikibase:claim ?p.
  ?date_prop wikibase:statementProperty ?ps.
  ?date_prop wikibase:propertyType ?date_prop_type .
  ?date_prop rdfs:label ?main_label .  filter(lang(?main_label)="en-gb") .
   
  filter(?date_prop_type in (wikibase:Time, wikibase:Edtf) ).
  }
 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,en_gb" }
}
group by ?item ?itemLabel ?s ?qualLabel ?subLabel  ?main_label
having (?tcount >1 )  # comment out to get everything
ORDER BY ?itemLabel ?main_label ?qualLabel ?subLabel ?date_prop


</sparql>
</sparql>
614

edits