Skip to content

Instantly share code, notes, and snippets.

@adam-cowley
Last active February 3, 2022 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adam-cowley/8991ea517266b173199e320ba8c609e7 to your computer and use it in GitHub Desktop.
Save adam-cowley/8991ea517266b173199e320ba8c609e7 to your computer and use it in GitHub Desktop.
Learn with Jason as a Graph
// 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(),
e += value { .title, .description, .demo, .repo, .links, .youtubeID, slug: value.slug.current }
// Only ever one host...
// MERGE (host:Person {name: value.host.name})
// MERGE (host)-[:HOSTED]->(e)
// Create guest node and relationship to the
FOREACH (guest in value.guest |
MERGE (g:Person {name: guest.name})
ON CREATE SET g.twitter = guest.twitter
MERGE (e)-[:HAS_GUEST]->(g)
)
// Added 93 labels, created 93 nodes, set 477 properties, created 48 relationships, completed after 1957 ms.
// Get most popular tags
MATCH (t:Tag)
RETURN t.name, size((t)<-[:HAS_TAG]-()) AS episodes
ORDER BY episodes DESC
LIMIT 10;
// Episodes with tag
MATCH (t:Tag {name: "nextjs"})<-[:HAS_TAG]-(e)-[:HAS_GUEST]->(g)
RETURN e.title, g.name AS guest, g.twitter AS twitter;
// Similar Episodes
MATCH (e1:Episode)-[:HAS_TAG]->(t)<-[:HAS_TAG]-(e2)
RETURN e1.title, e2.title, count(*) AS inCommon, collect(t.name) AS tags
ORDER BY inCommon DESC
LIMIT 10;
// Use the episode title to create some rudimental tags
MATCH (e:Episode)
// Split title into a list
UNWIND split(e.title, ' ') AS word
WITH e, word
// Filter out stop words? Learn *with* Jason, etc
WHERE left(word, 1) = toUpper(left(word, 1)) AND size(word) > 3
// Remove empty
WITH e, apoc.text.clean(word) AS word
WHERE word <> ''
// apoc.text.clean: convert string to alphanumeric
MERGE (t:Tag {name: word})
// Create relationship from episode to tag
MERGE (e)-[:HAS_TAG]->(t);
// Added 148 labels, created 148 nodes, set 148 properties, created 210 relationships, completed after 20 ms.
// Delete trash tags
MATCH (t:Tag)
WHERE t.name IN ['build', 'your', 'learn', 'with', 'using']
DETACH DELETE t;
// Deleted 5 nodes, deleted 40 relationships, completed after 2 ms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment