Skip to content

Instantly share code, notes, and snippets.

@AlBaker
Last active December 12, 2015 02:38
Show Gist options
  • Save AlBaker/4700005 to your computer and use it in GitHub Desktop.
Save AlBaker/4700005 to your computer and use it in GitHub Desktop.
Using Groovy SPARQL with Dbpedia
@Grab('org.codehaus.groovy.sparql:groovy-sparql:0.5')
import groovy.sparql.*
def sparql = new Sparql(endpoint:"http://dbpedia.org/sparql")
def query = """
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX yago: <http://dbpedia.org/class/yago/>
SELECT ?president ?name WHERE {
?president a yago:PresidentsOfTheUnitedStates ;
foaf:name ?name
}
"""
sparql.eachRow query, { row ->
println "${row.president} is ${row.name}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment