Skip to content

Harry Potter

Full Recipe

Shared by: Alec Theriault

Ingest a small JSON object to manifest a graph of connected nodes that explore the familial relationships of Harry Potter characters.

Harry Potter Recipe
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
version: 1
title: Harry Potter
contributor: https://github.com/harpocrates
summary: Small graph of connected nodes
description: |-
  This Recipe loads a small graph of connected nodes.
  Before running this Recipe, download the dataset using
  curl https://quine.io/tutorials/harry_potter_data.json -o harry_potter_data.json
ingestStreams:
  - type: FileIngest
    path: harry_potter_data.json
    format:
      type: CypherJson
      query: |-
        MATCH (p) WHERE id(p) = idFrom('name', $that.name)
        SET p = { name: $that.name, gender: $that.gender, birth_year: $that.birth_year },
          p: Person
        WITH $that.children AS childrenNames, p
        UNWIND childrenNames AS childName
        MATCH (c) WHERE id(c) = idFrom('name', childName)
        CREATE (c)-[:has_parent]->(p)
standingQueries: [ ]
nodeAppearances: [ ]
quickQueries:
  - quickQuery:
      name: Adjacent Nodes
      querySuffix: MATCH (n)--(m) RETURN DISTINCT m
      queryLanguage: Cypher
      sort: Node
    predicate:
      propertyKeys: [ ]
      knownValues: { }
  - quickQuery:
      name: Siblings
      querySuffix: >-
        MATCH (n)-[:has_parent]->(p)<-[:has_parent]-(s)
        RETURN DISTINCT s
      queryLanguage: Cypher
      sort: Node
      edgeLabel: has sibling
    predicate:
      propertyKeys: [ ]
      knownValues: { }
sampleQueries: [ ]

Download Recipe

Scenario

If you are new to Quine, let's start simple. This small graph of connected nodes allows you to explore the familial relationships of Harry Potter characters in Quine. Use this recipe to follow along with the examples outlined in the Exploration UI getting started guide.

Sample Data

Note

Download the sample data to the same directory where Quine will be run.

Before running this Recipe, download the dataset.

curl https://quine.io/recipes/images/harry_potter_data.json -o harry_potter_data.json

How it Works

This recipe connects an ingest stream to the harry_potter_data.json file, parses the JSON object, manifests parent (p) and child (c) nodes, and creates a relationship between the nodes.

The sample data JSON object is straightforward containing character name, gender, birth_year, and a list of children.

{ "name": "James Sirius Potter",   "gender": "male",    "birth_year": 2003,  "children": [] }
{ "name": "Albus Severus Potter",  "gender": "male",    "birth_year": 2005,  "children": [] }
{ "name": "Lily Luna",             "gender": "female",  "birth_year": 2007,  "children": [] }
{ "name": "Rose Weasley",          "gender": "female",  "birth_year": 2005,  "children": [] }
{ "name": "Hugo Weasley",          "gender": "male",    "birth_year": 2008,  "children": [] }
{ "name": "Lily Potter",           "gender": "female",  "birth_year": 1960,  "children": ["Harry Potter"] }
{ "name": "James Potter",          "gender": "male",    "birth_year": 1960,  "children": ["Harry Potter"] }
{ "name": "Molly Weasley",         "gender": "female",  "birth_year": 1949,  "children": ["Ginny Weasley", "Ron Weasley"] }
{ "name": "Arthur Weasley",        "gender": "male",    "birth_year": 1950,  "children": ["Ginny Weasley", "Ron Weasley"] }
{ "name": "Harry Potter",          "gender": "male",    "birth_year": 1980,  "children": ["James Sirius Potter", "Albus Severus Potter", "Lily Luna"] }
{ "name": "Ginny Weasley",         "gender": "female",  "birth_year": 1981,  "children": ["James Sirius Potter", "Albus Severus Potter", "Lily Luna"] }
{ "name": "Ron Weasley",           "gender": "male",    "birth_year": 1980,  "children": ["Rose Weasley", "Hugo Weasley"] }
{ "name": "Hermione Granger",      "gender": "female",  "birth_year": 1979,  "children": ["Rose Weasley", "Hugo Weasley"] }

INGEST-1 processes the harry_potter_data.json file:

  - type: FileIngest
    path: harry_potter_data.json
    format:
      type: CypherJson
      query: |-
        MATCH (p) WHERE id(p) = idFrom('name', $that.name)
        SET p = { name: $that.name, gender: $that.gender, birth_year: $that.birth_year },
          p: Person
        WITH $that.children AS childrenNames, p
        UNWIND childrenNames AS childName
        MATCH (c) WHERE id(c) = idFrom('name', childName)
        CREATE (c)-[:has_parent]->(p)
POST /api/v1/ingest/INGEST-1
[
  {
    "type": "FileIngest",
    "path": "harry_potter_data.json",
    "format": {
      "type": "CypherJson",
      "query": "MATCH (p) WHERE id(p) = idFrom('name', $that.name)\nSET p = { name: $that.name, gender: $that.gender, birth_year: $that.birth_year },\n  p: Person\nWITH $that.children AS childrenNames, p\nUNWIND childrenNames AS childName\nMATCH (c) WHERE id(c) = idFrom('name', childName)\nCREATE (c)-[:has_parent]->(p)"
    }
  }
]

Running the Recipe

 java -jar quine-1.8.2.jar -r hpotter.yaml
Graph is ready
Running Recipe: Harry Potter
Using 2 quick queries
Running Ingest Stream INGEST-1
Quine web server available at http://localhost:8080
INGEST-1 status is completed and ingested 13 

Summary

Open your browser and navigate to http://localhost:8080. Click the query bar and select CALL recentNodes(10). Change 10 to 20 to ensure that you pick up the entire graph, and click the Query button.

A jumbled graph will appear in your browser, click the "tree view" button () to structure the graph before you begin exploring.

Harry Potter Graph

Explore the graph using the pre loaded quick queries or write Cypher queries in the query bar.

Tip

Quick Queries are available by right clicking on a node.

Quick Query Node Type Description
Adjacent Nodes All Display the nodes that are adjacent to this node.
Siblings All Show the has sibling relationship for this node.

Now that you have the graph loaded into Quine, head over to the Exploration UI guide to learn more about how to use Quine's interface.