This file contains hidden or 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
// there is also a projection of the results into the closure's binding | |
// if x, y, or z are not populated in the answer, then they are still valid binidng but are null | |
stardog.each("select ?x ?y ?z WHERE { ?x ?y ?z } LIMIT 2", { | |
println x | |
println y | |
println z // may be a LiteralImpl, so you get full access to manipulate Value objects | |
} | |
) |
This file contains hidden or 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
// insert and remove | |
stardog.insert([["urn:test3", "urn:test:predicate", "hello world"], | |
["urn:test4", "urn:test:predicate", "hello world2"]]) | |
stardog.remove(["urn:test3", "urn:test:predicate", "hello world"]) | |
stardog.remove(["urn:test4", "urn:test:predicate", "hello world2"]) |
This file contains hidden or 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
// withConnection, tx safe | |
stardog.withConnection { con -> | |
def queryString = """ | |
SELECT ?s ?p ?o | |
{ | |
?s ?p ?o | |
} | |
""" | |
TupleQueryResult result = null; | |
try { |
This file contains hidden or 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('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 ; |
This file contains hidden or 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.6') | |
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 ; |
This file contains hidden or 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
String uri = snarlTemplate.queryForObject(sparql, new RowMapper<String>() { | |
String mapRow(BindingSet b) { | |
return b.getValue("myQueryParameter") | |
} | |
}) | |
// OR | |
String result = snarlTemplate.queryForObject(sparql, new SingleMapper("b")); |
This file contains hidden or 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
def db = new Stardog(home:"/opt/stardog", url: "snarl://localhost:5820/",to:"testdb", username:"admin", password:"admin") | |
db.withConnection { Connection c -> | |
c.namespaces().add("ns", "http://mydomain/data/") | |
c.namespaces().add("dcterms", "http://purl.org/dc/terms/") | |
c.namespaces().add("org", "http://mydomain/org/") | |
c.namespaces().add("per", "http://mydomain/people/") | |
} | |
This file contains hidden or 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
(require '[pallet.compute :refer [instantiate-provider]]) | |
(require '[pallet.api :refer [group-spec server-spec node-spec plan-fn converge lift]]) | |
(require '[pallet.compute :refer [images]] | |
'[clojure.pprint :refer [pprint]]) | |
(require '[pallet.crate.java :as java]) | |
(require '[pallet.crate.automated-admin-user :refer [automated-admin-user]]) | |
(require '[pallet.actions :as pact]) | |
(def vmfest (instantiate-provider "vmfest" | |
:vbox-comm :ws)) |
This file contains hidden or 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
(defproject quickstart "0.1.0-SNAPSHOT" | |
:description "FIXME Pallet project for quickstart" | |
:dependencies [[org.clojure/clojure "1.5.1"] | |
[com.palletops/pallet "0.8.0-RC.3"] | |
[com.palletops/pallet-vmfest "0.3.0-beta.2"] | |
[com.palletops/pallet-docker "0.1.0"] | |
[com.palletops/app-deploy-crate "0.8.0-alpha.3"] | |
[com.palletops/runit-crate "0.8.0-alpha.1"] | |
[com.palletops/docker-crate "0.8.0-alpha.1"] | |
[com.palletops/java-crate "0.8.0-beta.5"] |
This file contains hidden or 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
SnarlTemplate tmp = new SnarlTemplate(); | |
tmp.setDataSource(dataSource); | |
String sparql = "DELETE { ?a ?b \"aloha world\" } INSERT { ?a ?b \"shalom world\" } WHERE { ?a ?b \"aloha world\" }"; | |
Map<String, Object> params = new HashMap<String, Object>() {{ | |
put("b", new URIImpl(uriB)); | |
}}; | |
// Execute the SPARQL Update query |