2011 SoftUmeYa, LLC. Masashi Umezawa
What is Graph DB!?
RDB
O/R mapping is boring in 21st century
NOSQL
Key Value Store is good, but we wants to treat a
little more complicated structures
○ Document Database
CouchDB, MongoDB ○ Graph Database
Neo4j, OrientDB
With Neo4j
Most popular open source graph DB
http://neo4j.org/
GPL 3. Commercial license is also available.
The implementation language is Java
○
JVM language bindings - Python, Ruby, Scala,
Groovy, Clojure, etc.
○
REST API
Property graph of Neo4j
Node (id = 0)
properties = {
key1 = value key2 = value2 }
Node (id = 1)
properties = {
key1 = value key2 = value2 }
Relationship (id = 2)
type = 'hasA' direction = out
properties = {
key1 = value key2 = value2 }
Neo4reSt
Neo4j REST Client written in Squeak
Basic functions are almost covered
○ Node, Relationship, and Property
○ Indexing, Traverse, and Query (still on the way)
High portability
○ WebClient base The Pharo version will be based on Zinc
Structure of Neo4reSt
Raw HTTP Client
A simple REST client
○ Directly handles HTTP Responses
Standard HTTP Client
Wrapper of Raw Client
○ Results will be represented as JSON or other Smalltalk objects.
Object Model
Wrapper of Standard Client
Making a simple graph
I'll try to make a simple graph
a Node
name = "ume"
a Node
name = "Smalltalk"
a Relationship: uses
db := N4GraphDb new.
"Creating nodes"
node1 := db createNode: {#name-> 'ume'}.
node2 := db createNode: {#name-> 'Smalltalk'}.
"Creating relationships"
relation1 := node1 relateTo: node2 type: #uses
properties: {#years->18}.
"Add a relationship from the initial node"
db initialNode relateTo: node1 type: #people.
Making a simple graph(2)
Get information from the graph
db := N4GraphDb new.
"Get the relationship from the initial node with 'people' type"
toAPerson := (db initialNode outgoing: #people) first.
"Walking to the next relationship"
useRel := (toAPerson endNode outgoing: #uses) first.
"Getting a relationship property "
useRel at: #years. "->18"
"Getting a node property"
useRel endNode at: #name. "->Smalltalk"
Using index
Add indexes to Nodes or Relationships
node1 := (db initialNode outgoing: #peole) first endNode.
"Getting indexes abount 'people'"
indexes := db indexer nodeIndexesNamed: 'people'.
"Add a index to the node"
indexes addKey: 'name' value: 'ume' for: node1.
"Get the node from the index"
indexes detectWithKey: 'name' value: 'ume'
Example Applications
Source code repository
A package includes class definitions, method
definitions, and loose method definitions
○ Hierarchy structure
There are more relations from authors, versions, etc.
Backend of Wiki
Wiki -> Books, Book -> Pages, Pages <-> Pages
We can simply map the structure of Swiki, Pier, and
Package dumper demo
I'll try to store the snapshot of the Monticello
package (Neo4reSt itself).
workingCopy := MCWorkingCopy allManagers
detect: [:each | each package name =
'Neo4reSt'
].
snapshot := workingCopy package snapshot.
N4ObjectDumper dump: snapshot
.
Demo
Search by Cypher
Neo4j standard Graph query language
db := N4GraphDb new.
"Collect method sources which method category is 'actions'"
db
queryByCypher:
'
start
a=node(3)
match
a-->b
where
b._className="MCMethodDefinition"
and b.category="actions"
return
b.source
'.
Some links
Neo4j
http://neo4j.org/
Neo4j.rb
http://neo4j.rubyforge.org/
Neo4reSt
http://squeaksource.blueplane.jp/Neo4reSt.html
Summary
Neo4reSt is a REST client of Neo4j
Among the net4j REST clients, Neo4reSt is not
so bad.
Basic functions are already covered.