Skip to content

Instantly share code, notes, and snippets.

View AlBaker's full-sized avatar

Al Baker AlBaker

View GitHub Profile
@AlBaker
AlBaker / test.clj
Last active December 26, 2015 20:58
(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))
@AlBaker
AlBaker / StardogGroovyNamespaces.groovy
Created July 1, 2013 16:21
Use Stardog Groovy to add namespaces
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/")
}
@AlBaker
AlBaker / SNARLQueryForObjectExample.java
Last active December 18, 2015 10:48
SNARL Template queryForObject
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"));
@AlBaker
AlBaker / SampleSparql.groovy
Created February 9, 2013 22:19
Groovy Sparql released
@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 ;
@AlBaker
AlBaker / GroovySparqlExample.groovy
Last active December 12, 2015 02:38
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 ;
@AlBaker
AlBaker / StardogWithConnection.groovy
Created January 28, 2013 02:46
Stardog withConnection closure example
// withConnection, tx safe
stardog.withConnection { con ->
def queryString = """
SELECT ?s ?p ?o
{
?s ?p ?o
}
"""
TupleQueryResult result = null;
try {
@AlBaker
AlBaker / StardogAddRemove.groovy
Created January 28, 2013 02:44
Stardog Add and Remove triples example
// 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"])
@AlBaker
AlBaker / Projection.groovy
Created January 28, 2013 02:43
Stardog projection example
// 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
}
)
@AlBaker
AlBaker / StardogConnection.groovy
Last active December 11, 2015 19:59
Stardog Connection Example
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
@AlBaker
AlBaker / batchContext.xml
Created January 19, 2013 02:01
Stardog Spring Batch example
<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 &lt;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>