Skip to content

Instantly share code, notes, and snippets.

View AlBaker's full-sized avatar

Al Baker AlBaker

View GitHub Profile
@AlBaker
AlBaker / sample.groovy
Created July 31, 2011 03:44
Linked Ratpack Sample
set 'port', 4999
// All three methods (RDFBuilder closure, construct, resolve) return
// Jena models and can be further processed with Groovy SPARQL's Sparql class
// link(String endpoint) returns the Sparql endpoint or you can instantiate new
// ones. Jena+ ARQ will be on the classpath
get("/") {
setHeader("Content-Type", "application/rdf+xml")
rdf.xml {
@AlBaker
AlBaker / Main.groovy
Created May 23, 2012 00:54
Executable War Main
package mypackage;
import java.net.URL;
import java.security.ProtectionDomain
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;
@AlBaker
AlBaker / build.gradle
Created June 24, 2012 04:22
StardogPetStore Build
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "eclipse-wtp"
apply plugin: "war"
apply plugin: "jetty"
def springVersion = "3.1.0.RELEASE"
def slf4jVersion = "1.6.1"
// TODO - change to wherever stardog is unzipped
def stardogLocation = "CHANGE"
@AlBaker
AlBaker / root-context.xml
Created June 24, 2012 04:26
StardogPetStore root application context
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<bean name="dataSource" class="com.clarkparsia.stardog.ext.spring.DataSourceFactoryBean">
<property name="to" value="petstore"/>
<property name="username" value="admin"/>
@AlBaker
AlBaker / build.gradle
Created August 22, 2012 23:52
Embedded Stardog packaging
apply plugin: "java"
apply plugin: "war"
def stardogLocation = "/some/path"
dependencies {
// To load up a DispatcherServlet
compile 'org.springframework:spring-web:3.1.2.RELEASE'
// gremlin in stardog/lib comes with groovy, we don't want to pick that up for gradle
compile fileTree(dir: stardogLocation, include: '**/*.jar', exclude: '**/*gremlin*/*')
@AlBaker
AlBaker / StardogExample.groovy
Last active December 10, 2015 07:48
Two lines of Stardog
def stardog = new Stardog([embedded:true, createIfNotPresent:true, home:"test/stardog", to:"testgroovy", 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
// as of Stardog-Groovy 0.2, there is now 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 / StardogSample.groovy
Last active December 10, 2015 15:19
Stardog Groovy DSL
def query = "select ?x ?y ?z WHERE { ?x ?y ?z } LIMIT 2"
builder.html {
head {
title "Report"
}
body {
stardog.each query, {
p "x: " + x
@AlBaker
AlBaker / SingleMapper.java
Last active December 11, 2015 07:58
Stardog-Spring SingleMapper example
String sparql = "SELECT ?b WHERE { ?a <http://purl.org/dc/elements/1.1/title> ?b } LIMIT 1";
String result = snarlTemplate.queryForObject(sparql, new SingleMapper("b"));
@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>
@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