Defining labels
Entities are the dominant nouns in your application use cases:
-
What ingredients are used in a recipe?
-
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:
-
What people acted in a movie?
-
What person directed a movie?
-
What movies did a person act in?
Here are some of the labeled nodes that we will start with.
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? |
|
2: What person directed a movie? |
|
3: What movies did a person act in? |
|
5: Who was the youngest person to act in a movie? |
|
7: What is the highest rated movie in a particular year according to imDB? |
|
8: What drama movies did an actor act in? |
|
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:
And here is the initial instance model you will be creating:
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:
-
Uniquely identifying a node.
-
Answering specific details of the use cases.
-
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.