High level Neo4j graph database client for Pharo and Squeak
- Basic http client
- Object level interfaces for interacting database elements (Node, Relationship, etc) easily
- Support executing Cypher queries dynamically
Metacello new
baseline: 'Neo4reSt';
repository: 'github://mumez/Neo4reSt/repository';
load.
Before running test cases in 'Neo4reSt-Tests', you need to configure N4GraphDbTest class>>defaultSettings
according to your Neo4j environment. Please edit and evaluate N4GraphDbTest class>>initSettingsExample
.
In Neo4j web console:
:play movie-graph
This will open the instruction for populating sample Movie Graph data.
Then, in Smalltalk Playground (Workspace):
db := N4GraphDb new.
db settings username: 'neo4j'; password: 'neoneo'.
db allLabels. "Get all node labels"
"Print 'Movie' node properties"
(db nodesLabeled: 'Movie')
do: [ :each | Transcript cr; show: each properties ].
matrix := (db nodesLabeled: 'Movie' where: [:each | each @ 'title' = 'The Matrix']) first.
matrix properties.
matrix inRelationships.
matrix outRelationships.
(matrix inRelationshipsTyped: 'ACTED_IN')
collect: [:each | each tailNode @ 'name'].
(matrix inRelationshipsTyped: 'ACTED_IN' where: [ :start :rel :end | (rel @ 'roles') = #('Neo') ])
collect: [ :each | each tailNode properties ].
sf := db mergeNodeLabeled: 'Genre' properties: {'name'->'SF'. 'description'->'Science Fiction'}.
action := db mergeNodeLabeled: 'Genre' properties: {'name'->'Action'. 'description'->'Exciting Actions'}.
matrixToSf := matrix relateOneTo: sf typed: 'HAS_GENRE' properties: {'score'-> 6}.
matrixToAction := matrix relateTo: action typed: 'HAS_GENRE' properties: {'score'-> 7}.
matrix outRelationships collect: [ :each | each properties ]. "Now you can get genre relationships"
db runCypher: 'UNWIND range(1, 10) AS n RETURN n*n'. "inspect it"
resp := db runCypher: 'UNWIND range($from, $to) AS n RETURN n*n'
arguments: {'from'->2. 'to'->5}.
resp values. "print it"
m := 'm' asCypherIdentifier. "Movie"
p := 'p' asCypherIdentifier. "Person"
o := 'o' asCypherIdentifier. "Other person"
pathPattern := (p node: 'Person') - ('act1' asCypherIdentifier rel: 'ACTED_IN' ) -> (m node: 'Movie' props: {'released'->2000}) <- ('act2' asCypherIdentifier rel: 'ACTED_IN' ) - (o node: 'Person').
actorNameParam := 'actorName' asCypherParameter.
where := (p @ 'name') starts: actorNameParam.
"where := ((p @ 'born') > 1970) and: ((o @ 'born') > 1970). " " <= try changing"
return := (p @ 'name'), (o @ 'name'), (m @ 'title').
query := CyQuery match: pathPattern where: where return: return orderBy: (p @ 'name') skip: 0 limit: 100. "print it"
result := db runCypher: query arguments: { actorNameParam -> 'Tom' }.
(result values groupedBy: [ :each | each at: 1 ]). "inspect it"
db := N4GraphDb new.
db settings rootUri: 'http://127.0.0.1:7474/'.
-
Interacting with Neo4j from Pharo Smalltalk
- Actually, it is the introduction of SCypherGraph, another Neo4j client using FFI. However, the API is almost the same.
-
- A short presentation on Smalltalkers meeting in Tokyo 2011 December (OLD API)