Skip to content

Instantly share code, notes, and snippets.

@darekmydlarz
Created July 29, 2012 13:00
Show Gist options
  • Save darekmydlarz/3198558 to your computer and use it in GitHub Desktop.
Save darekmydlarz/3198558 to your computer and use it in GitHub Desktop.
Scala + Neo4j + Blueprints
import com.tinkerpop.blueprints.Graph
import com.tinkerpop.blueprints.impls.neo4j.Neo4jGraph
import com.tinkerpop.blueprints.Vertex
import com.tinkerpop.blueprints.Edge
import java.util.Iterator
import com.tinkerpop.blueprints.Direction
object BlueprintsNeo4j {
def main(args: Array[String]): Unit = {
val graph : Graph = new Neo4jGraph("tmp/graph")
val a : Vertex = graph.addVertex()
val b : Vertex = graph.addVertex()
a.setProperty("name", "Marko")
b.setProperty("name", "Polo")
val e : Edge = graph.addEdge(null, a, b, "knows")
e.setProperty("since", 2006)
val it = a.getEdges(Direction.BOTH).iterator();
while(it.hasNext()) {
val edge : Edge = it.next()
val v1 : Vertex = edge.getVertex(Direction.IN)
val v2 : Vertex = edge.getVertex(Direction.OUT)
println(v1.getProperty("name") + " knows " + v2.getProperty("name") + " since " + edge.getProperty("since"))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment