Skip to content

Commit 6b81125

Browse files
committed
update after review
1 parent 1cdb638 commit 6b81125

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

modules/ROOT/pages/cypher/index.adoc

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The "Query fundamentals" gives you a hands-on introduction to Cypher.
4343
Neo4j's graph model is composed of <<nodes>> and <<relationships>>, which may also have assigned <<properties>>.
4444
With nodes and relationships, you can build a graph that can express both simple and complex patterns.
4545

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

4848
[#cypher-syntax]
4949
== Cypher syntax
@@ -61,7 +61,7 @@ link:https://www.youtube.com/watch?v=_dup3YOZSm8[What is Cypher?]
6161
endif::[]
6262

6363
Cypher's constructs are based on English prose and iconography.
64-
This makes queries easy both to write and to read.
64+
It allows the user to get a natural language understanding while programming.
6565

6666
.A graph example involving four nodes and three relationships.
6767
image::cypherintro-graph1.svg[role="popup-link",width=600]
@@ -77,7 +77,7 @@ Now, if you were to write this same information in Cypher, then it would look li
7777
(:Sally)-[:WORKS_FOR]->(:Neo4j)
7878
----
7979

80-
However, in order to have this information in the graph, first you need to represent it as nodes and relationships.
80+
With this query, you turn the information into nodes and relationships, which are the core elements of Cypher.
8181

8282
=== Nodes
8383

@@ -93,17 +93,16 @@ The parentheses are a representation of the circles that compose the nodes in th
9393

9494
==== Node labels
9595

96-
Nodes can be grouped together through a <<label>>.
97-
They work like tags and allow you to specify certain types of entities to look for or to create.
98-
Labels also help Cypher distinguish between entities and optimize execution for your queries.
96+
Nodes can be grouped together through a <<label>>, which is an component that works like tags and allows you to specify certain types of entities in your queries.
97+
Labels also help Cypher distinguish between nodes and optimize execution.
9998

10099
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`:
101100

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

105-
In a relational database context, this would be the same as telling SQL which table to look for the particular row.
106-
The same way you can tell SQL to query a person's information from a `Person` table, you can also tell Cypher to only check the `Person` label for that information.
104+
In a relational database context, this would be the same as using SQL to refer to a table that should be looked for a particular row.
105+
The same way you can use SQL to query a person's information from a `Person` table, you can also use Cypher to only check the `Person` label for that information.
107106

108107
[CAUTION]
109108
====
@@ -114,6 +113,7 @@ This can affect performance in very large graphs.
114113
==== Node variables
115114

116115
It is necessary to bind matched data entities to variables in order to reference them in subsequent clauses.
116+
If part of your query matches nodes that you need to reference in a later part of your query (i.e. in a link:https://neo4j.com/docs/cypher-manual/current/clauses/#reading-sub-clauses[subclause]), you can use *node variables*.
117117

118118
Variables can be single letters or words, and should be written in lower-case.
119119
For example, if you want to bind all nodes labeled `Person` to the variable `p`, you write `(p:Person)`.
@@ -129,20 +129,15 @@ RETURN p
129129
[#cypher-relationships]
130130
=== Relationships
131131

132-
One of the benefits of graph databases is that you can store information about how elements (nodes) are related to each other in the form of relationships.
132+
Similarly to relational databases, graphs can also store information about how elements (nodes) are related to each other in the form of relationships.
133133

134-
In Cypher, relationships are represented as square brackets and an arrow connecting two nodes (e.g. `(Node1)-[]->(Node2)`).
134+
In Cypher, relationships are represented as square brackets with an optional arrow to indicate the direction (e.g. `(Node1)-[]->(Node2)`).
135135

136136
In the example, the lines containing `:LIKES`, `:IS_FRIENDS_WITH`, and `:WORKS_FOR` represent the relationship between the nodes:
137137

138138
.Graph featuring nodes and relationships.
139139
image::cypherintro-graph1.svg[]
140140

141-
[NOTE]
142-
====
143-
Remember to always put a colon in front of a relationship type.
144-
If you happen to forget it, and write a query such as `(:Person)-[LIKES]->(:Technology)`, `[LIKES]` will then represent a xref:cypher/index.adoc#_relationship_variables[relationship *variable*], not a relationship *type*.
145-
====
146141

147142
==== Relationship directions
148143

@@ -196,6 +191,13 @@ In the previous example, the relationship types are:
196191
* `[:IS_FRIENDS_WITH]` - communicates that Sally _is friends with_ John.
197192
* `[:WORKS_FOR]` - communicates that Sally _works for_ Neo4j.
198193

194+
[IMPORTANT]
195+
====
196+
Remember to always put a colon in front of a relationship type.
197+
If you write `(Person)-[LIKES]->(Technology)`, `[LIKES]` will represent a relationship *variable*, not a relationship *type*.
198+
In this case, since no relationship type is declared, Cypher's `RETURN` clause will search for all types of relationships in order to retrieve a result to your query.
199+
====
200+
199201
==== Relationship variables
200202

201203
Variables can be used for relationships in the same way as for nodes.
@@ -227,28 +229,19 @@ image::cypherintro-variables.svg[]
227229
3+d|Rows: 1
228230
|===
229231

230-
Remember to always put a colon in front of a relationship type.
231-
If you happen to forget it, and write the query like this:
232-
233-
[source,cypher]
234-
----
235-
(Person)-[LIKES]->(Technology)
236-
----
237-
238-
`[LIKES]` will represent a relationship *variable*, not a relationship *type*.
239-
In this case, since no relationship type is declared, Cypher will search for all types of relationships in order to retrieve a result to your query.
240-
241232
[#cypher-properties]
242233
=== Properties
243234

244235
Properties can be added both to nodes and relationships and be of a variety of data types.
245236
For a full list of values and types, see link:{docs-home}/cypher-manual/current/values-and-types/[Cypher manual -> Values and types].
246237

247-
Another way to organize the data in the previous example would be to add a *property*, `name`, and `Sally` and `John` as *property values* on `Person`-labeled nodes:
238+
In the following example, `sally` and `john` are xref:cypher/index.adoc##_node_variables[variables] for `Person` nodes which contain a `name` property with the *property values* "Sally" and "John":
248239

249240
.Graph example with node and relationship properties.
250241
image::cypherintro-properties.svg[]
251242

243+
To add this info to the graph, you can use the following query:
244+
252245
[source,cypher]
253246
----
254247
CREATE (sally:Person {name:'Sally'})-[r:IS_FRIENDS_WITH]->(john:Person {name:'John'})
@@ -281,21 +274,29 @@ In order to *do* something with this pattern, such as adding it to or retrieving
281274
For example, you can add this information to the database using the link:{docs-home}/cypher-manual/current/clauses/create/[`CREATE`] clause:
282275

283276
[source, cypher]
284-
----
277+
--
285278
CREATE (sally:Person {name: "Sally"})-[r:LIKES]->(t:Technology {type: "Graphs"})
286-
----
279+
--
287280

288281
And once this data is written to the database, you can retrieve it with this pattern:
289282

290283
[source, cypher]
291-
----
284+
--
292285
MATCH (sally:Person {name: "Sally"})-[r:LIKES]->(t:Technology {type: "Graphs"})
293-
RETURN p,r,t
294-
----
286+
RETURN sally,r,t
287+
--
295288

296-
=== Patterns variables
289+
==== Pattern variables
297290

298291
In the same way as nodes and relationships, you can also use variables for patterns.
292+
Considering the previous example, you can turn contain the whole pattern (`(Sally)-[:LIKES]->(Technology)`) inside a pattern by creating a variable (`p`) for it all:
293+
294+
[source,cypher]
295+
--
296+
MATCH p = (sally:Person {name: "Sally"})-[r:LIKES]->(t:Technology {type: "Graphs"})
297+
RETURN p
298+
--
299+
299300
For more information, refer to link:{docs-home}/cypher-manual/current/patterns/reference/[Cypher manual -> Patterns -> Syntax and Semantics].
300301

301302
== Keep learning

0 commit comments

Comments
 (0)