Skip to content

Instantly share code, notes, and snippets.

@AlBaker
Created March 3, 2014 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlBaker/9331434 to your computer and use it in GitHub Desktop.
Save AlBaker/9331434 to your computer and use it in GitHub Desktop.
@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