This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
== Northwind Graph | |
=== Introduction | |
Recently, I was asked to pitch a method for providing recommendations. Luckily, armed with the knowledge obtained from talks from Max De Marzi and [Mark Needham](https://skillsmatter.com/skillscasts/7298-modelling-a-recommendation-engine-a-worked-example) at a recent Neo4j London Meetups, I knew this could be easily achieved with Neo4j. | |
The key issue with recommendation engines comes from the data. Luckily, Neo4j comes bundled with the Northwind Graph Example. The Northwind database is an infamous dataset containing purchase history that has been used to teach relational databases for years and was a great place to start. You can import the Northwind database into a graph by following the ["Import Data into Neo4j"](http://neo4j.com/developer/guide-importing-data-and-etl/) post on Neo4j or type the following into Neo4j's browser at `http://localhost:7474/` | |
:play northwind graph |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function queue(all) { | |
return new Promise((resolve, reject) => { | |
const output = []; | |
next(all.splice(0, 1)) | |
function next(go) { | |
go(); | |
.then(res => { | |
output.push(res); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CALL apoc.load.json('https://app.ticketmaster.com/discovery/v2/classifications?locale=en-us&apikey={key}') YIELD value AS json | |
UNWIND json._embedded.classifications as classification | |
MERGE (seg:Segment {ticketmaster_id: classification.segment.id, name: classification.segment.name}) | |
WITH seg, classification | |
UNWIND classification.segment._embedded.genres as genre | |
MERGE (gen:Genre {ticketmaster_id: genre.id, name: genre.name}) | |
MERGE (seg)-[:HAS_GENRE]->(gen) | |
WITH seg, gen, genre | |
UNWIND genre._embedded.subgenres as subgenre | |
MERGE (sub:SubGenre {ticketmaster_id: subgenre.id, name: subgenre.name}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>ANSIBlackColor</key> | |
<data> | |
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS | |
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECUw | |
LjQ4OTQ2NTYxNjMgMC41NDM3OTkwNSAwLjU2MjMyMzI0NjYAEAKAAtIQERITWiRjbGFz | |
c25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an express app | |
const express = require('express'); | |
const app = express(); | |
// Tell it to use Neo4j middleware | |
app.use(require('./neo4j')); | |
// Example Route | |
app.get('/', (req, res) => { | |
// Create Driver session |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const neo4j = require('neo4j-driver').v1 | |
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', 'neo')) | |
const session = driver.session() | |
session.run( | |
'CREATE (e:Event { id: $id, title: $title, startsAt: datetime($startsAt) }) RETURN e', | |
{ | |
id: 2, | |
title: 'Another Test Event', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node { | |
diameter: 50px; | |
color: #A5ABB6; | |
border-color: #9AA1AC; | |
border-width: 2px; | |
text-color-internal: #FFFFFF; | |
font-size: 10px; | |
} | |
relationship { | |
color: #A5ABB6; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ status: 'success', message: 'Book updated' } | |
{ | |
ISBN: 1, | |
publication: '2020-03-13', | |
createdAt: '2020-03-13T17:30:20.191000000Z' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:begin | |
CREATE INDEX ON :Fixture(kickoff); | |
CREATE CONSTRAINT ON (node:Country) ASSERT (node.id) IS UNIQUE; | |
CREATE CONSTRAINT ON (node:Fixture) ASSERT (node.id) IS UNIQUE; | |
CREATE CONSTRAINT ON (node:Group) ASSERT (node.id) IS UNIQUE; | |
CREATE CONSTRAINT ON (node:Player) ASSERT (node.id) IS UNIQUE; | |
CREATE CONSTRAINT ON (node:Stadium) ASSERT (node.name) IS UNIQUE; | |
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE; | |
:commit | |
CALL db.awaitIndexes(300); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a graph of episodes and guests | |
CALL apoc.load.json('https://www.learnwithjason.dev/api/episodes') | |
YIELD value | |
// | |
MERGE (e:Episode { | |
id: value._id | |
}) | |
ON CREATE SET | |
e.createdAt = datetime(), |
OlderNewer