Create the Genre Nodes

In this Challenge, you will working with the data you previously imported with the Data Importer and did some transformations already.

You can only perform the steps of this Challenge if you have imported the data in an earlier Challenge and have transformed data to Date and StringArray types, and added the Actor and Director labels.

This challenge has 4 steps:

  1. Create the constraint for the Genre nodes.

  2. Create the Genre nodes.

  3. Remove the genres property.

  4. Verify your final schema for the data model

As a reminder, here is the data model we are moving toward where you see that we want to add the Genre nodes to the graph.

Movie data model

Step 1: Create the constraint

Execute this code in the sandbox on the right to add the uniqueness constraint for the Genre nodes to the graph:

Cypher
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/app-python/main/modules/3-refactoring-imported-data/lessons/7-nodes-from-properties/create-genre-constraint.cypher[]

After you have added this constraint, try running SHOW CONSTRAINTS.

Step 2: Create the Genre nodes

Execute this code in the sandbox on the right to create the Genre nodes in the graph, and the IN_GENRE relationships:

Cypher
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/app-python/main/modules/3-refactoring-imported-data/lessons/7-nodes-from-properties/merge-genre-nodes.cypher[]

Your execution should create 17 Genre nodes and 212 IN_GENRE relationships.

Step 3: Remove the genres property

Now that we have the Genre nodes, we no longer need the genres property in the Movie nodes.

Run code into the sandbox on the right to remove the genres property.

Cypher
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/app-python/main/modules/3-refactoring-imported-data/lessons/7-nodes-from-properties/remove-genres-property.cypher[]

Your execution should set 93 properties.

Step 4: View the final schema

Your post-import refactoring of the graph should now be complete. View the schema.

Cypher
Unresolved directive in lesson.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/app-python/main/shared/db-schema-visualization.cypher[]

Validate Results

Once you completed the steps of this Challenge, click the Check Database button and we will check the database for you.

Hint

Did you execute the three code blocks shown in this Challenge?

Solution

If your graph does not verify, you may need to:

  1. Clear the graph with:

cypher
Unresolved directive in questions/verify.adoc - include::https://raw.githubusercontent.com/neo4j-graphacademy/app-python/main/shared/detach-delete-all-nodes.cypher[]
  1. Re-import the data once again with the Data Importer

  2. Transform the genres, countries, and language properties to lists

  3. Add the Actor and Director labels

  4. Execute the three code blocks of this Challenge

Summary

In this challenge, you performed the final steps to refactor the graph to match the target data model. In the next module, you learn about importing larger datasets.