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

问题描述 投票:0回答:1

我正在使用密码查询执行以下步骤,但在步骤 3 中出现错误。我在下面列出了所有步骤。

步骤1.加载数据并定义节点关系属性

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

示例查询和表结构

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”对节点进行着色,并根据属性“sentiment”对边进行着色(引发错误的查询)

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

错误:

Neo.ClientError.Procedure.ProcedureCallFailed 无法调用过程

apoc.create.addLabels
:原因:org.neo4j.internal.kernel.api.exceptions.EntityNotFoundException:无法加载 ID 为 -2 的 NODE。

预期输出

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

neo4j cypher graph-databases
1个回答
1
投票

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

试试这个:

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

应该可以。 文档链接

更新:

要使用 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;
© www.soinside.com 2019 - 2024. All rights reserved.