Data mapping in gds projection

  • neo4j 5.5.0, gds 2.4.5

I am trying to create a new gds project by executing the following cypher:

MATCH (source:staff {dept: 'IT'})-[r:relation]->(target:staff {dept: 'IT'}) 
WITH gds.graph.project(
    'Temp', 
    source, 
    target,
    {
        sourceNodeProperties: source {.pos},
        targetNodeProperties: target {.pos}
    }
    ) as g
RETURN g

Cypher works while node property 'pos' is intiger. However, in my database, this attribute has been set to be string, like 'product manager', 'UI designer', etc. Since I am not authorized to alter my datasource, I cannot use 'set' function to rewrite this attribute.

Suppose I have such dictionary for attribute 'pos':

{0: product manager, 1: UI designer, 2: data scientist}

Is there any way to insert a case when, or other workable mapping syntax, to create a new GDS project with the above mapping affected?

I noticed in an example in the documentation that they use the coalesce function to set a default value in the node property mapped. This leads me to believe the maps are derived for each node. As such, maybe you can add a case statement in the node property maps to derive a new attribute based on ‘pos’ that is an integer.

For example:

MATCH (source:staff {dept: 'IT'})-[r:relation]->(target:staff {dept: 'IT'}) 
WITH gds.graph.project(
    'Temp', 
    source, 
    target,
    {
        sourceNodeProperties: {posint: case when source.pos = ‘UI’ then 1 when source.pos =‘manager’ then 2 else 3 end },
        targetNodeProperties: {.pos}
    }
    ) as g
RETURN g
2 Likes

It works! Appreciate so much!

I tried like

(case when source.pos = ‘UI’ then 1 when source.pos =‘manager’ then 2 else 3 end) as posint

before and surely failed :rofl:

1 Like