Skip to content

Instantly share code, notes, and snippets.

View mhgrove's full-sized avatar

Michael Grove mhgrove

View GitHub Profile
@mhgrove
mhgrove / gist:5013411
Last active December 14, 2015 02:28
A series of snippets of streaming protobuf serialization code, works with protobuf 2.4.1 but not 2.5.0rc1.
// some initialization which takes place in the constructor of the streamed
// protobug message writer
mBytes = new ByteArrayOutputStream((int)(64 * (1 << 10)));
coded = CodedOutputStream.newInstance(mBytes);
// then as protobuf messages come in, i append to the stream
// if the message puts us over the threshold of 64k, we write out what's in
// the buffer and start fresh
private void write(final MessageLite aObj) throws IOException {
@mhgrove
mhgrove / ParseTest.java
Created November 12, 2012 19:00
Sesame SPARQL parser perf regression
package test;
import org.apache.commons.math.stat.descriptive.SummaryStatistics;
import org.openrdf.query.parser.sparql.SPARQLParser;
public class ParseTest {
public static void main(String[] args) throws Exception {
final String q = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
Distinct
Projection
ProjectionElemList
ProjectionElem "g"
ProjectionElem "var35"
ProjectionElem "b"
ProjectionElem "c"
LeftJoin
LeftJoin
SingletonSet
@mhgrove
mhgrove / CreateDiskAndICV.java
Last active October 5, 2015 16:24
SNARL Admin
try (AdminConnection dbms = AdminConnectionConfiguration.toEmbeddedServer().credentials("admin", "admin").connect()) {
dbms.disk("icvWithGuard") // disk db named 'icvWithGuard'
.set(ICVOptions.ICV_ENABLED, true) // enable icv guard mode
.set(ICVOptions.ICV_REASONING_ENABLED, true) // specify that guard mode should use reasoning
.create(new File("data/sp2b_10k.n3")); // create the db, bulk loading the file(s) to start
}
@mhgrove
mhgrove / AddConstraint.java
Last active October 5, 2015 17:14
ICV Example
// We'll start out by creating a validator from our SNARL Connection
ICVConnection aValidator = aConn.as(ICVConnection.class);
// add add a constraint, which must be done in a transaction.
aValidator.addConstraint(aConstraint);
@mhgrove
mhgrove / FullExample.java
Last active October 5, 2015 16:51
SNARL Connection Pooling
/*
* 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,
@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 / AddToJena.java
Last active February 14, 2019 07:33
Example of how to use Stardog's Jena Bindings
// start a transaction before adding the data. This is not required,
// but it is faster to group the entire add into a single transaction rather
// than rely on the auto commit of the underlying stardog connection.
aModel.begin();
// read data into the model. note, this will add statement at a time.
// Bulk loading needs to be performed directly with the BulkUpdateHandler provided
// by the underlying graph, or by reading in files in RDF/XML format, which uses the
// bulk loader natively. Alternatively, you can load data into the Stardog
// database using SNARL, or via the command line client.
@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,