我刚刚在十分钟前下载并安装了Neo4j 3.0.0。我正在用Neo4j创建一个图形数据库。
当我尝试一次运行3个语句时,出现错误:
Can't create node 'famA' with labels or properties here. The variable is already declared in this context
(这是我试图放入定义节点的地方)。
我不确定问题是什么。我的第一个想法是我需要在块之间携带变量,因为我以前遇到过这个问题,但这似乎是一个不同的情况(抱歉,我还是Neo4j的新手)。
看看famA
发生了什么,它只被声明一次,看起来语法还可以吗?好的就在这里:
// Create the definition node:
CREATE
(famA:Family {family_ID:'A'})
WITH famA
MATCH (a:Person {name:"a"})-[*]-(b:Person)
MERGE (famA:Family)<-[:FAMILY]-(a)
MERGE (famA:Family)<-[:FAMILY]-(b)
我还想注意,我的剧本上周工作正常 - 也许这是一个新版本的问题?
有没有人有任何想法?谢谢。
以下是创建db的代码:
// First family: family_ID = A. This family has 3 members with Alzheimers who are not alive, and more than half of them are Left handed
CREATE
( a:Person {name: 'a', id:'1', Gender:'Male', Diagnosis: 'Alzheimers', `Is Alive?`: 'No', Handedness: 'Left', `Risk Score`: 'PURPLE'}),
( aSP:Person {name: 'aSP', id:'2', Gender:'Female', Diagnosis: 'Alzheimers', `Is Alive?`: 'No', Handedness: 'Left', `Risk Score`: 'GIRAFFE'}),
( b:Person {name: 'b', id:'3', Gender:'Male', Diagnosis: 'Normal', `Is Alive?`: 'No', Handedness: 'Left', `Risk Score`: 'PURPLE'}),
( bSP:Person {name: 'bSP', id:'4', Gender:'Female', Diagnosis: 'Alzheimers', `Is Alive?`: 'No', Handedness: 'Right', `Risk Score`: 'GIRAFFE'}),
(bSib:Person {name: 'bSib', id:'5', Gender:'Female', Diagnosis: 'MCI', `Is Alive?`: 'No', Handedness: 'Left', `Risk Score`: 'GIRAFFE'}),
( c:Person {name: 'c', id:'6', Gender:'Male', Diagnosis: 'MCI', `Is Alive?`: 'No', Handedness: 'Right', `Risk Score`: 'PURPLE'}),
(cSib:Person {name: 'cSib', id:'7', Gender:'Female', Diagnosis: 'Alzheimers', `Is Alive?`: 'Yes', Handedness: 'Left', `Risk Score`: 'GIRAFFE'})
CREATE
(a)-[:SPOUSE]->(aSP),
(b)-[:CHILD]->(a),
(b)-[:CHILD]->(aSP),
(b)-[:SPOUSE]->(bSP),
(bSib)-[:SIBLING]->(b),
(bSib)-[:CHILD]->(aSP),
(c)-[:CHILD]->(b),
(c)-[:CHILD]->(bSP),
(cSib)-[:SIBLING]->(c),
(cSib)-[:CHILD]->(bSP)
// Create the definition node:
CREATE
(famA:Family {family_ID:'A'})
WITH famA
MATCH (a:Person {name:"a"})-[*]-(b:Person)
MERGE (famA:Family)<-[:FAMILY]-(a)
MERGE (famA:Family)<-[:FAMILY]-(b)
答案 0 :(得分:3)
从famA merge
删除标签(如果您使用带有标签的merge
- 它将表示节点创建,但此节点先前已创建):
// Create the definition node:
CREATE
(famA:Family {family_ID:'A'})
WITH famA
MATCH (a:Person {name:"a"})-[*]-(b:Person)
MERGE (famA)<-[:FAMILY]-(a)
MERGE (famA)<-[:FAMILY]-(b)
答案 1 :(得分:0)
我有类似的情况需要改变这个:
MATCH (ks1:KbWordSequence)
MATCH (ks2:KbWordSequence {kbidseq: ks1.kbidseqnxt})
CREATE (ks1)-[:NEXT]->(ks2)
MERGE (ks1:KbWordSequence)-[:NEXT]->(ks2:KbWordSequence {kbidseqnxt: ks1.kbidseq})
到此:
MATCH (ks1:KbWordSequence)
MATCH (ks2:KbWordSequence {kbidseq: ks1.kbidseqnxt})
CREATE (ks1)-[:NEXT]->(ks2)
MERGE (ks1)-[:NEXT]->(ks2)
SET ks2.kbidseqnxt = ks1.kbidseq
基本上我不允许在第二个MERGE语句中设置节点值,我必须在该合并上添加一个SET。