Normalize as boolean
The APOC library contains a procedure that can be used to translate STRING
values into BOOLEAN
values.
Procedure for translating string values into booleans
Qualified Name | Type |
---|---|
|
Procedure |
Example
The below example will further explain this procedure.
The following creates a graph containing
NODE
values with BOOLEAN
properties represented in different formats:CREATE (:Person {prop: 'Y', name:'A'}),
(:Person {prop: 'Yes', name:'B'}),
(:Person {prop: 'NO', name:'C'}),
(:Person {prop: 'X', name:'D'})
We want to transform some properties into a BOOLEAN
, Y
, Yes
into true and the properties NO
into false.
The other properties that don’t match these possibilities will be set as null
.
The following normalizes all applicable
BOOLEAN
values for all NODE
values that have the prop
property:MATCH (n)
CALL apoc.refactor.normalizeAsBoolean(n,'prop',['Y','Yes'],['NO'])
WITH n
ORDER BY n.id
RETURN n.prop AS prop
If the above query is run, the following will be returned: