当我尝试创建具有虚拟关系的子图时,图表中的真实关系就会显示出来

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

我的数据库中有两个大图。当我在第一张图上使用它时,这是一个运行良好的查询:

MATCH (fe:FEATURE)-->+(t:THREAT)-->+(g:GAP)
MATCH (g)<--+(fa:FACT)
where t.key="FRAUD_PAN" 
WITH collect(DISTINCT [fe, t]) + collect(DISTINCT [t, g]) AS hases,
    collect(DISTINCT [fa, g]) AS requireses
WITH 
    COLLECT {
        WITH hases
        UNWIND hases AS pair
        RETURN [
            pair[0], 
            apoc.create.vRelationship(pair[0], 'HAS', {}, pair[1]), 
            pair[1]
        ] AS tuple
    } +
    COLLECT {
        WITH requireses
        UNWIND requireses AS pair
        RETURN [
            pair[0], 
            apoc.create.vRelationship(pair[0], 'REQUIRE', {}, pair[1]), 
            pair[1]
        ] AS tuple
    } AS tuples
UNWIND tuples AS tuple
RETURN tuple[0], tuple[1], tuple[2]

这是它的输出

enter image description here

如果我通过根据图表更改威胁键来在另一个图表上使用相同的查询,则这是输出

enter image description here 为什么会产生两个HAS关系呢?一种是通过查询创建的虚拟关系,另一种关系来自主图。为什么会出现这种情况?

这是此查询的另一个版本,其中包含一些其他节点

// Match and collect the nodes and relationships
MATCH (fe:FEATURE)-->+(t:THREAT)-->+(g:GAP)
MATCH (g)<--+(fa:FACT)
MATCH (g)-->+(s:SCENARIO)
MATCH (fa)<--+(d:DATA)
WHERE fe.key="Test_S3 Storage"
WITH DISTINCT fe, t, g, fa, s, d

// Collect distinct pairs for each relationship type
WITH 
    collect(DISTINCT [fe, t]) AS hases,
    collect(DISTINCT [t, g]) AS threat_gaps,
    collect(DISTINCT [fa, g]) AS requireses,
    collect(DISTINCT [g, s]) AS scenarioes,
    collect(DISTINCT [d, fa]) AS datas
WITH 
    hases + threat_gaps + requireses + scenarioes + datas AS all_pairs
UNWIND all_pairs AS pair

// Create unique identifiers for virtual relationships
WITH DISTINCT pair[0] AS fromNode, pair[1] AS toNode,
    CASE
        WHEN pair[0]:FEATURE AND pair[1]:THREAT THEN 'V_HAS1'
        WHEN pair[0]:THREAT AND pair[1]:GAP THEN 'V_HAS2'
        WHEN pair[0]:FACT AND pair[1]:GAP THEN 'V_REQUIRE1'
        WHEN pair[0]:GAP AND pair[1]:SCENARIO THEN 'V_HAS3'
        WHEN pair[0]:DATA AND pair[1]:FACT THEN 'V_OF1'
    END AS relationshipType

// Return only virtual relationships, ensuring no real relationships are included
RETURN DISTINCT fromNode, apoc.create.vRelationship(fromNode, relationshipType, {}, toNode) AS virtualRelationship, toNode

这是它的输出

enter image description here 可以看出,即使在虚拟关系的密码中没有定义原始关系HAS,它也是存在的。 为什么真正的关系没有出现在我的第一张图中,如上所示?我对此很困惑。

neo4j cypher neo4j-apoc
1个回答
0
投票

neo4j-desktop 导致原始(存在于主图中)关系以虚拟关系出现在图中。我必须禁用该属性才能消除这些不相关的边缘。 这是导致问题的属性:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.