Skip to content

Instantly share code, notes, and snippets.

View datablend's full-sized avatar

Davy Suvee datablend

View GitHub Profile
@datablend
datablend / compound.json
Created August 6, 2011 10:08
compound presentation as json
{
"compound_cid" : "46200001" ,
"smiles" : "CCC1C(C(C(C(=NOCC=CCN2CCCCC2)C(CC(C(C(C(C(C(=O)O1)C)OC3CC(C(C(O3)C)O)(C)OC)C)OC4C(C(CC(O4)C)N(C)CC5=CC=CC=C5)O)(C)O)C)C)O)(C)O" ,
"fingerprint_count" : 120 ,
"fingerprints" : [
"0[N]1[C O]2[C C C]" ,
"0[N]1[C O]2[C C C]3[C C C C C]" ,
"0[C]1[C C C]2[C C N O]3[C C C C O O]" ,
"0[C]1[C C]2[C C C C O]3[C C N O]" ,
"0[O]1[C]2[C O]3[C C C]" ,
@datablend
datablend / fingerprints.json
Created August 6, 2011 14:10
fingerprint counts output
{
"fingerprint" : "0[N]1[C O]2[C C C]",
"count" : 472
}
{
"fingerprint" : "0[N]1[C O]2[C C C]3[C C C C C]",
"count" : 41
}
{
"fingerprint" : "0[O]1[C]2[C O]3[C C C]",
@datablend
datablend / Query.java
Created August 11, 2011 13:35
Map reduce
// Calculate the essential numbers
int maxnumberofcompoundfingerprints = (int) (fingerprintsToFind.size() / 0.6);
int minnumberofcompoundfingerprints = (int) (fingerprintsToFind.size() * 0.6);
int numberoffingerprintstoconsider = fingerprintsToFind.size() - minnumberofcompoundfingerprints;
List<String> fingerprintsToConsider = fingerprintsToFind.subList(0,numberoffingerprintstoconsider+1);
// Find all compounds that satisfy the specified conditions
DBObject compoundquery =
QueryBuilder.start(FINGERPRINTS_PROPERTY).in(fingerprintsToConsider)
@datablend
datablend / InferenceLoop.java
Created November 20, 2011 16:59
Setup Neo4J RDF store
neograph = new Neo4jGraph("var/rdf");
// Let's use manual transaction mode
neograph.setMaxBufferSize(0);
sail = new ForwardChainingRDFSInferencer(new GraphSail(neograph));
sail.initialize();
connection = sail.getConnection();
@datablend
datablend / InferenceLoop.java
Created November 20, 2011 17:02
Add data through loop
InferenceLoop loop = new InferenceLoop();
Scanner in = new Scanner(System.in);
while (true) {
System.out.println("Provide RDF statement:");
System.out.print("=> ");
String input = in.nextLine();
System.out.println("The following edges were created:");
loop.inference(input);
}
// Parses and add the RDF statement accordingly
public void inference(String statement) throws SailException, InterruptedException {
String[] triple = statement.split(" ");
inference(new URIImpl(triple[0]), new URIImpl(triple[1]), new URIImpl(triple[2]));
}
// Add the inference
public void inference(URI subject, URI predicate, URI object) throws SailException, InterruptedException {
neograph.startTransaction();
connection.addStatement(subject, predicate, object);
// Parses and add the RDF statement accordingly
public void inference(String statement) throws SailException, InterruptedException {
String[] triple = statement.split(" ");
inference(new URIImpl(triple[0]), new URIImpl(triple[1]), new URIImpl(triple[2]));
}
// Add the inference
public void inference(URI subject, URI predicate, URI object) throws SailException, InterruptedException {
neograph.startTransaction();
connection.addStatement(subject, predicate, object);
@datablend
datablend / PushTransactionEventHandler.java
Created November 20, 2011 17:56
Transaction handler
public class PushTransactionEventHandler implements TransactionEventHandler<Object> {
private int id = 1;
public void afterCommit(TransactionData transactionData, Object o) {
// Retrieve the created relationships. (The relevant nodes will be retrieved through these relationships)
Iterable<Relationship> relationships = transactionData.createdRelationships();
// Iterate and add
for (Relationship relationship : relationships) {
public class PushUtility {
private static final String url = "http://localhost:8080/workspace0?operation=updateGraph";
private static final String nodejson = "{\"an\":{\"%1$s\":{\"label\":\"%1$s\"}}}";
private static final String edgejson = "{\"ae\":{\"%1$d\":{\"source\":\"%2$s\",\"target\":\"%3$s\",\"directed\":true,\"label\":\"%4$s\",\"inferred\":\"%5$b\"}}}";
private static void push(String message) {
try {
// Create a connection and push the node or edge json message
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
@datablend
datablend / RDF
Created November 20, 2011 18:16
RDF data
http://datablend.be/example/teaches http://www.w3.org/2000/01/rdf-schema#domain http://datablend.be/example/teacher
http://datablend.be/example/teaches http://www.w3.org/2000/01/rdf-schema#range http://datablend.be/example/student
http://datablend.be/example/Davy http://datablend.be/example/teaches http://datablend.be/example/Bob