Add labels to the graph

In this Challenge, you will be 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.

This challenge has 3 steps:

  1. Add the Actor label to the Person nodes.

  2. Add the Director label to the Person nodes.

  3. View the labels stored in the graph.

As a reminder, here is the data model we are moving toward where you see that we want Person nodes to have the Actor label and/or Director label, depending upon the type of relationship to a Movie node.

Movie data model

Step 1: Add the Actor labels

Execute this code in the sandbox on the right to add the Actor labels to the graph:

Cypher
Unresolved directive in lesson.adoc - include::{repository-raw}/main/modules/3-refactoring-imported-data/lessons/6-c-add-labels/add-actor-label.cypher[]

This code should update 353 nodes in the graph.

Step 2: Add the Director labels

Modify and run the code you just executed to add the Director labels to the nodes.

Your execution should update 97 nodes in the graph.

Step 3: Examine the new labels in the graph

Run code into the sandbox on the right to view the node labels. Person nodes now have the additional labels of Actor and/or Director.

Cypher
Unresolved directive in lesson.adoc - include::{repository-raw}/main/shared/apoc-meta-nodetypeproperties.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

  1. Find all Person nodes that have a :DIRECTED relationship.

  2. Use SET to set the label to DIRECTED

Solution

Here is the code to set the Director label:

cypher
Unresolved directive in questions/verify.adoc - include::{repository-raw}/main/modules/3-refactoring-imported-data/lessons/6-c-add-labels/solution.cypher[]

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

  1. Clear the graph with:

cypher
Unresolved directive in questions/verify.adoc - include::{repository-raw}/main/shared/detach-delete-all-nodes.cypher[]
  1. Re-import the data once again with the Data Importer

  2. Transform the genres, countries, languages properties to lists

  3. Add the Director labels

Summary

In this challenge, you added the Actor and Director labels to the Person nodes. In the next lesson, you learn how to refactor the graph to create nodes from properties.