-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvarious-wikidata-dbpedia-sparql-fed-examples.sql
2389 lines (2026 loc) · 78.5 KB
/
various-wikidata-dbpedia-sparql-fed-examples.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Wikidata Example 1
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX hint: <http://www.bigdata.com/queryHints#>
SELECT *
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{ SELECT DISTINCT ?item ?label ?numero (SAMPLE(?image) AS ?image)
WHERE {
?item p:P528 ?catalogStatement .
?item rdfs:label ?label .
?catalogStatement ps:P528 ?numero .
?catalogStatement pq:P972 wd:Q14530 .
OPTIONAL {?item wdt:P18 ?image } .
# SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?label ?numero ORDER BY ?numero
}
} ;
-- Live Results Link: https://tinyurl.com/khm8dzt
-- Wikidata & DBpedia Example 2
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT xsd:string(?label) as ?name?dbpediaID ?item as ?wikidataID
?description
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{
SELECT DISTINCT ?item ?numero (SAMPLE(?pic) AS ?picture)
WHERE {
?item p:P528 ?catalogStatement .
?catalogStatement ps:P528 ?numero .
?catalogStatement pq:P972 wd:Q14530 .
OPTIONAL {?item wdt:P18 ?pic } .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?numero ORDER BY ?numero
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?item ?dbpediaID ?label ?image ?description ?subjectText
FROM <http://dbpedia.org>
WHERE { ?dbpediaID owl:sameAs ?item ;
rdfs:label ?label ;
foaf:depiction ?image ;
rdfs:comment ?description ;
dct:subject [ rdfs:label ?subjectText ] .
FILTER (LANG(?label) = "en")
FILTER (LANG(?description) = "en")
}
}
} ;
-- Live Results Link: https://tinyurl.com/k475m7u
--- Federated Query Across DBpedia and Wikidata SPARQL Query Endpoints for PivotViewer
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT ?subjectText ?dbpediaID as ?href xsd:string(?label) as ?name
?description ?item as ?wikidataID ?dbpediaID ?image ?picture
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{
SELECT DISTINCT ?item ?numero (SAMPLE(?pic) AS ?picture)
WHERE {
?item p:P528 ?catalogStatement .
?catalogStatement ps:P528 ?numero .
?catalogStatement pq:P972 wd:Q14530 .
OPTIONAL {?item wdt:P18 ?pic } .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?numero ORDER BY ?numero
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?item ?dbpediaID ?label ?image ?description ?subjectText
FROM <http://dbpedia.org>
WHERE { ?dbpediaID owl:sameAs ?item ;
rdfs:label ?label ;
foaf:depiction ?image ;
rdfs:comment ?description ;
dct:subject [ rdfs:label ?subjectText ] .
FILTER (LANG(?label) = "en")
FILTER (LANG(?description) = "en")
}
}
} ;
-- Live Result Link: https://tinyurl.com/m4e77nz
-- Adds Names of Entity Types for additional Categorization
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT ?dbpediaID as ?href xsd:string(?label) as ?name
?description ?subjectText ?typeName
?item as ?wikidataID ?dbpediaID ?image ?picture
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{
SELECT DISTINCT ?item ?numero (SAMPLE(?pic) AS ?picture)
WHERE {
?item p:P528 ?catalogStatement .
?catalogStatement ps:P528 ?numero .
?catalogStatement pq:P972 wd:Q14530 .
OPTIONAL {?item wdt:P18 ?pic } .
# SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?numero ORDER BY ?numero
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT ?item ?dbpediaID ?label ?image ?description ?subjectText ?typeName
FROM <http://dbpedia.org>
WHERE { ?dbpediaID a [rdfs:label ?typeName] ;
owl:sameAs ?item ;
rdfs:label ?label ;
foaf:depiction ?image;
rdfs:comment ?description ;
dct:subject [ rdfs:label ?subjectText ] .
FILTER (LANG(?label) = "en")
FILTER (LANG(?typeName) = "en")
FILTER (LANG(?description) = "en")
}
}
} ;
-- Live Results Link : https://tinyurl.com/lw3nc3y
-- Saint-Raymond Museum
-- Shows Empty Solution fields due to missing data in DBpedia
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT DISTINCT ?dbpediaID as ?href xsd:string(?label) as ?name
?description ?subjectText
?item as ?wikidataID ?dbpediaID ?img ?image
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{
SELECT DISTINCT ?item ?monarque ?image
(CONCAT("http://zone47.com/crotos/?p195=19675&p180=", REPLACE( str(?monarque),"http://www.wikidata.org/entity/Q","")) as ?voir )
WHERE {
?item wdt:P195 wd:Q1376.
?item wdt:P180 ?monarque .
?monarque wdt:P39 wd:Q842606 .
OPTIONAL{ ?item wdt:P18 ?image }
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" }
}
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT ?item ?dbpediaID ?label ?img ?description ?subjectText
FROM <http://dbpedia.org>
WHERE {
OPTIONAL { ?dbpediaID owl:sameAs ?item ;
rdfs:label ?label ;
foaf:depiction ?img;
rdfs:comment ?description ;
dct:subject [ rdfs:label ?subjectText ] .
FILTER (LANG(?label) = "en")
FILTER (LANG(?typeName) = "en")
FILTER (LANG(?description) = "en")
}
}
}
} ;
-- Live Results Link: https://tinyurl.com/keb5oyk
-- Tennis
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?singlesEvent ?dbpediaEventID ?dbpediaWimbledonEventID ?wimbledonEvent
?date ?winnerItem ?Player_name ?Event ?Country ?enArticle
WHERE {
SERVICE <http://query.wikidata.org/sparql> {
SELECT ?singlesEvent ?singlesEventLabel ?wimbledonEvent ?wimbledonEventLabel
?date ?winnerItem ?Player_name ?Event ?image ?Country ?enArticle
(COUNT(?article) as ?rank)
WHERE {
VALUES ?events {wd:Q16893072 wd:Q16893403}
?singlesEvent wdt:P31 ?events .
?singlesEvent wdt:P361 ?wimbledonEvent .
?wimbledonEvent wdt:P31 wd:Q41520 .
?wimbledonEvent wdt:P582 ?endDate .
?singlesEvent wdt:P1346 ?winnerItem .
?winnerItem wdt:P21 ?genderItem .
OPTIONAL{?winnerItem wdt:P741 ?playingHandItem }
OPTIONAL{?winnerItem wdt:P27 ?citizenshipItem }
BIND (if(?genderItem = wd:Q6581072, ?endDate - "P1D"^^xsd:duration, ?endDate ) as ?date )
BIND (if(?genderItem = wd:Q6581072, "Women's Singles", "Men's Singles") as ?Event)
# OPTIONAL {?winnerItem wdt:P18 ?image }
OPTIONAL {?article schema:about ?winnerItem }
OPTIONAL {?enArticle schema:about ?winnerItem .
?enArticle schema:isPartOf <https://en.wikipedia.org/>
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
?wimbledonEvent rdfs:label ?wimbledonEventLabel .
?singlesEvent rdfs:label ?singlesEventLabel .
?winnerItem rdfs:label ?Player_name .
?playingHandItem rdfs:label ?Playing_Hand .
?citizenshipItem rdfs:label ?Country .}
}
GROUP BY ?singlesEvent ?singlesEventLabel ?wimbledonEvent ?wimbledonEventLabel ?date
?winnerItem ?Player_name ?Event ?image ?Playing_Hand ?Country ?enArticle
ORDER BY DESC (?rank)
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?singlesEvent ?dbpediaEventID ?dbpediaWimbledonEventID ?wimbledonEvent
FROM <http://dbpedia.org>
WHERE {
OPTIONAL { ?dbpediaEventID owl:sameAs ?singlesEvent .
?dbpediaWimbledonEventID owl:sameAs ?wimbledonEvent .
# rdfs:label ?label ;
# foaf:depiction ?img ;
# rdfs:comment ?description ;
# dct:subject [ rdfs:label ?subjectText ] .
# FILTER (LANG(?label) = "en")
# FILTER (LANG(?typeName) = "en")
# FILTER (LANG(?description) = "en")
}
}
}
} ;
-- Live Results Link: https://tinyurl.com/k3n7o2g (with images)
-- Live Resuls Link: https://tinyurl.com/mr5ahqk (without images)
-- Europeana
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?work ?dbpediaWorkID ?title ?inception ?precision
?image ?Exhibition_country ?type_of_work
?creator ?genre ?depicting ?material_used
WHERE {
SERVICE <http://query.wikidata.org/sparql> {
SELECT ?work ?title ?inception ?precision
?image ?Exhibition_country ?type_of_work
?creator ?genre ?depicting ?material_used
WHERE {
{
SELECT ?work ?inception ?precision ?exhibitionCountryItem
?instanceOfItem ?creatorItem ?genreItem ?depictingItem
?materialUsedItem (SAMPLE(?image) as ?image) (COUNT(?article) as ?rank)
WHERE {
?work wdt:P608 wd:Q20980830.
FILTER (?work != wd:Q133575)
?work p:P608/pq:P17 ?exhibitionCountryItem.
?work p:P571/psv:P571 ?inceptionStatementNode .
?inceptionStatementNode wikibase:timeValue ?inception .
?inceptionStatementNode wikibase:timePrecision ?precision .
OPTIONAL {?work wdt:P18 ?image}
OPTIONAL {?article schema:about ?work}
OPTIONAL {?work wdt:P31 ?instanceOfItem }
OPTIONAL {?work wdt:P170 ?creatorItem }
OPTIONAL {?work wdt:P136 ?genreItem }
OPTIONAL {?work wdt:P180 ?depictingItem }
OPTIONAL {?work wdt:P186 ?materialUsedItem }
}
GROUP BY ?work ?inception ?precision ?exhibitionCountryItem ?instanceOfItem
?creatorItem ?genreItem ?depictingItem ?materialUsedItem
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language 'en' .
?work rdfs:label ?title .
?instanceOfItem rdfs:label ?type_of_work .
?creatorItem rdfs:label ?creator .
?genreItem rdfs:label ?genre .
?depictingItem rdfs:label ?depicting .
?materialUsedItem rdfs:label ?material_used .
?exhibitionCountryItem rdfs:label ?Exhibition_country .
}
}
ORDER BY DESC (?rank)
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?work ?dbpediaWorkID
FROM <http://dbpedia.org>
WHERE {
OPTIONAL { ?dbpediaWorkID owl:sameAs ?work .
# rdfs:label ?label ;
# foaf:depiction ?img;
# rdfs:comment ?description ;
# dct:subject [ rdfs:label ?subjectText ] .
# FILTER (LANG(?label) = "en")
# FILTER (LANG(?typeName) = "en")
# FILTER (LANG(?description) = "en")
}
}
}
} ;
-- Live Results Link: https://tinyurl.com/lkr3gzm
-- Prize Winners
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?person ?dbpediaID ?place ?dbpediaPlaceID ?longitude ?latitude?name ?coord ?image ?almamater ?article
WHERE
{ SERVICE <http://query.wikidata.org/sparql> {
SELECT ?name ?coord ?image ?almamater ?article ?place ?person
WHERE {
?person wdt:P166 wd:Q47170 ;
wdt:P69 ?place .
?place wdt:P625 ?coord
OPTIONAL{ ?person wdt:P18 ?image }
OPTIONAL{ ?article schema:about ?person ; schema:isPartOf <https://en.wikipedia.org/> }
?person rdfs:label ?name filter (lang(?name) = "en")
?place rdfs:label ?almamater filter (lang(?almamater) = "en")
}
}
SERVICE <http://dbpedia.org/sparql> {
SELECT ?person ?place ?dbpediaID ?dbpediaPlaceID ?longitude ?latitude
FROM <http://dbpedia.org>
WHERE {
?dbpediaID owl:sameAs ?person .
?dbpediaPlaceID owl:sameAs ?place ;
geo:lat ?latitude ;
geo:long ?longitude .
}
}
} ;
-- Live Results Link: https://tinyurl.com/lodjceo
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?item as ?wikidDataID ?dbpediaID ?itemLabel ?image ?sitelink ?itemDescription
WHERE {
SERVICE <http://query.wikidata.org/sparql> {
SELECT DISTINCT ?item ?itemLabel ?itemDescription (SAMPLE(?image) AS ?image) ?sitelink
WHERE {
?item wdt:P31 wd:Q515 ;
wdt:P6 ?person .
?person wdt:P21 wd:Q6581072 .
OPTIONAL { ?item wdt:P18 ?image. }
OPTIONAL {
?sitelink schema:about ?item.
?sitelink schema:isPartOf <https://en.wikipedia.org/>.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en,fr,es,de,ru,it,nl,ja,zh,pl,cs". }
}
GROUP BY ?item ?itemLabel ?itemDescription ?sitelink
LIMIT 50
}
SERVICE <http://dbpedia.org/sparql> {
SELECT DISTINCT ?item ?dbpediaID
FROM <http://dbpedia.org>
WHERE {
?dbpediaID owl:sameAs ?item .
}
}
} ;
-- Currently Fails with Like Operator error
-- Timeline Nobel Prize Winners
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SPARQL
SELECT ?t ?dbpediaID ?rrLabel ?valueLabel
{
SERVICE <http://query.wikidata.org/sparql>
{
SELECT DISTINCT ?t ?rrLabel ?valueLabel
WHERE
{
{
wd:Q151564 ?prop ?t FILTER (datatype(?t)=xsd:dateTime) .
?value wikibase:directClaim ?prop.
}
UNION
{
wd:Q151564 ?q ?statement FILTER regex (STR(?q),"prop/P") .
?statement ?p ?t FILTER regex (STR(?p), "prop/qualifier/P") FILTER (datatype(?t)=xsd:dateTime) .
?statement ?r ?value FILTER regex (STR(?r),"prop/statement/") .
BIND(IRI(CONCAT(CONCAT(SUBSTR(STR(?r),1,29),"direct/"),SUBSTR(STR(?r),40))) as ?rprop)
?rr wikibase:directClaim ?rprop .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
}
SERVICE <http://dbpedia.org/sparql> {
SELECT DISTINCT ?t ?dbpediaID
FROM <http://dbpedia.org>
WHERE {
?dbpediaID owl:sameAs ?t .
}
}
} ;
-- Universities Page Rankings
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX vrank: <http://purl.org/voc/vrank#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT ?uni AS ?wikiDataUni ?dbpediaUni ?uniLabel ?pr AS ?pageRank ?latitude ?longitude ?label ?dbpediaUni AS ?href ?label as ?name
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{
SELECT DISTINCT ?uni ?uniLabel ?pr WHERE {
?uni wdt:P31/(wdt:P279)* wd:Q3918.
SERVICE <http://dbpedia.org/sparql> {
?uni vrank:hasRank/vrank:rankValue ?pr
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
}
} ORDER BY DESC(?pr) LIMIT 100
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?dbpediaUni ?latitude ?longitude ?label
WHERE {
?dbpediaUni owl:sameAs ?uni ;
geo:lat ?latitude ;
geo:long ?longitude ;
rdfs:label ?label .
FILTER (LANG(?label) = "en")
}
ORDER BY DESC (?pr)
}
} ;
-- Awards by Gender
-- Currently Fails
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX vrank: <http://purl.org/voc/vrank#>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
SELECT DISTINCT *
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{
SELECT ?award ?awardLabel ?total ?women ?women_percentage
WHERE {
{
SELECT ?award (COUNT(*) AS ?total) (SUM(IF(?gender = wd:Q6581072, 1, 0)) AS ?women)
(ROUND(1000 / COUNT(*) * SUM(IF(?gender = wd:Q6581072, 1, 0))) / 10 AS ?women_percentage)
WHERE {
?human wdt:P166 ?award ; wdt:P21 ?gender ; wdt:P31 wd:Q5 .
}
GROUP BY ?award
ORDER BY DESC(?total)
LIMIT 200
}
?award rdfs:label ?awardLabel .
FILTER (LANG(?awardLabel) = "en") .
}
ORDER BY DESC(?total)
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?award
WHERE {
?dbpediaID owl:sameAs ?award .
}
}
}
-- Wikidata and SQID Example with DBpedia URI added
-- Returns empty solution due to no matches in DBpedia
SPARQL
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT DISTINCT ?ps ?dbpediaID
WHERE
{
SERVICE <http://query.wikidata.org/sparql>
{
SELECT ?it ?s ?p (SAMPLE(?pq) as ?pqs)
WHERE {
{ SELECT DISTINCT ?it ?s ?p {
?s ?ps wd:P735 . ?it ?pc ?s .
?p wikibase:statementProperty ?ps . ?p wikibase:claim ?pc .
FILTER( ?p != <http://www.wikidata.org/entity/P31> )
} LIMIT 101 }
OPTIONAL { ?s ?pq ?v . ?psub wikibase:qualifier ?pq }
}
GROUP BY ?it ?s ?p
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?ps
WHERE {
?dbpediaID owl:equivalentProperty ?ps .
}
}
}
-- Currently Fails
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SELECT *
WHERE { SERVICE <http://query.wikidata.org/sparql>
{ SELECT (SUM(?goals) as ?total_goals)
(SAMPLE(?height) as ?height)
(SAMPLE(xsd:date(?birthdate)) as ?bday)
WHERE { ?s wdt:P106 wd:Q937857 ;
p:P54 ?team_statement ;
wdt:P2048 ?height ;
wdt:P569 ?birthdate .
?team_statement pq:P1351 ?goals .
} GROUP BY ?s
}
} ;
-- Wikidata and DBpedia -- Butterflies
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SELECT ?species as ?wikiDataID ?dbpediaID ?image ?speciesLabel as ?name ?speciesLabel ?dbpediaID as ?href
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{
SELECT ?species ?speciesLabel ?image
WHERE {
?species wdt:P31 wd:Q16521; # taxon
wdt:P171* wd:Q28319; # in the Lepidoptera order
# wdt:P105/wdt:P361* wd:Q7432; # species or subdivision thereof
wdt:P183/wdt:P17 wd:Q664; # endemic to New Zealand
wdt:P18 ?image. # with image
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?dbpediaID
WHERE {
?dbpediaID owl:sameAs ?species .
}
}
} ;
-- Wikidata and DBpedia re. Monet
-- Fails
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
SELECT ?person as ?wikiDataID ?DBpediaID ?t ?value ?valueLabel ?rrLabel ?rr ?img as ?image ?DBpediaID as ?href ?rrLabel as ?name
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{
SELECT DISTINCT ?person ?t ?value ?valueLabel ?rrLabel ?rr (SAMPLE(?image) as ?img)
WHERE
{
VALUES ?person {wd:Q296}
{?person wdt:P570 ?death .
?person ?prop ?t FILTER (datatype(?t)=xsd:dateTime) FILTER (?t <= ?death) .
?value wikibase:directClaim ?prop. }
UNION
{
?person ?q ?statement FILTER regex (STR(?q),"prop/P") . #exclude P:describedBy
?person wdt:P570 ?death .
?statement ?p ?t FILTER regex (STR(?p), "prop/qualifier/P") FILTER (datatype(?t)=xsd:dateTime) FILTER (?t <= ?death).
?statement ?r ?value FILTER regex (STR(?r),"prop/statement/") .
BIND(IRI(CONCAT(CONCAT(SUBSTR(STR(?r),1,29),"direct/"),SUBSTR(STR(?r),40))) as ?rprop)
?rr wikibase:directClaim ?rprop .
OPTIONAL {?value wdt:P18 ?image}
}
UNION { # author of / creator of
?value wdt:P50|wdt:P98|wdt:P655|wdt:P1773|wdt:P170 ?person .
?person wdt:P570 ?death ;
wdt:P569 ?birth .
?value wdt:P571|wdt:P577 ?t .
FILTER ((?t <= ?death)&&(?t >= ?birth))
#FILTER NOT EXISTS {?value wdt:P629 ?x }
FILTER NOT EXISTS {?person wdt:P800 ?value } .
OPTIONAL {?value wdt:P1433 ?rr .}
OPTIONAL {?value wdt:P18 ?image .}
}
UNION #Notable Works
{
?person wdt:P800 ?rr ;
wdt:P570 ?death ;
wdt:P569 ?birth .
?rr wdt:P577|wdt:P571|wdt:P1191 ?t FILTER ((?t <= ?death)&&(?t >= ?birth)).
OPTIONAL {?rr wdt:P18 ?image .}
}
UNION #discoverer or inventor
{
?rr wdt:P61 ?person .
?person wdt:P570 ?death ;
wdt:P569 ?birth .
?rr wdt:P575|wdt:P571|wdt:P585 ?t FILTER ((?t <= ?death)&&(?t >= ?birth)).
OPTIONAL {?rr wdt:P18 ?image .}
}
UNION #architect
{
?rr wdt:P84 ?person .
?person wdt:P570 ?death ;
wdt:P569 ?birth .
?rr wdt:P571|wdt:P1619 ?t FILTER ((?t <= ?death)&&(?t >= ?birth)).
OPTIONAL {?rr wdt:P18 ?image .}
}
UNION #composer
{
?rr wdt:P86 ?person .
?person wdt:P570 ?death ;
wdt:P569 ?birth .
?rr wdt:P571|wdt:P1191|wdt:P577 ?t FILTER ((?t <= ?death)&&(?t >= ?birth)).
OPTIONAL {?rr wdt:P18 ?image .}
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en, fr, de". }
} GROUP BY ?person ?t ?value ?rr ?rrLabel ?valueLabel
ORDER BY ?t
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?dbpediaID
WHERE {
?dbpediaID owl:sameAs ?person .
}
}
} ;
## DBpedia and Wikidata Bible Illustrations
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?creator ?painting ?dbpediaPainting ?dbpediaCreator ?dbpediaCreatorName ?image ?name ?dbpediaPainting as ?href
WHERE {
SERVICE <http://query.wikidata.org/sparql>
{
SELECT ?creator ?painting count(?painting) as ?count
WHERE
{
?painting wdt:P31/wdt:P279* wd:Q4502142.
?painting wdt:P180 ?depicts.
?painting wdt:P170 ?creator.
?depicts wdt:P31/wdt:P279* wd:Q12405827 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?painting ?creator
HAVING (count(?painting) > 5)
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?dbpediaPainting ?dbpediaCreator ?dbpediaCreatorName ?image ?name
WHERE {
?dbpediaPainting owl:sameAs ?painting ;
rdfs:label ?name ;
foaf:depiction ?image .
FILTER (LANG(?name) = "en")
?dbpediaCreator owl:sameAs ?creator ;
rdfs:label ?dbpediaCreatorName .
FILTER (LANG(?dbpediaCreatorName) = "en")
}
}
} ;
## DBpedia and Wikidata Swiss Mountains
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?item ?dbpediaID as ?href xsd:string(?label) as ?name ?subjectName ?prominence ?image
WHERE
{
SERVICE <http://query.wikidata.org/sparql>
{
SELECT ?item ?itemLabel ?coord ?prominence ?layer ?image
WHERE {
?item wdt:P31 wd:Q8502. # a mountain
?item wdt:P625 ?coord.
?item wdt:P17 wd:Q39. # in Switzerland
?item wdt:P2660 ?prominence .
BIND(
IF(?prominence < 1000, "<1000 metres",
IF(?prominence < 2000, "1000 - 2000 metres",
IF(?prominence < 3000, "2000 - 3000 metres",
IF(?prominence < 4000, "3000 - 4000 metres",
"> 4000 metres"))))
AS ?layer).
OPTIONAL {?item wdt:P18 ?image.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
LIMIT 200
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?dbpediaID ?name ?label ?subjectName
WHERE {
?dbpediaID owl:sameAs ?item ;
rdfs:label ?label ;
dct:subject ?subject.
FILTER (LANG(?label) = "en")
?subject rdfs:label ?subjectName .
}
}
} ;
## DBpedia and Wikidata analysis of
## # ratio of female characters per fictional universe
# (assuming that any item with “from fictional universe” and “sex or gender” is a fictional character)
## Fails with empty solution
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dct: <http://purl.org/dc/terms/>
SELECT ?universe ?dbpediaUniverse ?universeLabel ?percentString ?females ?total
WHERE
{
SERVICE <http://query.wikidata.org/sparql>
{
SELECT ?universe ?universeLabel ?percentString ?females ?total WHERE { # add ?percent if you want to sort in the table
{
SELECT ?universe (SUM(?female) AS ?females) (COUNT(*) AS ?total) WHERE {
?character wdt:P1080 ?universe;
wdt:P21 ?gender.
BIND(IF(?gender IN (wd:Q6581072, wd:Q1052281), 1, 0) AS ?female)
}
GROUP BY ?universe
}
BIND(?females/?total AS ?ratio)
BIND(100*?ratio AS ?percent)
BIND(CONCAT(SUBSTR(STR(?percent), 1, 5), "%") AS ?percentString)
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY DESC(?total)
}
SERVICE <http://dbpedia.org/sparql>
{
SELECT DISTINCT ?dbpediaCharacter ?dbpediaUniverse
WHERE {
?dbpediaCharacter owl:sameAs ?character .
?dbpediaUniverse owl:sameAs ?universe .
}
}
} ;
## Birds from Wikidata
#defaultView:ImageGrid
SPARQL
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX schema: <http://schema.org/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX psn: <http://www.wikidata.org/prop/statement/value-normalized/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?item ?dbpediaID as ?href ?itemLabel as ?name ?image ?subjectName ?mainTaxonLabel
WHERE
{
SERVICE <http://query.wikidata.org/sparql>