Skip to content

Instantly share code, notes, and snippets.

View AlBaker's full-sized avatar

Al Baker AlBaker

View GitHub Profile
@AlBaker
AlBaker / stardog-reasoning-explain.md
Last active June 18, 2017 21:14
Debugging with Stardog Reasoning Explain

What to do when you're knowledge graph seems to know something it shoulnd't? For example when subjects were coming back with a type relationship they shouldn't - stardog reasoning explain to the rescue:

$ stardog reasoning explain decomp "<https://example.org/id/1> a ns:MyType"
INFERRED <example.org/id/1> a ns:MyType
   ASSERTED ns1:linkedFrom rdfs:domain ns1:MyType
   INFERRED <https://example.org/id/1> ns1:linkedFrom i:1_1
      ASSERTED ns1:linkedFrom owl:inverseOf ns1:linkedRequirement
      ASSERTED i:1_1 ns1:linkedRequirement <https://example.org/id/1>
@AlBaker
AlBaker / core.clj
Last active March 24, 2017 13:57
Stardog-clj example
(ns stardog-clojure.core
(:require
[stardog.core :refer [insert! remove! update! query create-db-spec make-datasource
with-connection-pool with-transaction]]
[stardog.values :as values])
(:gen-class))
(defn db-spec
[database]
(create-db-spec database "http://localhost:5820/" "admin" "admin" true))
@AlBaker
AlBaker / gist:3037ab5eb56cbf59a272ef67387f019e
Created January 11, 2017 20:03 — forked from debasishg/gist:8172796
A collection of links for streaming algorithms and data structures
  1. General Background and Overview
@AlBaker
AlBaker / stardog-boot-clj-script.clj
Last active December 21, 2016 04:27
Using boot-clj with Stardog to create database scripts
#!/usr/bin/env boot
(set-env! :dependencies '[[org.clojure/clojure "1.8.0"]
[stardog-clj "4.2.1"]])
(require '[stardog.core :refer [insert! remove! query create-db-spec make-datasource
with-connection-pool with-transaction]])
;;; This script can be executed with ./script-name
;;; export BOOT_CLOJURE_VERSION=1.8.0
@AlBaker
AlBaker / pom.xml
Created August 10, 2016 00:03
POM file for stardog-groovy with spring-boot and groovy-maven-eclipse compiler
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<ivysettings>
<settings defaultResolver="downloadGrapes"/>
<resolvers>
<chain name="downloadGrapes" returnFirst="true">
<filesystem name="cachedGrapes">
<ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
<artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]"/>
</filesystem>
<!-- todo add 'endorsed groovy extensions' resolver here -->
@GrabResolver(name='stardog', root='http://maven.stardog.com/')
@Grab('com.complexible.stardog:stardog-groovy:3.1.4')
import com.complexible.stardog.ext.groovy.Stardog
def stardog = new Stardog([url: "snarl://localhost:5820/", to:"testdb", username:"admin", password:"admin", reasoning:true])
def list = []
stardog.query("select ?s ?p ?o WHERE { ?s a <http://www.lehigh.edu/~zhp2/2004/0401/univ-bench.owl#Person> }", { list << it } )
println list.size() // 719 using the Lehigh data set
@AlBaker
AlBaker / pom.xml
Created June 6, 2015 01:09
stardog project maven pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>stardog-maven</groupId>
<artifactId>stardog</artifactId>
<version>0.0.1-SNAPSHOT</version>
@Grab('com.complexible.stardog:stardog-groovy:3.0.0')
import com.complexible.stardog.ext.groovy.Stardog
def stardog = new Stardog([url: "snarl://localhost:5820/", to:"testdb", username:"admin", password:"admin", reasoning:true])
stardog.query("select ?x WHERE { ?x a <urn:SomeSubclass> } LIMIT 2", { println it } ) // <- Stardog answers the query with reasoned relationships!
@AlBaker
AlBaker / EmbeddedProvider.java
Last active August 29, 2015 14:13
Stardog Spring embedded server configuration
package com.complexible.stardog.ext.spring;
import com.complexible.common.protocols.server.ServerException;
import com.complexible.stardog.Stardog;
import com.complexible.stardog.StardogException;
import com.complexible.stardog.api.admin.AdminConnection;
import com.complexible.stardog.api.admin.AdminConnectionConfiguration;
import com.complexible.stardog.protocols.snarl.SNARLProtocolConstants;
public class EmbeddedProvider implements Provider {