Skip to content

Instantly share code, notes, and snippets.

View mhgrove's full-sized avatar

Michael Grove mhgrove

View GitHub Profile
@mhgrove
mhgrove / Example01_CreateOntology.java
Created December 6, 2010 20:16
Example programs using Ortiz, Pellet 3.0's new native API for OWL
package com.clarkparsia.pellet.examples;
import java.io.IOException;
import java.io.PrintWriter;
import com.clarkparsia.pellet.api.kb.Ontology;
import com.clarkparsia.pellet.api.kb.OntologyFactory;
import com.clarkparsia.pellet.api.kb.OntologySyntax;
import com.clarkparsia.pellet.api.term.TermFactory;
import com.clarkparsia.pellet.api.term.entity.NamedClass;
@mhgrove
mhgrove / Server2.java
Created August 20, 2013 11:52
Netty HTTP Streaming Bug
// Copyright (c) 2010 - 2013, Clark & Parsia, LLC. <http://www.clarkparsia.com>
// For more information about licensing and copyright of this software, please contact
// inquiries@clarkparsia.com or visit http://stardog.com
package netty;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@mhgrove
mhgrove / LocalEcho.java
Last active December 21, 2015 10:58
Modified LocalEcho class which demonstrates the name collision in LocalAddress
package netty;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
@mhgrove
mhgrove / HttpStaticFileServerHandler.java
Created September 6, 2013 14:11
ByteBufHttpOutputStream
public static final class ByteBufHttpOutputStream extends OutputStream {
/**
* The channel to which the {@link ByteBuf} objects are written
*/
private final ChannelHandlerContext mChannelHandlerContext;
/**
* The {@link ByteBuf} to which data is currently being written
*/
@Override
public void channelRead0(
ChannelHandlerContext ctx, FullHttpRequest request) throws Exception {
if (!request.getDecoderResult().isSuccess()) {
sendError(ctx, BAD_REQUEST);
return;
}
if (request.getMethod() != GET) {
sendError(ctx, METHOD_NOT_ALLOWED);
// this is where we'll store our constraints
Sail aConstraints = new MemoryStore();
aConstraints.initialize();
// more specifically, we'll store them in a particular named graph
URI aConstraintGraph = Values.iri("urn:icv");
// and here is our database. note this can be *any* type of Repository
Repository aRepo = new SailRepository(new MemoryStore());
@mhgrove
mhgrove / gist:2952a69d54397b46f17e
Last active February 11, 2016 14:27
query example
mhgrove:dist mhgrove$ ./bin/stardog-admin db create -n foo
Successfully created database 'foo'.
mhgrove:dist mhgrove$ ./bin/stardog query foo "insert data { graph <tag:stardog:api:context:equipment> { <urn:a> <urn:b> <urn:c> } . graph <tag:stardog:api:context:phase-of-development> { <urn:d> <urn:e> <urn:f> } }"
Update query processed successfully in 00:00:00.147.
mhgrove:dist mhgrove$ ./bin/stardog data export foo --format NQUADS
<urn:a> <urn:b> <urn:c> <tag:stardog:api:context:equipment> .
<urn:d> <urn:e> <urn:f> <tag:stardog:api:context:phase-of-development> .
mhgrove:dist mhgrove$ ./bin/stardog query foo "SELECT ?s ?p ?o
> WHERE {
@mhgrove
mhgrove / CreateReasoningConn.java
Last active March 21, 2017 01:48
Example of how to use Stardog's Reasoning capabilities via SNARL
ReasoningConnection aReasoningConn = ConnectionConfiguration
.to("reasoningExampleTest")
.credentials("admin", "admin")
.reasoning(true)
.connect()
.as(ReasoningConnection.class);
@mhgrove
mhgrove / SNARLAddData.java
Last active March 21, 2017 01:48
Example of how to use the native Stardog API, SNARL
aConn.begin();
aConn.add().io()
.format(RDFFormat.N3)
.stream(new FileInputStream("data/sp2b_10k.n3"));
Model aGraph = Models2.newModel(Values.statement(Values.iri("urn:subj"),
Values.iri("urn:pred"),
Values.iri("urn:obj")));
@mhgrove
mhgrove / SesameExample.java
Last active September 26, 2017 17:49
Example of how to use Stardog's Sesame bindings
/*
* Copyright (c) 2010-2015 Clark & Parsia, LLC. <http://www.clarkparsia.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,