SPARQL examples: Difference between revisions

From clb-lod
Line 26: Line 26:
This will list MARC creator roles existing in the data, and number of creator statements.
This will list MARC creator roles existing in the data, and number of creator statements.
<sparql tryit="1">
<sparql tryit="1">
#defaultView:BarChart
PREFIX clbwb: <https://clb-lod.wikibase.cloud/entity/>
PREFIX clbwb: <https://clb-lod.wikibase.cloud/entity/>
PREFIX clbdp: <https://clb-lod.wikibase.cloud/prop/direct/>
PREFIX clbdp: <https://clb-lod.wikibase.cloud/prop/direct/>
Line 34: Line 35:
PREFIX clbno: <https://clb-lod.wikibase.cloud/prop/novalue/>
PREFIX clbno: <https://clb-lod.wikibase.cloud/prop/novalue/>


select ?marc_creator_prop (group_concat(distinct ?marc_code) as ?marc_codes) ?marc_creator_role_label (count(?bibItem) as ?number_of_creator_statements)                        
select ?marc_creator_role ?marc_creator_role_label (count(?bibItem) as ?number_of_creator_statements)
where {                        
                         
?marc_creator_prop clbdp:P5 clbwb:Q33; wikibase:directClaim ?marc_creator_role; clbdp:P59 ?marc_code; rdfs:label ?marc_creator_role_label .
where {
                         
?marc_creator_prop clbdp:P5 clbwb:Q33; wikibase:directClaim ?marc_creator_role; rdfs:label ?marc_creator_role_label .
   filter (lang(?marc_creator_role_label)="en")
   filter (lang(?marc_creator_role_label)="en")
?bibItem ?marc_creator_role [] .                 
?bibItem ?marc_creator_role [] .                 
}
}
group by ?marc_creator_prop ?marc_codes ?marc_creator_role_label ?number_of_creator_statements         
group by ?marc_creator_role ?marc_creator_role_label ?number_of_creator_statements         
order by desc(?number_of_creator_statements)
order by desc(?number_of_creator_statements)
</sparql>
</sparql>

Revision as of 12:31, 2 October 2022

SPARQL Query Examples

CLB-LOD Ontology

Overview of items reserved for the CLB-LOD Ontology (Q1 to Q200)

PREFIX clbwb: <https://clb-lod.wikibase.cloud/entity/>
PREFIX clbdp: <https://clb-lod.wikibase.cloud/prop/direct/>
PREFIX clbp: <https://clb-lod.wikibase.cloud/prop/>
PREFIX clbps: <https://clb-lod.wikibase.cloud/prop/statement/>
PREFIX clbpq: <https://clb-lod.wikibase.cloud/prop/qualifier/>
PREFIX clbpr: <https://clb-lod.wikibase.cloud/prop/reference/>
PREFIX clbno: <https://clb-lod.wikibase.cloud/prop/novalue/>

select ?wikibase_item ?label
       
where { 
  ?wikibase_item rdfs:label ?label. filter (lang(?label)="en")
  values ?wikibase_item {clbwb:Q1 clbwb:Q2 clbwb:Q3 clbwb:Q4 clbwb:Q5 clbwb:Q6 clbwb:Q7 clbwb:Q8 clbwb:Q9 clbwb:Q10 clbwb:Q11 clbwb:Q12 clbwb:Q13 clbwb:Q14 clbwb:Q15 clbwb:Q16 clbwb:Q17 clbwb:Q18 clbwb:Q19 clbwb:Q20 clbwb:Q21 clbwb:Q22 clbwb:Q23 clbwb:Q24 clbwb:Q25 clbwb:Q26 clbwb:Q27 clbwb:Q28 clbwb:Q29 clbwb:Q30 clbwb:Q31 clbwb:Q32 clbwb:Q33 clbwb:Q34 clbwb:Q35 clbwb:Q36 clbwb:Q37 clbwb:Q38 clbwb:Q39 clbwb:Q40 clbwb:Q41 clbwb:Q42 clbwb:Q43 clbwb:Q44 clbwb:Q45 clbwb:Q46 clbwb:Q47 clbwb:Q48 clbwb:Q49 clbwb:Q50 clbwb:Q51 clbwb:Q52 clbwb:Q53 clbwb:Q54 clbwb:Q55 clbwb:Q56 clbwb:Q57 clbwb:Q58 clbwb:Q59 clbwb:Q60 clbwb:Q61 clbwb:Q62 clbwb:Q63 clbwb:Q64 clbwb:Q65 clbwb:Q66 clbwb:Q67 clbwb:Q68 clbwb:Q69 clbwb:Q70 clbwb:Q71 clbwb:Q72 clbwb:Q73 clbwb:Q74 clbwb:Q75 clbwb:Q76 clbwb:Q77 clbwb:Q78 clbwb:Q79 clbwb:Q80 clbwb:Q81 clbwb:Q82 clbwb:Q83 clbwb:Q84 clbwb:Q85 clbwb:Q86 clbwb:Q87 clbwb:Q88 clbwb:Q89 clbwb:Q90 clbwb:Q91 clbwb:Q92 clbwb:Q93 clbwb:Q94 clbwb:Q95 clbwb:Q96 clbwb:Q97 clbwb:Q98 clbwb:Q99 clbwb:Q100 clbwb:Q101 clbwb:Q102 clbwb:Q103 clbwb:Q104 clbwb:Q105 clbwb:Q106 clbwb:Q107 clbwb:Q108 clbwb:Q109 clbwb:Q110 clbwb:Q111 clbwb:Q112 clbwb:Q113 clbwb:Q114 clbwb:Q115 clbwb:Q116 clbwb:Q117 clbwb:Q118 clbwb:Q119 clbwb:Q120 clbwb:Q121 clbwb:Q122 clbwb:Q123 clbwb:Q124 clbwb:Q125 clbwb:Q126 clbwb:Q127 clbwb:Q128 clbwb:Q129 clbwb:Q130 clbwb:Q131 clbwb:Q132 clbwb:Q133 clbwb:Q134 clbwb:Q135 clbwb:Q136 clbwb:Q137 clbwb:Q138 clbwb:Q139 clbwb:Q140 clbwb:Q141 clbwb:Q142 clbwb:Q143 clbwb:Q144 clbwb:Q145 clbwb:Q146 clbwb:Q147 clbwb:Q148 clbwb:Q149 clbwb:Q150 clbwb:Q151 clbwb:Q152 clbwb:Q153 clbwb:Q154 clbwb:Q155 clbwb:Q156 clbwb:Q157 clbwb:Q158 clbwb:Q159 clbwb:Q160 clbwb:Q161 clbwb:Q162 clbwb:Q163 clbwb:Q164 clbwb:Q165 clbwb:Q166 clbwb:Q167 clbwb:Q168 clbwb:Q169 clbwb:Q170 clbwb:Q171 clbwb:Q172 clbwb:Q173 clbwb:Q174 clbwb:Q175 clbwb:Q176 clbwb:Q177 clbwb:Q178 clbwb:Q179 clbwb:Q180 clbwb:Q181 clbwb:Q182 clbwb:Q183 clbwb:Q184 clbwb:Q185 clbwb:Q186 clbwb:Q187 clbwb:Q188 clbwb:Q189 clbwb:Q190 clbwb:Q191 clbwb:Q192 clbwb:Q193 clbwb:Q194 clbwb:Q195 clbwb:Q196 clbwb:Q197 clbwb:Q198 clbwb:Q199 clbwb:Q200 }
bind(xsd:integer(strafter(str(?wikibase_item),"https://clb-lod.wikibase.cloud/entity/Q")) as ?order) 
} order by ?order

Try it!


Distribution of MARC creator roles

This will list MARC creator roles existing in the data, and number of creator statements.

#defaultView:BarChart
PREFIX clbwb: <https://clb-lod.wikibase.cloud/entity/>
PREFIX clbdp: <https://clb-lod.wikibase.cloud/prop/direct/>
PREFIX clbp: <https://clb-lod.wikibase.cloud/prop/>
PREFIX clbps: <https://clb-lod.wikibase.cloud/prop/statement/>
PREFIX clbpq: <https://clb-lod.wikibase.cloud/prop/qualifier/>
PREFIX clbpr: <https://clb-lod.wikibase.cloud/prop/reference/>
PREFIX clbno: <https://clb-lod.wikibase.cloud/prop/novalue/>

select ?marc_creator_role ?marc_creator_role_label (count(?bibItem) as ?number_of_creator_statements)
                           
where {
                           
?marc_creator_prop clbdp:P5 clbwb:Q33; wikibase:directClaim ?marc_creator_role; rdfs:label ?marc_creator_role_label .
  filter (lang(?marc_creator_role_label)="en")
?bibItem ?marc_creator_role [] .                

}
group by ?marc_creator_role ?marc_creator_role_label ?number_of_creator_statements        
order by desc(?number_of_creator_statements)

Try it!