This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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