Skip to content

Commit

Permalink
Update Patterns with new var-length table and quantified relationship…
Browse files Browse the repository at this point in the history
… information (#789)
  • Loading branch information
JPryce-Aklundh committed Nov 22, 2023
1 parent 7edbd9f commit c36c388
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions modules/ROOT/pages/patterns/reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -697,17 +697,20 @@ For example, the following quantified relationship:

[source, role=noheader]
----
()-[r]->{m,n}()
(:A)-[r:R]->{m,n}(:B)
----

is equivalent to the following quantified path pattern, with empty node patterns on either side:
is equivalent to the following quantified path pattern:

[source, role=noheader]
----
() (()-[r]->()){m,n} ()
(:A) (()-[r:R]->()){m,n} (:B)
----

However, unlike a quantified path pattern, a quantified relationship must always have a node pattern on each side.
With the expanded form of a quantified path pattern, it is possible to add predicates inside.
Conversely, if the only predicate is a relationship type expression, query syntax can be more concise using a quantified relationship.

Note that, unlike a quantified path pattern, a quantified relationship must always have a node pattern on each side.

[[quantified-relationship-examples]]
=== Examples
Expand Down Expand Up @@ -1106,26 +1109,31 @@ For rules on valid relationship variable names, see xref:syntax/naming.adoc[Cyph
[[variable-length-relationships-rules]]
=== Rules

The following table shows variants of the variable-length quantifier syntax and their equivalent canonical xref:patterns/reference.adoc#quantifier[quantifier] form (the form used by xref:patterns/reference.adoc#quantified-path-pattern[quantified path patterns]):
The following table shows variants of the variable-length quantifier syntax and their equivalent xref:patterns/reference.adoc#quantifiers[quantifier] form (the form used by xref:patterns/reference.adoc#quantified-path-patterns[quantified path patterns]):

[options="header",cols="1m,1a"]
[options="header",cols="1m,1a,1m,1m"]
|===
| *Variant* | *Description*
| *Variant* | *Description* | *Quantified relationship equivalent* | *Quantified path pattern equivalent*

| -[*]\-> | 1 or more iterations. | -[]\->+ | \(()-[]\->())+

| -[*n]\-> | Exactly n iterations. | -[]\->\{n} | \(()-[]\->())\{n}

| -[*m..n]\->| Between m and n iterations. | -[]\->{m,n} | \(()-[]\->()){m,n}

| * | 1 or more iterations.
| -[*m..]\-> | m or more iterations. | -[]\->{m,} | \(()-[]\->()){m,}

| *n | Exactly n iterations.
| -[*0..]\-> | 0 or more iterations. | -[]\->* | \(()-[]\->())*

| *m..n | Between m and n iterations.
| -[*..n]\-> | Between 1 and n iterations. | -[]\->{1,n} | \(()-[]\->()){1,n}

| *m.. | m or more iterations.
| -[*0..n]\-> | Between 0 and n iterations. | -[]\->{,n} | \(()-[]\->()){,n}

|*..n | Between 1 and n iterations.
|===

Note that `*` used here on its own is not the same as the Kleene star (an operator that represents zero or more repetitions), as the Kleene star has a lower bound of zero.
The above table can be used to translate the quantifier used in variable-length relationships.
The rules given for xref:patterns/reference.adoc#quantified-path-pattern[quantified path patterns] would apply to the translation.
The rules given for xref:patterns/reference.adoc#quantified-path-patterns[quantified path patterns] would apply to the translation.

This table shows some examples:

Expand Down

0 comments on commit c36c388

Please sign in to comment.