-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
12329 lines (11846 loc) · 608 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<title>SPARQL 1.2 Query Language</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove"></script>
<script src="./common/local-biblio.js" class="remove"></script>
<script src="./common/fixup.js" class="remove"></script>
<script class="remove">
// All config options at https://respec.org/docs/
var respecConfig = {
group: "rdf-star" ,
localBiblio: localBibliography,
specStatus: "ED",
edDraftURI: "https://w3c.github.io/sparql-query/spec/",
testSuiteURI: "https://w3c.github.io/rdf-tests/",
shortName: "sparql12-query",
copyrightStart: "2008",
github: "https://github.com/w3c/sparql-query",
wgPublicList: "public-rdf-star-wg",
// implementationReportURI: "https://w3c.github.io/sparql12-query/reports/",
// errata: "https://w3c.github.io/sparql12-query/errata/",
previousPublishDate: "2013-03-21",
prevRecURI: "https://www.w3.org/TR/2013/REC-sparql11-query-20130321",
prevRecShortname: "sparql11-query",
previousMaturity: "REC",
editors: [
{ name: "Olaf Hartig", w3cid: "112469"},
{ name: "Andy Seaborne", w3cid: "29909" },
{ name: "Ruben Taelman", w3cid: "84199"},
{ name: "Gregory Williams", w3cid: "38870"},
{ name: "Thomas Pellissier Tanon", w3cid: "73758"},
],
formerEditors: [
{ name: "Steve Harris" },
{ name: "Andy Seaborne" },
{ name: "Eric Prud'hommeaux" },
],
//doJsonLd: true,
lint: { "no-unused-dfns": false }
};
</script>
<style>
/* @import url("local.css"); */
/* Inlined to make preview work */
/* CSS For SPARQL Query */
/* In-progress working draft artifacts - to be removed eventually */
.issue { background-color: #fdd;
font-size: 88% ; }
.add { background-color: #7fff7f }
.remove { background-color: #ff7f7f }
ul.issue {}
.issueBlock { margin: 1em 1em 1em 2.5em ; /* Top Right Bottom Left */
padding: 1ex;
/*overflow: auto;*/
page-break-inside: avoid ; }
.issueTopic { font-weight: bold ; }
.todo { font-size: 80% ; color: #444 ; }
p.todo {}
.wgNote { border: 0.2em solid red;
padding: 0.5em ;
margin: 1em 1em 1em 2em ; }
.box { border: thin solid #888888;
page-break-inside: avoid ;
background-color: #F8F8F8 ; padding:1em ;
margin-left:0 ; margin-right: 2ex;
margin-top: 0.1ex ; margin-bottom: 0.1ex ;
}
/* Misc WD stuff */
span.cvs-id {color: gray; font-size:80%; display: block; }
/* == General Tag Treatment == */
pre { margin: 1em 4em 1em 2.5em ; /* Top Right Bottom Left */
padding: 1ex;
/*overflow: auto;*/
page-break-inside: avoid ; }
/* Tables */
table, td { text-align: left; }
td, th { border-style: solid;
border-width: 1px;
border-color: black;
border-bottom-color: gray;
border-right-color: gray; }
td.annotation, th.annotation { border-style: none; border-bottom-style: dotted; }
table.plain { border-spacing: 0px; padding: 0px ; border-collapse: collapse ; }
/* cellpadding="0" cellspacing="1" style="border-collapse: collapse */
th.major { background-color: #005a9c;
color: white; }
.subHeading { text-align: left;
background-color: #CCCCCC; }
th, td { padding: 3px; }
td { font-size: 85%; }
th a:link { text-decoration: none; }
th a:hover { background-color:#FFFF99;
text-decoration: underline; }
/* == Prototypes == */
pre.prototype { background-color:#f7f8ff;
border:thin solid #8888aa;
margin: 1em 1em 1em 0em ; }
.return, .type { color: #177 }
/* Definitions */
.defn { margin-left:0 ; margin-right: 2ex;
margin-top: 0.1ex ; margin-bottom: 0.1ex ;
/*border: double 1px #888888; *//* Buggy */
border: thin solid #888888;
padding: 1ex 2ex 0.5ex 2ex ; /* top, right, bottom, left */
page-break-inside: avoid ;
background-color: #F0F8F8 ; }
div.defn p { margin-top: 1ex ; margin-bottom: 1.5ex ;}
div.defn ul { margin-top: 1ex ; margin-bottom: 1.5ex ; }
@media print { .defn { margin: 1em 1em 1em 1em ; } }
span.definedTerm {font-weight: bold;}
div.grammarExtract
{ border: thin solid #888888;
padding: 1ex 2ex 1ex 2ex ; /* top, right, bottom, left */
margin: 1em 6em 1em 2em ;
page-break-inside: avoid ;
background-color: #F8F8F8 ;
width: fit-content; }
pre.codeBlock { font-family:monospace ; page-break-inside: avoid ;
margin: 0 ;
margin-right: 2ex ;
border: thin solid #888888; }
/* Examples */
pre.data { border: thin solid #88AA88;
background-color: #E8F0E8;
margin: 1em 1em 1em 0em ; }
pre.dataExcerpt { border: thin solid #88AA88;
background-color: #E8F0E8;
margin: 1em 1em 1em 0em ; }
/* Example Queries */
.query { background-color:#f7f8ff; }
.queryExcerpt { background-color:#f7f8ff; }
pre.query { border:thin solid #8888aa;
margin: 1em 1em 1em 0em ; }
/* Example Results */
.result { border: thin solid #888888 ;
background-color: #F0F0F0 ; }
pre.resultGraph { margin: 0em 0em 0em 0em ; /* Top Right Bottom Left */
padding: 0ex;
font-size: 100% ;
page-break-inside: avoid ; }
pre.resultSet { margin: 0em 0em 0em 0em ; /* Top Right Bottom Left */
padding: 0ex;
font-size: 100% ;
page-break-inside: avoid ; }
pre.resultAsk { margin: 0em 0em 0em 0em ; /* Top Right Bottom Left */
padding: 0ex;
font-size: 100% ;
page-break-inside: avoid ; }
pre.resultTurtle{ margin: 0em 0em 0em 0em ; /* Top Right Bottom Left */
padding: 0ex;
font-size: 100% ;
page-break-inside: avoid ; }
pre.result { margin: 1em 1em 1em 0em ; }
div.result { font-family: monospace;
margin: 1em 1em 1em 0em ;
padding: 1ex ;}
.result table { border-collapse: collapse; }
.result table td{ border-width: 1px ;
border-color : black ;
font-family: monospace ;
empty-cells: show;
padding-left: 1ex ; padding-right: 1ex ;
vertical-align:top;
text-align: left ; }
/* spacing: 0 ;*/
.result table th{ border-width: 1px ;
font-family: monospace ;
border-color: black ;
empty-cells: show;
padding-left: 1ex ; padding-right: 1ex ;
vertical-align:top;
text-align:center; }
/* Examples : Algebra */
div.algExample { border: thin solid #888888;
page-break-inside: avoid ;
padding:0.5em ; margin:0.5em ;
margin-left: 2em ; margin-right: 2em ;
font-family:monospace ; }
div.algExample1 { padding:0.5em ; background-color: #F0F0FF ; }
div.algExample2 { padding:0.5em ; margin-top: 0.5em ; background-color: #F0FFF0 ; }
/* Grammar Mark-up */
.operator { color: #3f3f5f; }
.function { color: #3f3f5f; }
/* Tuned to cope with different browsers behaviours */
div.grammarTable table { border-style: solid ;
border-width: 1px ;
border-color: #AAA ;
border-spacing: 0px ;
border-collapse: collapse ; }
div.grammarTable table * { border-left-width: 0px ;
border-right-width: 0px ;
border-color: #AAA ; }
div.grammarTable table * tr { border-top-style: solid ;
border-top-width: 1px ;
border-top-color: #AAA ; }
.grammar { text-align: left ;
vertical-align: top ; }
.token { color: #3f3f5f; }
table.FAndOTable .token { color: #00c; }
table.FAndOTable .token:visited { color: #a0c; }
.gRuleHead { font-style: italic ;
font-family: monospace ; }
.gRuleBody { font-family: monospace ; }
.gRuleLabel { font-family: monospace ; }
.code { font-family: monospace; font-size: 100%; }
pre.code { font-family: monospace; font-size: 100%; margin: 0 ; }
/* Table of Contents */
.toc { text-indent: 0; }
/* References to the Rdf Data Model */
span.rdfDM { color: #11d; }
/* Truth Table */
.truth { font-family: monospace; }
.error { color: #ff1f1f; }
table.truthTable td { text-align: center; font-family: monospace; }
table.truthTable th { background-color: #dfdfdf; }
table.truthTable tbody th { font-weight: normal; font-family: monospace; }
/* Casting table */
table.casting { font-size: x-small; }
.castY { background-color: #7FFF7F;
color: black; }
.castN { background-color: #FF7F7F;
color: black; }
.castM { background-color: white;
color: black; }
span.cancast:hover { background-color: #ffa;
color: black; }
.SPARQLoperator { background-color: #FFFFbf; /* yellow */
}
.owlnonterminal {
font-weight: bold;
font-family: sans-serif;
font-size: 95%;
}
.owlgrammar {
margin-top: 1ex;
margin-bottom: 1ex;
padding-left: 1ex;
padding-right: 1ex;
padding-top: 1ex;
padding-bottom: 0.6ex;
border: 1px dashed #2f6fab;
font-family: monospace;
}
/* ReSpec */
dfn { font-style: normal ; }
/* ReSpec */
code { font-family: monospace; }
div.constraint,
div.issue,
div.notice { margin-left: 2em; }
ol.enumar { list-style-type: decimal; }
ol.enumla { list-style-type: lower-alpha; }
ol.enumlr { list-style-type: lower-roman; }
ol.enumua { list-style-type: upper-alpha; }
ol.enumur { list-style-type: upper-roman; }
div.exampleInner pre { margin-left: 1em;
margin-top: 0em; margin-bottom: 0em}
div.exampleOuter {border: 4px double gray;
margin: 0em; padding: 0em}
div.exampleInner { background-color: #d5dee3;
border-top-width: 4px;
border-top-style: double;
border-top-color: #d3d3d3;
border-bottom-width: 4px;
border-bottom-style: double;
border-bottom-color: #d3d3d3;
padding: 4px; margin: 0em }
div.exampleWrapper { margin: 4px }
div.exampleHeader { font-weight: bold;
margin: 4px}
@media (max-width: 850px) {
table th, table td { font-size: 12px; padding: 3px 4px;}
.result table tr td:nth-child(2n), .result table tr th:nth-child(2n) { overflow-wrap: anywhere; min-width: 90px; }
div.result { overflow-x: scroll; width: fit-content; max-width: 100%; }
pre.query { margin: 1em 1em 1em 0em; }
}
@media (max-width: 767px) {
table { word-break: normal; overflow-wrap: anywhere; }
.FAndOTable { overflow-x: scroll; display: block; max-width: 100% }
.grammarTable { overflow-x: scroll; }
.grammarTable table tr td:last-child { overflow-wrap: anywhere!important; }
}
</style>
</head>
<body>
<section id="abstract">
<h2>Abstract</h2>
<p>
RDF is a directed, labeled graph data model for representing information in the
Web. This specification defines the syntax and semantics of the SPARQL Query Language for
RDF. SPARQL can be used to express queries across diverse data sources, whether the data is
stored natively as RDF or viewed as RDF via middleware. SPARQL contains capabilities for
querying required and optional graph patterns along with their conjunctions and
disjunctions. SPARQL also supports aggregation, subqueries, negation, creating values by
expressions, extensible value testing, and constraining queries by source RDF graph. The results
of SPARQL queries can be result sets or RDF graphs.
</p>
</section>
<section id="sotd" class="introductory updateable-rec">
<p>
This specification is published by the
<a href="https://www.w3.org/groups/wg/rdf-star">RDF Star Working Group</a> as part of the
update of specifications for format and errata.
</p>
<section id="related" data-include="common/sparql-related.html"></section>
</section>
<!-- BODY -->
<section id="introduction">
<h2>Introduction</h2>
<p>
RDF is a directed, labeled graph data model for representing information in the Web. RDF is
often used to represent, among other things, personal information, social networks, metadata
about digital artifacts, as well as to provide a means of integration over disparate sources of
information. This specification defines the syntax and semantics of the SPARQL Query Language
for RDF.
</p>
<p>
The SPARQL Query Language for RDF is designed to meet the use cases and
requirements identified by the RDF Data Access Working Group in [[RDF-DAWG-UC]],
the SPARQL 1.1 Working Group in [[SPARQL-FEATURES]], and the RDF-star Working Group.
</p>
<section id="docOutline">
<h3>Document Outline</h3>
<p>
Unless otherwise noted in the section heading, all sections and appendices in this
document are normative.
</p>
<p>
This section of the document, <a href="#introduction">section 1</a>, introduces the SPARQL
Query Language specification. It presents the organization of this specification document and
the conventions used throughout the specification.
</p>
<p>
<a href="#basicpatterns">Section 2</a> of the specification introduces the SPARQL query
language itself via a series of example queries and query results.
<a href="#termConstraint">Section 3</a> continues the introduction of the SPARQL query language with
more examples that demonstrate SPARQL's ability to express constraints on the RDF terms that
appear in a query's results.
</p>
<p>
<a href="#sparqlSyntax">Section 4</a> presents details of the SPARQL query language's
syntax. It is a companion to the full grammar of the language and defines how grammatical
constructs represent IRIs, blank nodes, literals, and variables. Section 4 also defines the
meaning of several grammatical constructs that serve as syntactic sugar for more verbose
expressions.
</p>
<p>
<a href="#GraphPattern">Section 5</a> introduces basic graph patterns and group graph
patterns, the building blocks from which more complex SPARQL query patterns are constructed.
Sections 6, 7, and 8 present constructs that combine SPARQL graph patterns into larger graph
patterns. In particular, <a href="#optionals">Section 6</a> introduces the ability to make
portions of a query optional; <a href="#alternatives">Section 7</a> introduces the ability to
express the disjunction of alternative graph patterns; and <a href="#negation">Section 8</a>
introduces patterns to test for the absense of information.
</p>
<p>
<a href="#propertypaths">Section 9</a> adds property paths to graph pattern matching,
giving a compact representation of queries and also the ability to match arbitrary length
paths in the graph.
</p>
<p>
<a href="#assignment">Section 10</a> describes the forms of assignment possible
in SPARQL.
</p>
<p>
<a href="#aggregates">Sections 11</a> introduces the mechanism to group and
aggregate results, which can be incorporated as subqueries as described
in <a href="#subqueries">Section 12</a>.
</p>
<p>
<a href="#rdfDataset">Section 13</a> introduces the ability to constrain
portions of a query to particular source graphs. Section 13 also presents
SPARQL's mechanism for defining the source graphs for a query.
</p>
<p>
<a href="#basic-federated-query">Section 14</a> refers to the separate document
[[[SPARQL11-FEDERATED-QUERY]]].
</p>
<p>
<a href="#solutionModifiers">Section 15</a> defines the constructs that affect
the solutions of a query by ordering, slicing, projecting, limiting, and
removing duplicates from a sequence of solutions.
</p>
<p>
<a href="#QueryForms">Section 16</a> defines the four types of SPARQL queries
that produce results in different forms.
</p>
<p>
<a href="#expressions">Section 17</a> defines SPARQL's extensible value testing
and expression framework. It presents the functions and operators that can be
used to constrain the values that appear in a query's results and also calculate
new values to be returned by a query.
</p>
<p>
<a href="#sparqlDefinition">Section 18</a> is a formal definition of the
evaluation of SPARQL graph patterns and solution modifiers.
</p>
<p>
<a href="#grammar">Section 19</a> contains the normative definition of the syntax for the
SPARQL query and [[[SPARQL11-UPDATE]]] languages, as given by a grammar expressed in EBNF
notation.
</p>
</section>
<section id="docConventions">
<h3>Document Conventions</h3>
<section id="docNamespaces">
<h4>Namespaces</h4>
<p>In this document, examples assume the following namespace prefix bindings unless
otherwise stated:</p>
<div style="text-align: center;">
<table style="border-collapse: collapse; border-color: #000000; border-spacing: 5px; border-width: 1px">
<tbody>
<tr>
<th>Prefix</th>
<th>IRI</th>
</tr>
<tr>
<td><code>rdf:</code></td>
<td><code>http://www.w3.org/1999/02/22-rdf-syntax-ns#</code></td>
</tr>
<tr>
<td><code>rdfs:</code></td>
<td><code>http://www.w3.org/2000/01/rdf-schema#</code></td>
</tr>
<tr>
<td><code>xsd:</code></td>
<td><code>http://www.w3.org/2001/XMLSchema#</code></td>
</tr>
<tr>
<td><code>fn:</code></td>
<td><code>http://www.w3.org/2005/xpath-functions#</code></td>
</tr>
<tr>
<td><code>sfn:</code></td>
<td><code>http://www.w3.org/ns/sparql#</code></td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="docDataDesc">
<h4>Data Descriptions</h4>
<p>This document uses the [[[TURTLE]]] [[TURTLE]] data format to show each triple
explicitly. Turtle allows IRIs to be abbreviated with prefixes:</p>
<pre class="data nohighlight">
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://example.org/book/>
:book1 dc:title "SPARQL Tutorial" .
</pre>
</section>
<section id="docResultDesc">
<h4>Result Descriptions</h4>
<p>Result sets are illustrated in tabular form.</p>
<div class="result">
<div id="table39"></div>
<table class="resultTable">
<tbody>
<tr>
<th>x</th>
<th>y</th>
<th>z</th>
</tr>
<tr>
<td>"Alice"</td>
<td><code><http://example/a></code></td>
<td> </td>
</tr>
</tbody>
</table>
</div>
<p>A 'binding' is a pair (<a href="#defn_QueryVariable">variable</a>,
<a data-cite="RDF12-CONCEPTS#dfn-rdf-term">RDF term</a>).
In this result set, there are three variables:
<code>x</code>, <code>y</code> and <code>z</code> (shown as column headers). Each solution
is shown as one row in the body of the table. Here, there is a single solution, in
which variable <code>x</code> is bound to <code>"Alice"</code>, variable <code>y</code> is
bound to <code><http://example/a></code>, and variable <code>z</code> is not bound to
an RDF term. Variables are not required to be bound in a solution.</p>
</section>
<section id="docTerminology">
<h4>Terminology</h4>
<p>The SPARQL language includes IRIs.
Note that all IRIs in SPARQL queries are absolute; they may or may not include a fragment
identifier [[RFC3987]], section 3.1. IRIs include URIs [[RFC3986]] and URLs. The abbreviated
forms (<a href="#QSynIRI">relative IRIs and prefixed names</a>) in the SPARQL syntax are
resolved to produce absolute IRIs.</p>
<p>The following terms are defined in [[[RDF12-CONCEPTS]]] [[RDF12-CONCEPTS]] and used in
SPARQL:</p>
<ul>
<li>
<a data-cite="RDF12-CONCEPTS#dfn-iri">IRI</a>
</li>
<li>
<a data-cite="RDF12-CONCEPTS#dfn-literal">literal</a>
</li>
<li>
<a data-cite="RDF12-CONCEPTS#dfn-lexical-form">lexical form</a>
</li>
<li>
<a data-cite="RDF12-CONCEPTS#dfn-language-tag">language tag</a>
</li>
<li>
<a data-cite="RDF12-CONCEPTS#dfn-datatype-iri">datatype IRI</a>
</li>
<li>
<a data-cite="RDF12-CONCEPTS#dfn-blank-node">blank node</a>
</li>
<li>
<a data-cite="RDF12-CONCEPTS#dfn-rdf-term">RDF term</a>
</li>
</ul>
<p>
Blank node identifiers are
<a data-cite="?RDF12-CONCEPTS#note-bnode-id">part of
SPARQL and RDF concrete serializations</a>.
In this document, the syntax form "<code>_:abc</code>" is used where the
<a data-cite="RDF12-CONCEPTS#dfn-blank-node-identifier">blank node identifier</a>
is <code>abc</code>. and the "<code>_:</code>" is
the Turtle and SPARQL syntax used to introduce blank nodes with
identifiers.
</p>
</section>
</section>
</section>
<section id="basicpatterns">
<h2>Making Simple Queries (Informative)</h2>
<p>Most forms of SPARQL query contain a set of triple patterns called a <em>basic graph
pattern</em>. Triple patterns are like RDF triples except that each of the subject, predicate
and object may be a variable. A basic graph pattern <em>matches</em> a subgraph of the RDF data
when an <a data-cite="RDF12-CONCEPTS#dfn-rdf-term">RDF term</a> from that subgraph may be substituted for the
variables and the result is RDF graph equivalent to the subgraph.</p>
<section id="WritingSimpleQueries">
<h3>Writing a Simple Query</h3>
<p>The example below shows a SPARQL query to find the title of a book from the given data
graph. The query consists of two parts: the <code>SELECT</code> clause identifies the
variables to appear in the query results, and the <code>WHERE</code> clause provides the
basic graph pattern to match against the data graph. The basic graph pattern in this example
consists of a single triple pattern with a single variable (<code>?title</code>) in the
object position.</p>
<div class="exampleGroup">
<p>Data:</p>
<pre class="data nohighlight">
<http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> "SPARQL Tutorial" .</pre>
<div class="queryGroup">
<p>Query:</p>
<pre class="query nohighlight">
SELECT ?title
WHERE
{
<http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> ?title .
}
</pre>
<p>This query, on the data above, has one solution:</p>
<p>Query Result:</p>
<div class="result">
<div id="table109"></div>
<table class="resultTable">
<tbody>
<tr>
<th>title</th>
</tr>
<tr>
<td>"SPARQL Tutorial"</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section id="MultipleMatches">
<h3>Multiple Matches</h3>
<p>The result of a query is a <a href="#defn_sparqlSolutionSequence">solution sequence</a>,
corresponding to the ways in which the query's graph pattern matches the data. There may be
zero, one or multiple solutions to a query.</p>
<p>Data:</p>
<div class="exampleGroup">
<pre class="data nohighlight">PREFIX foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Johnny Lee Outlaw" .
_:a foaf:mbox <mailto:[email protected]> .
_:b foaf:name "Peter Goodguy" .
_:b foaf:mbox <mailto:[email protected]> .
_:c foaf:mbox <mailto:[email protected]> .
</pre>
<p>Query:</p>
<div class="queryGroup">
<pre class="query nohighlight">
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE
{ ?x foaf:name ?name .
?x foaf:mbox ?mbox }
</pre>
<p>Query Result:</p>
<div class="result">
<table class="resultTable">
<tbody>
<tr>
<th>name</th>
<th>mbox</th>
</tr>
<tr>
<td>"Johnny Lee Outlaw"</td>
<td><mailto:[email protected]></td>
</tr>
<tr>
<td>"Peter Goodguy"</td>
<td><mailto:[email protected]></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>Each solution gives one way in which the selected variables can be bound to RDF terms so
that the query pattern matches the data. The result set gives all the possible solutions. In
the above example, the following two subsets of the data provided the two matches.</p>
<pre class="data nohighlightExcerpt">
_:a foaf:name "Johnny Lee Outlaw" .
_:a foaf:box <mailto:[email protected]> .
</pre>
<pre class="data nohighlightExcerpt">
_:b foaf:name "Peter Goodguy" .
_:b foaf:box <mailto:[email protected]> .
</pre>
<p>This is a <a href="#BGPsparql">basic graph pattern match</a>; all the variables used in
the query pattern must be bound in every solution.</p>
</section>
<section id="matchingRDFLiterals">
<h3>Matching RDF Literals</h3>
<p>The data below contains three RDF literals:</p>
<div class="exampleGroup">
<pre class="data nohighlight">
PREFIX dt: <http://example.org/datatype#>
PREFIX ns: <http://example.org/ns#>
PREFIX : <http://example.org/ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
:x ns:p "cat"@en .
:y ns:p "42"^^xsd:integer .
:z ns:p "abc"^^dt:specialDatatype .
</pre>
<p>Note that, in Turtle, <code>"cat"@en</code> is an RDF literal with a lexical form "cat"
and a language tag "en"; <code>"42"^^xsd:integer</code> is a literal with the
datatype <code>http://www.w3.org/2001/XMLSchema#integer</code>; and
<code>"abc"^^dt:specialDatatype</code> is a literal with the datatype
<code>http://example.org/datatype#specialDatatype</code>.</p>
</div>
<p>This RDF data is the data graph for the query examples in sections 2.3.1–2.3.3.</p>
<section id="matchLangTags">
<h4>Matching Literals with Language Tags</h4>
<p>Language tags in SPARQL are expressed using <code>@</code> and the language tag, as
defined in [[[BCP47]]] [[BCP47]].</p>
<p>This following query has no solution because <code>"cat"</code> is not the same RDF
literal as <code>"cat"@en</code>:</p>
<div class="queryGroup">
<pre class="query nohighlight">SELECT ?v WHERE { ?v ?p "cat" }</pre>
<div class="result">
<table class="resultTable">
<tbody>
<tr>
<th> v </th>
</tr>
</tbody>
</table>
</div>
<p>but the query below will find a solution where variable <code>v</code> is bound to
<code>:x</code> because the language tag is specified and matches the given data:</p>
<pre class="query nohighlight">SELECT ?v WHERE { ?v ?p "cat"@en }
</pre>
<div class="result">
<table class="resultTable">
<tbody>
<tr>
<th>v</th>
</tr>
<tr>
<td><http://example.org/ns#x></td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
<section id="matchNumber">
<h4>Matching Literals with Numeric Types</h4>
<p>Integers in a SPARQL query indicate an RDF literal with the datatype
<code>xsd:integer</code>. For example: <code>42</code> is a shortened form of
<code>"42"^^<http://www.w3.org/2001/XMLSchema#integer></code>.</p>
<p>The pattern in the following query has a solution with variable <code>v</code> bound to
<code>:y</code>.</p>
<div class="queryGroup">
<pre class="query nohighlight">SELECT ?v WHERE { ?v ?p 42 }
</pre>
<div class="result">
<div id="table60"></div>
<table class="resultTable">
<tbody>
<tr>
<th>v</th>
</tr>
<tr>
<td><http://example.org/ns#y></td>
</tr>
</tbody>
</table>
</div>
</div>
<p><a href="#QSynLiterals">Section 4.1.2</a> defines SPARQL shortened forms for
<code>xsd:float</code> and <code>xsd:double</code>.</p>
</section>
<section id="matchArbDT">
<h4>Matching Literals with Arbitrary Datatypes</h4>
<p>The following query has a solution with variable <code>v</code> bound to
<code>:z</code>. The query processor does not have to have any understanding of the values
in the space of the datatype. Because the lexical form and datatype IRI both match, the
literal matches.</p>
<div class="queryGroup">
<pre class="query nohighlight">
SELECT ?v WHERE { ?v ?p "abc"^^<http://example.org/datatype#specialDatatype> }
</pre>
<div class="result">
<div id="table61"></div>
<table class="resultTable">
<tbody>
<tr>
<th>v</th>
</tr>
<tr>
<td><http://example.org/ns#z></td>
</tr>
</tbody>
</table>
</div>
</div>
</section>
</section>
<section id="BlankNodesInResults">
<h3>Blank Node Identifiers in Query Results</h3>
<p>
Query results can contain blank nodes. Blank nodes in the example
result sets in this document are written in the form "_:" followed by a
<a data-cite="RDF12-CONCEPTS#dfn-blank-node-identifier">blank node identifier</a>.
</p>
<p>Blank node identifiers are scoped to a result set (see "[[[RDF-SPARQL-XMLRES]]]" and
"[[[SPARQL11-RESULTS-JSON]]]") or, for the <code>CONSTRUCT</code> query form, the result
graph. Use of the same identifier within a result set indicates the same blank node.</p>
<div class="exampleGroup">
Data:
<pre class="data nohighlight">
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
_:a foaf:name "Alice" .
_:b foaf:name "Bob" .
</pre>
<div class="queryGroup">
Query:
<pre class="query nohighlight">
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?x ?name
WHERE { ?x foaf:name ?name }
</pre>
<div class="result">
<div id="table56"></div>
<table class="resultTable">
<tbody>
<tr>
<th>x</th>
<th>name</th>
</tr>
<tr>
<td>_:c</td>
<td>"Alice"</td>
</tr>
<tr>
<td>_:d</td>
<td>"Bob"</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>
The results above could equally be given with different blank node
identifiers because the blank node identifiers in the results only
indicate whether RDF terms in the solutions are the same or
different.
</p>
<div class="result">
<div id="table57"></div>
<table class="resultTable">
<tbody>
<tr>
<th>x</th>
<th>name</th>
</tr>
<tr>
<td>_:r</td>
<td>"Alice"</td>
</tr>
<tr>
<td>_:s</td>
<td>"Bob"</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>
These two results have the same information: the blank nodes used to
match the query are different in the two solutions. There need not be
any relation between a blank node identifier
<code>_:a</code> in the result set and a blank node identifier
used in the syntax for the data.
</p>
<p>
An application writer should not expect blank node identifiers in a
query to refer to a particular blank node in the data.
</p>
</section>
<section id="CreatingValuesWithExpressions">
<h3>Creating Values with Expressions</h3>
<p>SPARQL 1.2 allows values to be created from complex expressions. The queries below show how
the <a href="#func-concat">CONCAT</a> function can be used to concatenate first names and
last names from FOAF data, then assign the value using an
<a href="#selectExpressions">expression in the <code>SELECT</code> clause</a> and also assign the
value by using the <a href="#bind">BIND</a> form.</p>
<div class="exampleGroup">
Data:
<pre class="data nohighlight">
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
_:a foaf:givenName "John" .
_:a foaf:surname "Doe" .
</pre>
<div class="queryGroup">
Query:
<pre class="query nohighlight">
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ( CONCAT(?G, " ", ?S) AS ?name )
WHERE { ?P foaf:givenName ?G ; foaf:surname ?S }
</pre>
Query:
<pre class="query nohighlight">
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
?P foaf:givenName ?G ;
foaf:surname ?S
BIND(CONCAT(?G, " ", ?S) AS ?name)
}
</pre>
<div class="result">
<div id="table59"></div>
<table class="resultTable">
<tbody>
<tr>
<th>name</th>
</tr>
<tr>
<td>"John Doe"</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<section id="constructGraph">
<h3>Building RDF Graphs</h3>
<p>SPARQL has several <a href="#QueryForms">query forms</a>. The <code>SELECT</code> query
form returns variable bindings. The <code>CONSTRUCT</code> query form returns an RDF graph.
The graph is built based on a template which is used to generate RDF triples based on the
results of matching the graph pattern of the query.</p>
<div class="exampleGroup">
<p>Data:</p>
<pre class="data nohighlight">
PREFIX org: <http://example.com/ns#>
_:a org:employeeName "Alice" .
_:a org:employeeId 12345 .
_:b org:employeeName "Bob" .
_:b org:employeeId 67890 .
</pre>
<div class="queryGroup">
<p>Query:</p>
<pre class="query nohighlight">
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX org: <http://example.com/ns#>
CONSTRUCT { ?x foaf:name ?name }
WHERE { ?x org:employeeName ?name }
</pre>
<p>Results:</p>
<div class="result">
<pre class="resultGraph">
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
_:x foaf:name "Alice" .
_:y foaf:name "Bob" .
</pre>
</div>
</div>
<p>which can be serialized in <a data-cite="RDF12-XML#">RDF/XML</a> as:</p>
<div class="result">
<pre class="resultGraph" style="text-align: left;">
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/" >
<rdf:Description>
<foaf:name>Alice</foaf:name>
</rdf:Description>
<rdf:Description>
<foaf:name>Bob</foaf:name>
</rdf:Description>
</rdf:RDF>
</pre>
</div>
</div>
</section>
</section>
<section id="termConstraint">
<h2>RDF Term Constraints (Informative)</h2>
<p>Graph pattern matching produces a solution sequence, where each solution has a set of
bindings of variables to RDF terms. SPARQL <code>FILTER</code>s restrict solutions to those for
which the filter expression evaluates to <code>TRUE</code>.</p>
<p>This section provides an informal introduction to SPARQL <code>FILTER</code>s; their
semantics are defined in section '<a href="#expressions">Expressions and Testing Values</a>'
where there is a <a href="#SparqlOps">comprehensive function library</a>. The examples in this
section share one input graph:</p>