Cypher 查询中的问题 - org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException

Issue in Cypher Query - org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException

我正在使用密码查询执行以下步骤。我在第 3 步中遇到错误。我在下面列出了所有步骤。请帮助我达到预期的输出。

第 1 步 - 加载数据并定义节点关系的属性



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);

示例查询和 table 结构

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
}

步骤 2 - 创建图形投影

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 *

当前输出

第 3 步 - 尝试根据 属性“esg_index”为节点着色,并根据 属性“情感”为边着色(抛出错误的查询)

CALL apoc.create.addLabels(n.esg_index, [apoc.text.upperCamelCase(n.id)]) YIELD node
RETURN *

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.

预期输出

节点和边着色的图表。基于 esg_index 着色的节点和基于情绪

着色的边

APOC addLabels 函数将节点列表或它们的 id 作为其输入,可以使用 ID(n) 找到它们。您正在传递 esg_index,这就是您可能收到此错误的原因:

试试这个:

CALL apoc.create.addLabels(n, [apoc.text.upperCamelCase(n.id)]) YIELD node
RETURN *

应该可以。 Documentation link.

更新:

要使用 esg_index 添加标签,我认为 apoc.do.case 函数应该可以满足您的需要。你可以尝试这样的事情:

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;