Skip to content

Commit da46552

Browse files
Apply suggestions from code review
Co-authored-by: Jessica Wright <[email protected]>
1 parent 5ec028b commit da46552

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

modules/ROOT/pages/cypher/index.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[IMPORTANT]
1313
====
1414
This page covers the basics of Cypher.
15-
For the complete documentation, refer to link:{docs-home}/cypher/[Cypher].
15+
For the complete documentation, refer to the link:{docs-home}/cypher/[Cypher Manual].
1616
====
1717

1818
.A visual representation of a Cypher query
@@ -28,20 +28,20 @@ Intuitive and close to natural language, Cypher provides a visual way of matchin
2828
(:nodes)-[:ARE_CONNECTED_TO]->(:otherNodes)
2929
----
3030

31-
Round brackets are used to represent `(:Nodes)`, and `-[:ARROWS]->` to represent a relationship between the `(:Nodes)`.
31+
Round brackets are used to represent `(:Nodes)`, and square brackets `-[]->` to represent a relationship between the `(:Nodes)`.
3232
With this query syntax, you can perform create, read, update, or delete (CRUD) operations on your graph.
3333

3434
[TIP]
3535
====
36-
For a quick look with no installation required, get a free link:https://neo4j.com/cloud/platform/aura-graph-database/[Aura instance].
36+
To try querying with Cypher, get a free link:https://neo4j.com/cloud/platform/aura-graph-database/[Aura instance], no installation required.
3737
Use the graduation cap icon on the top right section to access the interactive guides.
3838
The "Query fundamentals" gives you a hands-on introduction to Cypher.
3939
====
4040

4141
== How does Cypher work?
4242

4343
Neo4j's graph model is composed of <<nodes>> and <<relationships>>, which may also have assigned <<properties>>.
44-
With nodes and relationships, you can build powerful patterns that can express simple or complex patterns.
44+
With nodes and relationships, you can build a graph that can express both simple and complex patterns.
4545

4646
Pattern recognition is a key fundamental cognitive process, making Cypher, which utilizes pattern matching, intuitive and easy to learn.
4747

@@ -66,7 +66,7 @@ This makes queries easy both to write and to read.
6666
.A graph example involving four nodes and three relationships.
6767
image::cypherintro-graph1.svg[role="popup-link",width=600]
6868

69-
If you were to represent the data in this graph in English, it might read as something like: _"Sally likes Graphs. Sally is friends with John. Sally works for Neo4j."_
69+
If you want to represent the data in this graph in English, it would read as something like: _"Sally likes Graphs. Sally is friends with John. Sally works for Neo4j."_
7070

7171
Now, if you were to write this same information in Cypher, then it would look like this:
7272

@@ -88,7 +88,7 @@ In the previous example, `Sally`, `John`, `Graphs`, and `Neo4j` are the nodes:
8888
.A visual representation of nodes.
8989
image::cypherintro-nodes.svg[role="popup-link",width=450]
9090

91-
In Cypher, you can depict a node by surrounding it with parentheses, e.g. `(node)`.
91+
As mentioned previously, nodes are represented as round brackets `(node)` in Cypher.
9292
The parentheses are a representation of the circles that compose the nodes in the visualization.
9393

9494
==== Node labels
@@ -97,9 +97,9 @@ Nodes can be grouped together through a <<label>>.
9797
They work like tags and allow you to specify certain types of entities to look for or to create.
9898
Labels also help Cypher distinguish between entities and optimize execution for your queries.
9999

100-
In the example, both `Sally` and `John` can be grouped under a `Person` label, `Graphs` can receive a `Technology` label, and `Neo4j` can be labeled as `Company`:
100+
In the example, both `Sally` and `John` are persons, so they get a `Person` label, `Graphs` gets a `Technology` label, and `Neo4j` is a `Company`:
101101

102-
.Nodes grouped in labels. Note that `Sally`, `John`, `Graphs`, and `Neo4j` are now xref:cypher/index.adoc#cypher-properties[properties] instead.
102+
.Nodes grouped by labels. Note that `Sally`, `John`, `Graphs`, and `Neo4j` are now xref:cypher/index.adoc#cypher-properties[properties] instead.
103103
image::cypher-graph-nodes-arr.svg[role="popup-link",width=450]
104104

105105
In a relational database context, this would be the same as telling SQL which table to look for the particular row.

modules/ROOT/pages/cypher/intro-tutorial.adoc

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ You will create a graph, find nodes, query patterns, and solve questions about t
77

88
== Create the Movie Graph
99

10-
After you create a link:https://neo4j.com/product/auradb/?ref=docs-nav-get-started[free Aura instance], select the "Connect" button and go to "Query".
11-
In the query pane, write the following code:
10+
After you create a link:https://neo4j.com/product/auradb/?ref=docs-nav-get-started[free Aura instance], use the "Connect" button and select "Query".
11+
In the Cypher editor, copy and paste the following Cypher and execute the query:
1212

1313
[source,cypher]
1414
--
@@ -700,21 +700,23 @@ WHERE cloudAtlas.title = "Cloud Atlas"
700700
RETURN cloudAtlas
701701
--
702702

703-
=== An amount of people
703+
=== Limit returned results
704704

705-
If you want to find the names of 10 people in the graph, no matter in what order, you need to `LIMIT` the `RETURN` answers to your `MATCH` query: This code finds all _Person_ nodes in the graph but just returns the _name_ property value for 10 of them.
705+
If you want to limit the number of returned results without any specific order, you can add `LIMIT` to the `RETURN` clause.
706+
This query finds all the `Person` nodes in the graph and returns 10 of them using the `name` property.
706707

707708
[source, cypher]
708709
--
709-
MATCH (people:Person)
710-
RETURN people.name LIMIT 10
710+
MATCH (p:Person)
711+
RETURN p.name LIMIT 10
711712
--
712713

713714
For this query, property values are returned and you can only view the results as a table.
714715

715-
=== Movies after release year
716+
=== The `WHERE` subclause
716717

717-
You can specify a range of values for selecting the `Movie` nodes to retrieve, either by specifically pointing the year:
718+
If you want to return nodes by a specific property, you can use the `WHERE` subclause.
719+
You can either return a specific value, in this case movies released in one specific year:
718720

719721
[source, cypher]
720722
--
@@ -723,7 +725,7 @@ WHERE nineties.released = 1990
723725
RETURN nineties.title
724726
--
725727

726-
Or with a range:
728+
Or within a range:
727729

728730
[source, cypher]
729731
--
@@ -749,8 +751,8 @@ For the first query, the result is "Joe Versus the Volcano", and for the second:
749751

750752
== Find patterns
751753

752-
On the previous step, you have queried the graph for nodes.
753-
Now you will retrieve related nodes by finding the xref:cypher/patterns.adoc[patterns] within the graph, that is, how these nodes interact with each other through relationships.
754+
In the previous step, you queried the graph for nodes.
755+
Now you are going to retrieve related nodes by finding the xref:cypher/patterns.adoc[patterns] within the graph, that is, how these nodes are related to each other.
754756

755757
=== All Tom Hanks movies
756758

@@ -766,12 +768,12 @@ This is the result:
766768

767769
image::tomhanksmovies.svg[Result to the query searching for all movies that Tom Hanks has acted in, width=500, role="popup-link"]
768770

769-
Note that Tom Hanks' node is connected to `Movie` nodes through two different relationships: `ACTED_IN` and `DIRECTED`, which means some people listed in the `Person` nodes can be both actors and directors.
771+
Note that Tom Hanks' node is connected to `Movie` nodes through two different relationships: `ACTED_IN` and `DIRECTED`, which means a `Person` node can be both an actor and a director.
770772

771773
=== Directors of "Cloud Atlas"
772774

773775
As mentioned previously, you can find information about directors through the relationship `DIRECTED`.
774-
To learn who directed "Cloud Atlas", you can write the following query:
776+
To learn who directed "Cloud Atlas", execute the following query:
775777

776778
[source, cypher]
777779
--
@@ -792,7 +794,7 @@ Here is the result:
792794

793795
=== Tom Hanks' co-actors
794796

795-
This is the query you would write to get the answer:
797+
If you want to expand the pattern and find actors who worked on the same movie, you can use the following query:
796798

797799
[source, cypher]
798800
--
@@ -814,13 +816,13 @@ Then, combine with people who acted in those same movies:
814816
MATCH (m)<-[b:ACTED_IN]-(coActors:Person)
815817
--
816818

817-
This is how your graph should look like:
819+
This is what your graph should look like:
818820

819821
image::tomhankscoactors.svg[Actors who played in the same movies as Tom Hanks, link="{imagesdir}/tomhankscoactors.svg",role="popup-link"]
820822

821823
=== People related to "Cloud Atlas"
822824

823-
Supposing that you don't know what relationships connect the `Person` and `Movie` nodes, you can query the graph to discover that:
825+
If you don't know what relationships connect the `Person` and `Movie` nodes, you can query the graph to discover that:
824826

825827
[source, cypher]
826828
--
@@ -834,7 +836,7 @@ Then, in the `RETURN` line, you can specify what property you want to retrieve i
834836
In Cypher, you can define what specific propety you want to retrieve by combining the variable and the name of the property.
835837
So, in this case, `people` is the variable for `Person` nodes and `name` is the property that stores the name of the people, thus `people.name`.
836838

837-
Then, since the relationships are not specified, you can use the link:https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-type[`type()` function] to retrieve the string associated to the relationship, and then `relatedTo` to also retrieve the properties associated to the relationship (e.g. `roles` in the case of `:ACTED_IN`).
839+
Then, since the relationships are not specified, you can use the link:https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-type[`type()` function] to retrieve the relationship type, and then `relatedTo` to also retrieve all the properties associated to the relationship (e.g. `roles` in the case of `:ACTED_IN`).
838840

839841
Here is the result:
840842

@@ -859,15 +861,16 @@ Here is the result:
859861

860862
=== Movies and actors up to three hops away from Kevin Bacon
861863

862-
The premise of the game "Six Degrees of Kevin Bacon" is that players need to link any actor to Kevin Bacon through their film co-stars in six or fewer steps.
863-
You can do the same with this graph using a shortest path query that will be here referred as the "Bacon Path".
864+
The premise of the game "Six Degrees of Kevin Bacon" is to link any actor to Kevin Bacon through their film co-stars in six or fewer steps.
865+
This game can be played in the Movie graph using different strategies.
864866

865-
To perform this type of query, you need to specify:
867+
Two possible strategies:
866868

867869
* link:https://neo4j.com/docs/cypher-manual/current/patterns/variable-length-patterns/[Variable length patterns]
868870
* link:https://neo4j.com/docs/cypher-manual/current/patterns/shortest-paths/[Built-in shortestPath() algorithm]
869871

870-
This first query aims to find all movies and/or people who are up to 3 hops away from Kevin Bacon in the graph:
872+
The first strategy is to use a variable length pattern.
873+
This query finds all `Person` and `Movie` nodes one to three hops away from Kevin Bacon:
871874

872875
[source, cypher]
873876
--
@@ -886,7 +889,7 @@ Here is the result of this query:
886889
image::kevinthreehops.svg[Result to query for what movies and actors are related to Kevin Bacon, link="{imagesdir}/kevinthreehops.svg",role="popup-link"]
887890

888891
The downside of this query is that you don't know _how_ Kevin Bacon is related to these people and movies.
889-
If you want to retrieve the relationships connecting these nodes, you need to write the following code:
892+
If you want to retrieve the path that connects these nodes, `MATCH` the *path* and return it along with the `Person` or `Movie` nodes involved:
890893

891894
[source, cypher]
892895
--
@@ -896,7 +899,7 @@ RETURN DISTINCT bacon, hollywood, p
896899

897900
Here you turn a whole line into a single variable (`p`), so that you can quote it back in `RETURN DISTINCT`, and also retrieve the relationships that connect all of these nodes.
898901

899-
Here is how the graph should look like now:
902+
Here is what the graph should look like now:
900903

901904
image::kevinthreehopsrel.svg[Three hops from Kevin Bacon and other actors and movies, now connected through acted in, directed and produced relationships, link="{imagesdir}/kevinthreehopsrel.svg",role="popup-link"]
902905

0 commit comments

Comments
 (0)