From e15c9244705969575a691131ff1fbc418f83ce93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jens=20Pryce-=C3=85klundh?= <112686610+JPryce-Aklundh@users.noreply.github.com> Date: Wed, 22 Nov 2023 14:31:44 +0100 Subject: [PATCH] Update Patterns with new var-length table and quantified relationship information (#789) (#792) --- modules/ROOT/pages/patterns/reference.adoc | 34 +++++++++++++--------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/modules/ROOT/pages/patterns/reference.adoc b/modules/ROOT/pages/patterns/reference.adoc index 134a4006c..e3d81a82b 100644 --- a/modules/ROOT/pages/patterns/reference.adoc +++ b/modules/ROOT/pages/patterns/reference.adoc @@ -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 @@ -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: