1 of 19

SPARQL Update, Quadstores

Jakub Klímek

2 of 19

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

3 of 19

SPARQL Update

SPARQL can be used to update/delete data too!

SPARQL 1.1 Update

  • W3C Recommendation
  • 21 March 2013

3

4 of 19

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

5 of 19

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

6 of 19

SPARQL Update - DELETE/INSERT

  • remove and/or add triples
  • from/to the Quad Store
  • based on bindings for a graph pattern specified in WHERE clause

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

7 of 19

SPARQL Update - WITH and USING

  • WITH – "overrides" the default graph
  • USING – has the same function as FROM
    • Selects graphs to be used in the WHERE clause

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

8 of 19

SPARQL Update - DELETE WHERE shortcut

DELETE WHERE {

?person foaf:givenName "Fred"@en;

?property ?value

}

Only works when there is no

  • FILTER
  • BIND
  • etc.

It is equivalent to:

DELETE {

?person foaf:givenName "Fred"@en;

?property ?value

}

WHERE {

?person foaf:givenName "Fred"@en;

?property ?value

}

8

9 of 19

SPARQL Update: Graph management

9

10 of 19

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

11 of 19

SPARQL Update - graph mgmt - operations

CREATE GRAPH, DROP GRAPH

For graph stores which can have an empty graph.

  • equivalent to empty operation and CLEAR GRAPH elsewhere

11

12 of 19

SPARQL Update - graph mgmt - operations

COPY GRAPH <http://publications.europa.eu/mdr/resource/authority/language> TO DEFAULT

  • deletes target graph, copies all triples from source graph to it

MOVE GRAPH <http://publications.europa.eu/mdr/resource/authority/language> TO DEFAULT

  • deletes target graph, copies all triples from source graph to it, deletes source graph

ADD DEFAULT TO GRAPH <http://publications.europa.eu/mdr/resource/authority/language>

  • adds all triples from source graph to target graph

12

13 of 19

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

14 of 19

Quadstores, triplestores, RDF databases

14

15 of 19

Quadstores, triplestores, RDF databases

Oldest, most used open-source RDF databases

15

16 of 19

OpenLink Virtuoso

  • 2 branches
    • Commercial – Cluster edition - Virtuoso 8
    • Open-Source – Single server - Virtuoso 7
  • Virtuoso Conductor
  • SPARQL Endpoint: http://your.virtuoso.address:8890/sparql
  • SPARQL Update endpoint with login: http://your.virtuoso.address:8890/sparql-auth
  • Configuration: virtuoso.ini
  • Faceted browser: http://your.virtuoso.address:8890/fct
    • needs fct package installed via Conductor

16

17 of 19

Eclipse rdf4j

  • Open-source Framework for RDF and Linked Data
  • https://rdf4j.org/
  • Includes a triple store and SPARQL server
  • Deployed to servlet container – DB and workbench
    • Tomcat, Jetty, …

17

18 of 19

Apache Jena Fuseki

  • Apache Jena
    • Open-source Framework for RDF and Linked Data
  • TDB2
    • Part of Jena
    • Single-server triplestore
    • Access using Jena API
  • Fuseki
    • Part of Jena
    • SPARQL server using TDB2
    • Configured via Turtle file
    • http://your.fuseki.server:3030

18

19 of 19

Triplestore implementations

Enterprise grade

Open-Source

19