apoc.refactor.normalizeAsBoolean

Procedure APOC Core

apoc.refactor.normalizeAsBoolean(entity, propertyKey, true_values, false_values) normalize/convert a property to be boolean

Signature

apoc.refactor.normalizeAsBoolean(entity :: ANY?, propertyKey :: STRING?, true_values :: LIST? OF ANY?, false_values :: LIST? OF ANY?) :: VOID

Input parameters

Name Type Default

entity

ANY?

null

propertyKey

STRING?

null

true_values

LIST? OF ANY?

null

false_values

LIST? OF ANY?

null

Usage Examples

The examples in this section are based on the following sample graph:

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 nodes that have the prop property:
MATCH (n)
CALL apoc.refactor.normalizeAsBoolean(n,'prop',['Y','Yes'],['NO'])
WITH n
ORDER BY n.id
RETURN n.name AS name, n.prop AS prop;
Table 1. Results
name prop

"A"

TRUE

"B"

TRUE

"C"

FALSE

"D"

NULL