Skip to content

Commit

Permalink
Add Neo4j day 2 homework
Browse files Browse the repository at this point in the history
  • Loading branch information
peferron committed Dec 12, 2016
1 parent 80ea339 commit 4e481b0
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions neo4j/homework.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,70 @@

### Do, 1.

```
```cypher
MATCH (n) RETURN n
```

### Do, 2.

```
```cypher
MATCH (n) DETACH DELETE n
```

### Do, 3.

Skipped.

## Day 2

### Find, 1.

[Neo4j REST API Documentation](https://neo4j.com/docs/rest-docs/current/)

### Find, 2.

[Jung API Javadoc](http:https://jung.sourceforge.net/doc/api/index.html)

### Find, 3.

[Using Neo4j from Python](https://neo4j.com/developer/python/)

### Do, 1.

```groovy
def actor(g, name) {
g.V.filter{it.name == name}.next()
}
Gremlin.defineStep('costars', [Vertex, Pipe], {
_().sideEffect{start = it}
.outE('ACTED_IN')
.inV
.inE('ACTED_IN')
.outV
.filter{!start.equals(it)}
.dedup
})
Gremlin.defineStep('path', [Vertex, Pipe], { target ->
_().costars
.loop(1){it.loops < 4 & !it.object.equals(target)}
.filter{it.equals(target)}
.path
})
def compare_distance(actor1, actor2, target) {
distance = {a, b -> (a.path(b).next().size() - 3) / 2}
actor1.name + ': ' + distance(actor1, target) + ', ' + actor2.name + ': ' + distance(actor2, target)
}
g = new Neo4jGraph('/Users/peferron/Downloads/neo4j-1.9.7/data/graph.db')
bacon = actor(g, 'Kevin Bacon')
elvis = actor(g, 'Elvis Presley')
roddy = actor(g, 'Roddy McDowall')
compare_distance(elvis, roddy, bacon)
```

### Do, 2 & 3.

Skipped.

0 comments on commit 4e481b0

Please sign in to comment.