Skip to content

Instantly share code, notes, and snippets.

@AlBaker
Created March 3, 2014 18:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
@Grab('com.github.albaker:GroovySparql:0.7.2')
import groovy.sparql.*
// SPARQL 1.0 or 1.1 endpoint
def sparql = new Sparql(endpoint:"http://localhost:1234/testdb/query", user:"user", pass:"pass")
def query = "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 4"
// sparql result variables projected into the closure delegate
sparql.each query, {
println "${s} : ${p} : ${o}"
}
// Run an update query
def updateQuery = """
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT { <http://example/egbook> dc:title "This is an example title5" } WHERE {}
"""
sparql.update(updateQuery)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment