Skip to content

Instantly share code, notes, and snippets.

@ib84
Created June 27, 2012 08:32
Show Gist options
  • Save ib84/3002452 to your computer and use it in GitHub Desktop.
Save ib84/3002452 to your computer and use it in GitHub Desktop.
little hypergraphdb demo
package hgtest.storage
import org.hypergraphdb._
import collection.JavaConversions._
import org.hypergraphdb.HGQuery.hg
import org.hypergraphdb.query.AtomTypeCondition
import org.hypergraphdb.util.HGUtils
import storage.bje.BJEStorageImplementation
object Test extends App{
var config: HGConfiguration = new HGConfiguration
val graph = new HyperGraph();
config.setStoreImplementation(new BJEStorageImplementation); config
graph.setConfig(config)
graph.open("/home/ingvar/workspace/blankHgdbDBdir/")
val handles1 = (1 to 3).map(i => hg.assertAtom(graph, i.toString)).toArray[HGHandle]
val handles2 = Vector(2, 3, 6, 8).map(i => hg.assertAtom(graph, i.toString)).toArray[HGHandle]
val combo1 = graph.add(new HGPlainLink(handles1:_*))
val combo2 = graph.add(new HGPlainLink(handles2:_*))
val query23 : java.util.List[HGPersistentHandle] = hg.findAll(graph, hg.link(handles2(0), handles2(1)))
val found = if (query23.size > 0) query23.forall{result => result.equals(combo1.getPersistent) ||result.equals(combo2.getPersistent) } else false
println("found both links pointing to 2 and 3?" + found)
// => prints true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment