This file contains 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
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 { |
This file contains 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
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; |
This file contains 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
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" |
This file contains 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
<?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"/> |
This file contains 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
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*/*') |
This file contains 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([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 |
This file contains 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 query = "select ?x ?y ?z WHERE { ?x ?y ?z } LIMIT 2" | |
builder.html { | |
head { | |
title "Report" | |
} | |
body { | |
stardog.each query, { | |
p "x: " + x |
This file contains 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 sparql = "SELECT ?b WHERE { ?a <http://purl.org/dc/elements/1.1/title> ?b } LIMIT 1"; | |
String result = snarlTemplate.queryForObject(sparql, new SingleMapper("b")); |
This file contains 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> |
This file contains 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 | |