Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Neo4J在关系中结合_Java_Database_Neo4j_Cypher - Fatal编程技术网

Java Neo4J在关系中结合

Java Neo4J在关系中结合,java,database,neo4j,cypher,Java,Database,Neo4j,Cypher,我正在尝试运行关系创建,但由于某些原因,我无法在关系查询中使用coalesce。我完全卡住了,其中一些可能是错误的,但我试图一步一步地修复它。这是我的密码 /* Get the kill assassin and student by relation UUID*/ 'MATCH (a:Student)-[r:TARGET]->(t:Student) WHERE r.uuid = $uuid ' + /* Lets Kill the student and set confirmed to

我正在尝试运行关系创建,但由于某些原因,我无法在关系查询中使用coalesce。我完全卡住了,其中一些可能是错误的,但我试图一步一步地修复它。这是我的密码

/* Get the kill assassin and student by relation UUID*/
'MATCH (a:Student)-[r:TARGET]->(t:Student) WHERE r.uuid = $uuid ' +
/* Lets Kill the student and set confirmed to true */
'SET r.confirmed = true, t.IsDead = true WITH ' +
/* Delete any teachers that may have the target of the student*/
'MATCH (t)<-[tr:TARGET]-(:Teacher) DELETE r ' +
/* Get the assassinated persons target. Set them as X. */
'MATCH (t)-[ar:TARGET]->(x:Student) WHERE ar.confirmed = false AND x.IsDead = false ' +
/* Lets deal with anyone who inherited our target if we are dead :(*/
'OPTIONAL MATCH (t)<-[sr:TARGET]-(ss:Student) WHERE sr.confirmed = false AND ss.IsDead = false ' +
/* Lets steal their kill node and set them as our new target unless of course someone decided to kill us and nab them */
'CREATE (COALESCE(t,a))-[nr:TARGET {killed:false,confirmed:false}]->(t) '
/*通过关系UUID获得杀人刺客和学生*/
'匹配(a:Student)-[r:TARGET]->(t:Student),其中r.uuid=$uuid'+
/*让我们杀了这个学生,并将确认设置为真*/
'设置r.confirm=true,t.IsDead=true,带'+
/*删除任何可能以该学生为目标的教师*/
'匹配(t)(x:学生),其中ar.confirm=false和x.IsDead=false'+
/*如果我们死了,让我们来对付任何继承我们目标的人:(*/
'可选匹配(t)(t)'
编辑:我经常清理我的代码。只是为了记录合并不能在关系中使用。下面是清理后的代码,供那些想知道的人使用

/**
     * a: The student who made the kill
     * v: The victim of the kill
     * r: the relationship between a and t
     * x: the victims target
     * tr (OPTIONAL) : the teacher who we hired to kill our target
     * ss: The person who will be inheriting t(victim)'s target
     */
    /* Get the Killer, set them as A AND set the Victim as T */
    'MATCH (a:Student)-[r:TARGET {uuid:$uuid,confirmed:false}]->(v:Student),' +
    /* Fetch the Victims Target and set them as x */
    '(v)-[:TARGET {confirmed:false}]->(x:Student {IsDead:false}) ' +
    /* Check if we hired a teacher to assassinate our target. Set the relationship to TR (teacher relation)*/
    'OPTIONAL MATCH (v)<-[tr:TARGET]-(:Teacher) ' +
    /* Fetch the alive person who has the target (in-case we died and then it went into review) */
    'MATCH (v)<-[sr:TARGET {confirmed:false}]-(ss:Student {IsDead:false}) ' +
    /* Create a relationship between SS and t */
    'CREATE (ss)-[:TARGET {killed:false,confirmed:false}]->(x) ' +
    /* Set the Kill Relationship to complete and kill the victim */
    'SET r.confirmed = true, v.IsDead = true,a.Balance = a.Balance + 3 ' +
    /* Delete the teacher relationship */
    'DELETE tr ', {uuid:uuid}
/**
*a:是那个杀人的学生
*v:谋杀案的受害者
*r:a和t之间的关系
*x:受害者的目标
*tr(可选):我们雇佣来杀死目标的老师
*ss:将继承t(受害者)目标的人
*/
/*找到凶手,把他们设为A,把受害者设为T*/
'匹配(a:学生)-[r:目标{uuid:$uuid,确认:false}]>(v:学生),'+
/*找到受害者目标并将其设置为x*/
“(v)-[:目标{已确认:错误}]>(x:Student{IsDead:false})”+
/*检查我们是否雇佣了一名教师来刺杀我们的目标。将关系设置为TR(教师关系)*/

'可选匹配(v)您不能在
CREATE
中使用表达式-但您可以将该表达式移动到
WITH
语句中,将其分配给变量,然后在CREATE中使用该变量

最后一行可以替换为:

/* Lets steal their kill node and set them as our new target unless of course someone decided to kill us and nab them */
WITH COALESCE(t, a) as n, t
CREATE (n)-[nr:TARGET {killed:false,confirmed:false}]->(t)
这可以很好地编译,但我必须首先解决查询中的一些其他问题:

  • 第2行,
    SET r.comfirmed…
    结尾,后面有
    ,但后面没有变量
  • 第3行,
    MATCH(t)(t:Student),其中r.uuid=$uuid
    /*让我们杀了这个学生,并将确认设置为真*/
    设置r.confirm=true,t.IsDead=true
    /*删除任何可能以该学生为目标的教师*/
    用a,t,r
    匹配(t)(x:学生),其中ar.confirm=false和x.IsDead=false
    /*如果我们死了,让我们来对付任何继承我们目标的人:(*/
    可选匹配(t)(t)
    
    但即使这样,它看起来也是错误的,
    COALESCE
    将始终解析为
    t
    ,因为要在查询中取得如此大的成功,
    t
    必须有一个值,因此最后一个
    CREATE
    将只是在
    t
    和自身之间创建一个关系。另外,
    可选匹配
    引入了新变量ss
但是该变量不在其他任何地方使用(使得可选匹配有些冗余)


我猜,
合并
应该在
ss
a
之间,而不是
t
a
,但这很难说。

你不能在
CREATE
中使用表达式,但你可以用
语句将该表达式移动到
中,将其赋值给变量,然后使用该变量在你的创造中是不稳定的

最后一行可以替换为:

/* Lets steal their kill node and set them as our new target unless of course someone decided to kill us and nab them */
WITH COALESCE(t, a) as n, t
CREATE (n)-[nr:TARGET {killed:false,confirmed:false}]->(t)
这可以很好地编译,但我必须首先解决查询中的一些其他问题:

  • 第2行,
    SET r.comfirmed…
    结尾,后面有
    ,但后面没有变量
  • 第3行,
    MATCH(t)(t:Student),其中r.uuid=$uuid
    /*让我们杀了这个学生,并将确认设置为真*/
    设置r.confirm=true,t.IsDead=true
    /*删除任何可能以该学生为目标的教师*/
    用a,t,r
    匹配(t)(x:学生),其中ar.confirm=false和x.IsDead=false
    /*如果我们死了,让我们来对付任何继承我们目标的人:(*/
    可选匹配(t)(t)
    
    但即使这样,它看起来也是错误的,
    COALESCE
    将始终解析为
    t
    ,因为要在查询中取得如此大的成功,
    t
    必须有一个值,因此最后一个
    CREATE
    将只是在
    t
    和自身之间创建一个关系。另外,
    可选匹配
    引入了新变量ss
但是该变量不在其他任何地方使用(使得可选匹配有些冗余)


我猜,
合并
应该在
ss
a
之间,而不是
t
a
,但这很难说。

非常感谢你的帮助。这让我找到了最终的解决方案,它更干净、更有条理。我将很快发布编辑。非常感谢你的帮助。这让我找到了我的final解决方案更干净、更有条理。我很快会发布一个编辑。这张图应该是什么?@manonthemat这是一个名为高级刺客的游戏。检查这里的回复这张图应该是什么?@manonthemat这是一个名为高级刺客的游戏。检查这里的回复