Skip to content

Instantly share code, notes, and snippets.

View AlBaker's full-sized avatar

Al Baker AlBaker

View GitHub Profile
@Grab('com.complexible.stardog:stardog-groovy:2.1.2')
import com.complexible.stardog.ext.groovy.Stardog
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 } )
@Grab('com.github.albaker:GroovySparql:0.7.2')
import groovy.sparql.*
// SPARQL 1.0 or 1.1 endpoint
def sparql = new Sparql(endpoint:"http://localhost:1234/testdb/query", user:"user", pass:"pass")
def query = "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 4"
// sparql result variables projected into the closure delegate
sparql.each query, {
<bean name="dataSource" class="com.complexible.stardog.ext.spring.DataSourceFactoryBean">
<property name="to" value="testdb"/>
<property name="username" value="admin"/>
<property name="password" value="admin"/>
<property name="reasoningType" value="QL"/>
</bean>
@AlBaker
AlBaker / CustomUser.clj
Created January 14, 2014 19:22
pallet EC2 config
{:aws {:provider "aws-ec2" :identity "ident"
:credential "cred" :environment {:user { :username "ubuntu" :private-key-path
"path/to/aws.pem" :public-key-path "path/to/aws.pub"}}}}
@AlBaker
AlBaker / StardogRules
Created December 30, 2013 16:32
Example of Stardog Rules
PREFIX swrlb: <http://www.w3.org/2003/11/swrlb#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
IF {
?x a :Person; hasAge ?age.
FILTER (?age >= 13 && ?age <= 19)
}
THEN {
?x a :Teenager.
}
@AlBaker
AlBaker / main.clj
Created December 22, 2013 17:57
Pallet Java Example Project
(ns pallet-java-example.main
(:use [clojure.tools.cli :only (cli)]
[clojure.pprint])
(:gen-class :main true)
(:require
[pallet.api :refer [group-spec server-spec node-spec plan-fn converge lift]]
[pallet.compute :refer [nodes images]]
[clojure.pprint :refer [pprint]]
[pallet.compute.vmfest :refer [add-image]]
[pallet.node :refer [group-name primary-ip]]
// Accepts the SPARQL Update queries
stardog.update("DELETE { ?a ?b \"hello world2\" } INSERT { ?a ?b \"aloha world2\" } WHERE { ?a ?b \"hello world2\" }")
def list = []
stardog.query("SELECT ?x ?y ?z WHERE { ?x ?y \"aloha world2\" } LIMIT 2", { list << it } )
assertTrue(list.size == 1)
String sparql = "ASK { ?a ?b \"aloha world\" }";
Map<String, Object> params = new HashMap<String, Object>() {{
put("b", new URIImpl(uriB));
}};
// SnarlTemplate returns boolean for ask
// Also parameter binding in the query is supported
boolean result = tmp.ask(sparql, params);
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
(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"]