Skip to content

Commit

Permalink
WIP: Have communication with Neo4j working
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBakerEffendi committed Mar 4, 2020
1 parent e4292b3 commit 79ddea2
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

.idea
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# neo4j-yelp
# Neo4j Yelp Dataset Solution

Contains Python scripts to import and model the Yelp challenge dataset into Neo4j respectively.

## Getting Started

### Step 1:

Download the [Neo4j Community Edition](https://neo4j.com/download-thanks/?edition=community&release=4.0.1&flavour=unix) ZIP or tarball or start the Neo4j Docker container with the `docker-compose.yml` file.

If using the ZIP or tarball, extract the archive to a directory e.g. `$HOME`:
```
tar -xvzf neo4j-community-4.0.1-unix.tar.gz -C ~/.
```

### Step 2:

If not using the Docker image, start Neo4j using the `neo4j` binary in the `neo4j-community-4.0.1/bin` file. Example:
```
~/neo4j-community-4.0.1/bin/neo4j start
```
Note this needs to run with Oracle Java 11 or OpenJDK 11. I recommend using [AdoptOpenJDK 11](https://adoptopenjdk.net/installation.html?variant=openjdk11&jvmVariant=hotspot) and setting $JAVA_HOME to the location of the directory e.g. `export JAVA_HOME=/home/david/Downloads/jdk-11.0.5+10`.

Neo4j browser should now be running on `http://localhost:7474`. Default username and password is `neo4j` and `neo4j` respectively.

### Step 3:

Before running the `neo4j_yelp.py` script, make sure that you have installed all of the dependencies and edited `config.py` to contain your credentials. To download all the dependencies you can simply type:
```
pip3 install -r requirements.txt --user
```

6 changes: 4 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PROTO = "bolt"
USER = "neo4j"
PASSWORD = "bitnami"
URI = "bolt://localhost:7687"
PASSWORD = "MyPassword"
HOSTNAME = "localhost"
PORT = "7687"
15 changes: 5 additions & 10 deletions neo4j_yelp.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from neo4j import GraphDatabase
from py2neo import Graph
import config

uri = "bolt://0.0.0.0:7687"
driver = GraphDatabase.driver(uri, auth=("neo4j", "bitnami"))
uri = "{}://{}:{}@{}:{}".format(config.PROTO, config.USER, config.PASSWORD, config.HOSTNAME, config.PORT)

def print_friends_of(tx, name):
for record in tx.run("MATCH (a:Person)-[:KNOWS]->(f) "
"WHERE a.name = {name} "
"RETURN f.name", name=name):
print(record["f.name"])
graph = Graph(uri)

with driver.session() as session:
session.read_transaction(print_friends_of, "Alice")
print(graph.evaluate("MATCH (tom {name: \"Tom Hanks\"}) RETURN tom"))
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
neo4j==1.7.6
neobolt==1.7.16
neotime==1.7.4
py2neo

0 comments on commit 79ddea2

Please sign in to comment.