I am performing the below steps using a cypher query, but am an getting error in step 3. I have listed all steps below.
Step 1. Load data and define properties of nodes relationship
CREATE CONSTRAINT IF NOT EXISTS ON (org: Organisation) ASSERT org.id IS UNIQUE;
LOAD CSV WITH HEADERS FROM 'file://nodes_1Jan22_full_v2.csv' AS row
CREATE (n: Organisation {id: row.organisation, esg_index: toFloat(row.tone)});
LOAD CSV WITH HEADERS FROM 'file://edges_1Jan22_full_v2.csv' AS row
MERGE (src: Organisation {id: row.src})
MERGE (dst: Organisation {id: row.dst})
MERGE (src)-[:RELATE {freq: toInteger(row.relationship), sentiment: toFloat(row.avg_tone)}]->(dst);
Sample query and table structure
MATCH p=()-[r:RELATE]->() RETURN p LIMIT 1
{
"start": {
"identity": 18862,
"labels": [
"Organisation"
],
"properties": {
"id": "american university",
"esg_index": -3.005288932058546
}
},
"end": {
"identity": 20048,
"labels": [
"Organisation"
],
"properties": {
"id": "duke university",
"esg_index": -1.6810932825414502
}
},
"segments": [
{
"start": {
"identity": 18862,
"labels": [
"Organisation"
],
"properties": {
"id": "american university",
"esg_index": -3.005288932058546
}
},
"relationship": {
"identity": 0,
"start": 18862,
"end": 20048,
"type": "RELATE",
"properties": {
"sentiment": -4.367701625823974,
"freq": 250
}
},
"end": {
"identity": 20048,
"labels": [
"Organisation"
],
"properties": {
"id": "duke university",
"esg_index": -1.6810932825414502
}
}
}
],
"length": 1.0
}
Step 2. Create graph projection
CALL gds.graph.project(
'gdelt-analytics',
'Organisation',
'RELATE',
{
relationshipProperties: 'freq'
}
)
MATCH (org:Organisation {id: 'public health'})
CALL gds.pageRank.stream('gdelt-analytics', {
maxIterations: 100,
dampingFactor: 0.85,
sourceNodes: [org],
relationshipWeightProperty: 'freq'
})
YIELD nodeId, score
RETURN *
Current Output
Step 3. Attempt to color node based on property "esg_index" and edges based on property "sentiment" (Query that is throwing error)
MATCH (n:Organisation )
CALL apoc.create.addLabels(n.esg_index, [apoc.text.upperCamelCase(n.id)]) YIELD node
RETURN *
Error:
Neo.ClientError.Procedure.ProcedureCallFailed Failed to invoke procedure
apoc.create.addLabels
: Caused by: org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException: Unable to load NODE with id -2.
Expected Output
Graph with nodes and edges colored. Nodes colored based on esg_index and edges colored based on sentiment
The APOC
addLabels
function takes either a list of nodes or their id, which can be found using ID(n)
, as its input. You are passing esg_index, that's why you might be getting this error:
Try this:
CALL apoc.create.addLabels(n, [apoc.text.upperCamelCase(n.id)]) YIELD node
RETURN *
It should work. Documentation link.
Update:
To add the label using esg_index, I think apoc.do.case
function should do the trick for you. You can try something like this:
CALL apoc.do.case([
n IS NOT NULL AND n.esg_index = -5,
'SET n:DARK_RED RETURN n AS node',
n IS NOT NULL AND n.esg_index = 1,
'SET n:GREEN RETURN n AS node'
],
'RETURN n AS node',{n: n})
YIELD value
RETURN value.node AS node;