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
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
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
@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
@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
// 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
// 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
// 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
def stardog = new Stardog([url: "snarl://localhost:5820/", to:"testdb", username:"admin", password:"admin"]) | |
stardog.query("select ?x ?y ?z WHERE { ?x ?y ?z } LIMIT 2", { println it } ) | |
// in this case, it is a BindingSet, ie TupleQueryResult.next() called until exhausted and closure executed | |
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
<bean id="snarlReader" class="com.clarkparsia.stardog.ext.spring.batch.SnarlItemReader" scope="step"> | |
<property name="dataSource" ref="dataSource"/> | |
<property name="query" value="SELECT ?a ?b WHERE { ?a <urn:test:predicate> ?b }"/> | |
<property name="rowMapper" ref="testRowMapper"/> | |
</bean> | |
<bean id="snarlWriter" class="com.clarkparsia.stardog.ext.spring.batch.SnarlItemWriter" scope="step"> | |
<property name="dataSource" ref="dataSource"/> | |
<property name="callback" ref="testBatchCallback"/> | |
</bean> |