Modeling Nodes

Defining labels

Entities are the dominant nouns in your application use cases:

  1. What ingredients are used in a recipe?

  2. Who is married to this person?

The entities of your use cases will be the labeled nodes in the graph data model.

In the Movie domain, we use the nouns in our use cases to define the labels, for example:

  1. What people acted in a movie?

  2. What person directed a movie?

  3. What movies did a person act in?

Here are some of the labeled nodes that we will start with.

Starting labels

Notice here that we use CamelCase for the names for labels.

Node properties

Node properties are used to:

  • Uniquely identify a node.

  • Answer specific details of the use cases for the application.

  • Return data.

For example, in a Cypher statement, properties are used to:

  • Anchor (where to begin the query).

    • MATCH (p:Person {name: 'Tom Hanks'})-[:ACTED_IN]-(m:Movie) RETURN m

  • Traverse the graph (navigation).

    • MATCH (p:Person)-[:ACTED_IN]-(m:Movie {title: 'Apollo 13'})-[:RATED]-(u:User) RETURN p,u

  • Return data from the query.

    • MATCH (p:Person {name: 'Tom Hanks'})-[:ACTED_IN]-(m:Movie) RETURN m.title, m.released

Unique identifiers in the Movie graph

In the Movie graph, we use the following properties to uniquely identify our nodes:

  • Person.tmdbId

  • Movie.tmdbId

Properties for nodes

In addition to the tmdbId that is used to uniquely identify a node, we must revisit the use cases to determine the types of data a node must hold.

Here is a list of our use cases specific to Person and Movie nodes that we will focus on. These use cases inform us about the data we need in Movie and Person nodes.

Use case Steps required

1: What people acted in a movie?

  1. Retrieve a movie by its title.

  2. Return the names of the actors.

2: What person directed a movie?

  1. Retrieve a movie by its title.

  2. Return the name of the director.

3: What movies did a person act in?

  1. Retrieve a person by their name.

  2. Return the titles of the movies.

5: Who was the youngest person to act in a movie?

  1. Retrieve a movie by its title.

  2. Evaluate the ages of the actors.

  3. Return the name of the actor.

7: What is the highest rated movie in a particular year according to imDB?

  1. Retrieve all movies released in a particular year.

  2. Evaluate the imDB ratings.

  3. Return the movie title.

8: What drama movies did an actor act in?

  1. Retrieve the actor by name.

  2. Evaluate the genres for the movies the actor acted in.

  3. Return the movie titles.

Given the details of the steps of these use cases, here are the properties we will define for the Movie nodes:

  • Movie.title (string)

  • Movie.released (date)

  • Movie.imdbRating (decimal between 0-10)

  • Movie.genres (list of strings)

Here are the properties we will define for the Person nodes:

  • Person.name (string)

  • Person.born (date)

  • Person.died (date)

Note: The died property will be optional.

Here is the initial data model:

Data model

And here is the initial instance model you will be creating:

Instance model

Check your understanding

1. Labels

Suppose you have created a list use cases for the application. What elements of the use cases are used to define labels the data model?

  • ❏ Adverbs

  • ✓ Nouns

  • ❏ Adjectives

  • ❏ Verbs

Hint

Only one element is used to represent the things or entities in your use cases.

Solution

Nouns represent the things or entities in your use cases.

2. Defining node properties

What can node properties be used for? Select the three correct answers below:

  • ✓ Uniquely identifying a node.

  • ✓ Answering specific details of the use cases.

  • ❏ Counting the number of relationships in or out of the node.

  • ✓ Returning data.

Hint

Node properties a important for identifying nodes and holding data for a node.

Solution

Node properties can be used for:

  1. Uniquely identifying a node.

  2. Answering specific details of the use cases.

  3. Returning data.

Summary

In this lesson, you learned that a good starting point for your data modeling is to come up with a set of use cases and identify the entities from the use cases. In the next challenge, you will create the first nodes in our initial instance model.