SPARQL Update, Quadstores
Jakub Klímek
This work is licensed under a Creative Commons Attribution 4.0 International License.
SPARQL querying - read only
sis:stud1 sis:name "John" ;
sis:age 26 ;
rdf:type sis:Person .
sis:stud2 sis:name "Peter" ;
sis:age 30 ;
rdf:type sis:Person .
sis:stud3 sis:name "Martin" ;
sis:age 20 .
2
?stud rdf:type sis:Person ;
sis:name ?name ;
sis:age ?age .
?stud | ?name | ?age |
sis:stud1 | "John" | 26 |
sis:stud2 | "Peter" | 30 |
| | |
Solutions table
SPARQL Update
3
SPARQL Update - INSERT DATA
Query:
PREFIX ns: <https://example.org/ns#>
INSERT DATA
{ GRAPH <https://example/bookStore>
{ <https://example/book1> ns:price 42 }
}
Data after:
# Graph: https://example/bookStore
@prefix dct: <http://purl.org/dc/terms/> .
@prefix ns: <https://example.org/ns#> .
�<https://example/book1> � dct:title "Fundamentals of Compiler Design"@en ;
ns:price 42 .
Data before:
# Graph: https://example/bookStore
@prefix dct: <http://purl.org/dc/terms/> . �
<https://example/book1> dct:title "Fundamentals of Compiler Design"@en .
4
SPARQL Update - DELETE DATA
Query:
PREFIX dct: <http://purl.org/dc/terms/>
DELETE DATA {
GRAPH <https://example/bookStore> {
<https://example/book1> �dct:title "Fundamentals of Compiler Desing"@en }
} ;
PREFIX dct: <http://purl.org/dc/terms/>
INSERT DATA {
GRAPH <https://example/bookStore> {
<https://example/book1> �dct:title "Fundamentals of Compiler Design"@en }
}
Data before:
# Graph: https://example/bookStore
@prefix dct: <http://purl.org/dc/terms/> .
<https://example/book1> dct:title "Fundamentals of Compiler Desing"@en .
Data after:
# Graph: https://example/bookStore
@prefix dct: <https://purl.org/dc/terms/> .
<https://example/book1> dct:title "Fundamentals of Compiler Design"@en .
5
SPARQL Update - DELETE/INSERT
Query:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
DELETE { ?person ?property ?value }
WHERE {
?person ?property ?value ;
foaf:givenName "Fred"@en
}
Data before:
<http://example/william> a foaf:Person ;
foaf:givenName "William"@en ;
foaf:mbox <mailto:bill@example> .
<http://example/fred> a foaf:Person ;
foaf:givenName "Fred"@en ;
foaf:mbox <mailto:fred@example> .
Data after:
<http://example/william> a foaf:Person ;
foaf:givenName "William"@en ;
foaf:mbox <mailto:bill@example> .
6
SPARQL Update - WITH and USING
WITH <g1>
DELETE { a b c }
INSERT { x y z }
WHERE { ... }
�is equivalent to��DELETE { GRAPH <g1> { a b c } }
INSERT { GRAPH <g1> { x y z } }
USING <g1>
WHERE { ... }
7
SPARQL Update - DELETE WHERE shortcut
DELETE WHERE {
?person foaf:givenName "Fred"@en;
?property ?value
}
Only works when there is no
It is equivalent to:
DELETE {
?person foaf:givenName "Fred"@en;
?property ?value
}
WHERE {
?person foaf:givenName "Fred"@en;
?property ?value
}
8
SPARQL Update: Graph management
9
SPARQL Update - graph mgmt - operations
Operations on whole graphs
LOAD
<http://publications.europa.eu/resource/cellar/2b7cf737-fdd6-11ea-b44f-01aa75ed71a1.0001.05/DOC_1>
INTO GRAPH <http://publications.europa.eu/mdr/resource/authority/language>
�CLEAR GRAPH <http://publications.europa.eu/mdr/resource/authority/language>
CLEAR DEFAULT - clear all triples from the default graph
CLEAR ALL - clear all triples from all graphs in the graph store
CLEAR NAMED - clear all triples from all named graphs in the graph store
10
SPARQL Update - graph mgmt - operations
CREATE GRAPH, DROP GRAPH
For graph stores which can have an empty graph.
11
SPARQL Update - graph mgmt - operations
COPY GRAPH <http://publications.europa.eu/mdr/resource/authority/language> TO DEFAULT
MOVE GRAPH <http://publications.europa.eu/mdr/resource/authority/language> TO DEFAULT
ADD DEFAULT TO GRAPH <http://publications.europa.eu/mdr/resource/authority/language>
12
SPARQL Update - ADD GRAPH
Query:
ADD DEFAULT TO <https://example.org/named>
Data before:
# Default graph
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<https://example.org/william> a foaf:Person ;
foaf:givenName "William"@en ;
foaf:mbox <mailto:bill@example> .
# Graph https://example.org/named
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<https://example.org/fred> a foaf:Person .
Data after:
# Default graph
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<https://example.org/william> a foaf:Person ;
foaf:givenName "William"@en ;
foaf:mbox <mailto:bill@example> .
# Graph https://example.org/named
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<https://example.org/fred> a foaf:Person .
<https://example.org/william> a foaf:Person ;
foaf:givenName "William"@en ;
foaf:mbox <mailto:bill@example> .
13
Quadstores, triplestores, RDF databases
14
Quadstores, triplestores, RDF databases
Oldest, most used open-source RDF databases
15
OpenLink Virtuoso
16
Eclipse rdf4j
17
Apache Jena Fuseki
18
Triplestore implementations
Enterprise grade
19