Skip to content

Commit

Permalink
Add docs for new normalize predicate expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
gem-neo4j committed Jan 9, 2024
1 parent 7e99bc7 commit d9d1c96
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 1 deletion.
34 changes: 34 additions & 0 deletions modules/ROOT/pages/clauses/where.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,40 @@ The `name` and `age` for `Peter` are are returned because his name contains "ete
|===


[[match-string-is-normalized]]
=== Checking if a string is normalized `IS NORMALIZED`

The `IS NORMALIZED` operator is used to check whether the given `STRING` is in the `NFC` Unicode normalization form:

.Query
[source, cypher]
----
MATCH (n:Person)
WHERE n.name IS NORMALIZED
RETURN n.name AS normalizedNames
----

The given strings contain only normalized Unicode characters, therefore all the names are matched and returned.
See here for more information on the xref:syntax/operators.adoc#match-string-is-normalized[normalization operator].

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| normalizedNames
| 'Andy'
| 'Timothy'
| 'Peter'
2+|Rows: 1
|===

*Considerations:*

|===

| `IS NORMALIZED` returns `null` when used on a non-`STRING` value, e.g. `RETURN 1 IS NORMALIZED` returns `null`.

|===

[[match-string-negation]]
=== String matching negation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ RETURN normalize("string", NFC)
| Introduction of a xref::functions/string.adoc#functions-normalize[normalize()] function.
Normalize a `STRING` according to the specified normalization form, which can be of type `NFC`, `NFD`, `NFKC` or `NFKD`.

a|
label:functionality[]
label:new[]

[source, cypher, role=noheader]
----
IS [NOT] [NFC \| NFD \| NFKC \| NFKD] NORMALIZED
----

[source, cypher, role=noheader]
----
RETURN "string" IS NORMALIZED
----

| Introduction of an xref::syntax/operators.adoc#match-string-is-normalized[IS NORMALIZED] operator.
The operator can be used to check if a `STRING` is normalized according to the specified normalization form, which can be of type `NFC`, `NFD`, `NFKC` or `NFKD`.

|===

[[cypher-deprecations-additions-removals-5.16]]
Expand Down
98 changes: 97 additions & 1 deletion modules/ROOT/pages/syntax/operators.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This page contains an overview of the available Cypher operators.
| xref::syntax/operators.adoc#query-operators-comparison[Comparison operators] | `+=+`, `+<>+`, `+<+`, `+>+`, `+<=+`, `+>=+`, `IS NULL`, `IS NOT NULL`
| xref::syntax/operators.adoc#query-operators-comparison[String-specific comparison operators] | `STARTS WITH`, `ENDS WITH`, `CONTAINS`, `=~` (regex matching)
| xref::syntax/operators.adoc#query-operators-boolean[Boolean operators] | `AND`, `OR`, `XOR`, `NOT`
| xref::syntax/operators.adoc#query-operators-string[String operators] | `+` (string concatenation)
| xref::syntax/operators.adoc#query-operators-string[String operators] | `+` (string concatenation), `IS NORMALIZED`
| xref::syntax/operators.adoc#query-operators-temporal[Temporal operators] | `+` and `-` for operations between durations and temporal instants/durations, `*` and `/` for operations between durations and numbers
| xref::syntax/operators.adoc#query-operators-map[Map operators] | `.` for static value access by key, `[]` for dynamic value access by key
| xref::syntax/operators.adoc#query-operators-list[List operators] | `+` (list concatenation), `IN` to check existence of an element in a list, `[]` for accessing element(s) dynamically
Expand Down Expand Up @@ -543,6 +543,7 @@ RETURN number
The string operators comprise:

* concatenating strings: `+`
* checking if a string is normalized: `IS NORMALIZED`


[[syntax-concatenating-two-strings]]
Expand All @@ -563,6 +564,101 @@ RETURN 'neo' + '4j' AS result
|===


[[match-string-is-normalized]]
=== Checking if a string is normalized `IS NORMALIZED`

The `IS NORMALIZED` operator is used to check whether the given `STRING` is in the `NFC` Unicode normalization form:

.Query
[source, cypher]
----
RETURN "the \u212B char" IS NORMALIZED AS normalized
----

The given string contains a non-normalized Unicode character: `\u212B`, therefore `false` is returned.
To normalize the string, it is possible to use the xref:functions/string.adoc#functions-normalize[normalize()] function.

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| normalized
| false
2+|Rows: 1
|===

*Considerations:*

|===

| `IS NORMALIZED` returns `null` when used on a non-`STRING` value, e.g. `RETURN 1 IS NORMALIZED` returns `null`.

|===


[[match-string-is-not-normalized]]
=== Checking if a string is not normalized `IS NOT NORMALIZED`

The `IS NOT NORMALIZED` operator is used to check whether the given `STRING` is not in the `NFC` Unicode normalization form:

.Query
[source, cypher]
----
RETURN "the \u212B char" IS NOT NORMALIZED AS notNormalized
----

The given string contains a non-normalized Unicode character: `\u212B`, therefore `true` is returned, as the string is not normalized.
To normalize the string, it is possible to use the xref:functions/string.adoc#functions-normalize[normalize()] function.

.Result
[role="queryresult",options="header,footer",cols="1*<m"]
|===
| notNormalized
| true
2+|Rows: 1
|===

*Considerations:*

|===

| `IS NOT NORMALIZED` returns `null` when used on a non-`STRING` value, e.g. `RETURN 1 IS NOT NORMALIZED` returns `null`.

|===


==== Using `IS NORMALIZED` with a specified normalization type
It is also possible to define which Unicode normalization type is used, with the default being `NFC`.

The possible normalization types are:

* `NFC`
* `NFD`
* `NFKC`
* `NFKD`

.Query
[source, cypher]
----
WITH "the \u00E4 char" as myString
RETURN myString IS NFC NORMALIZED AS nfcNormalized,
myString IS NFD NORMALIZED AS nfdNormalized
----

The given string contains the Unicode character: `\u00E4`, which is considered normalized in `NFC` form, but not in `NFD` form.

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| nfcNormalized | nfdNormalized
| true | false
2+|Rows: 2
|===

It is also possible to specify the normalization form when using the negated normalization predicate e.g. `RETURN "string" IS NOT NFD NORMALIZED`.




[[query-operators-temporal]]
== Temporal operators

Expand Down

0 comments on commit d9d1c96

Please sign in to comment.