Java 从neo4J语句中提取关系Result
如何从语句Result中提取关系 目前我有这样的想法:Java 从neo4J语句中提取关系Result,java,neo4j,cypher,Java,Neo4j,Cypher,如何从语句Result中提取关系 目前我有这样的想法: while (results.hasNext()) { Record record = results.next(); try { if (record.get(0).hasType(TYPE_SYSTEM.NODE())){ Node node = record.get(0).asNode(); //System.out
while (results.hasNext()) {
Record record = results.next();
try {
if (record.get(0).hasType(TYPE_SYSTEM.NODE())){
Node node = record.get(0).asNode();
//System.out.println(node.get("name") + ": " + node.get("guid"));
// Add block
if (node.hasLabel(configuration.getBlock())) {
Block block = Block.fromRecord(node);
blocks.addBlock(block);
} else
// Add property
if (node.hasLabel(configuration.getProp())) {
Property property = Property.fromRecord(node);
String guid = property.getGuid();
Block block = blocks.getBlock(guid);
block.addProperty(property);
} else
// Add output
if (node.hasLabel(configuration.getOutput())) {
Output output = Output.fromRecord(node);
String guid = output.getGuid();
Block block = blocks.getBlock(guid);
block.addOutput(output);
} else
// Add input
if (node.hasLabel(configuration.getInput())) {
Input input = Input.fromRecord(node);
inputs.add(input);
String guid = input.getGuid();
}
}
MATCH (start:Block{name:'block_3'})
CALL apoc.path.subgraphNodes(start, {relationshipFilter:'PART_OF|hasOutPort>|connectsTo>|<hasInPort'}) YIELD node as block
WITH
block,
[(block)-[:PART_OF]->(prop) | prop] as properties,
[(block)-[:hasOutPort]->(output) | output] as outputs,
[(block)-[:hasInPort]->(input) | input] as inputs
RETURN block, properties, outputs, inputs
我最初的查询是这样的:
while (results.hasNext()) {
Record record = results.next();
try {
if (record.get(0).hasType(TYPE_SYSTEM.NODE())){
Node node = record.get(0).asNode();
//System.out.println(node.get("name") + ": " + node.get("guid"));
// Add block
if (node.hasLabel(configuration.getBlock())) {
Block block = Block.fromRecord(node);
blocks.addBlock(block);
} else
// Add property
if (node.hasLabel(configuration.getProp())) {
Property property = Property.fromRecord(node);
String guid = property.getGuid();
Block block = blocks.getBlock(guid);
block.addProperty(property);
} else
// Add output
if (node.hasLabel(configuration.getOutput())) {
Output output = Output.fromRecord(node);
String guid = output.getGuid();
Block block = blocks.getBlock(guid);
block.addOutput(output);
} else
// Add input
if (node.hasLabel(configuration.getInput())) {
Input input = Input.fromRecord(node);
inputs.add(input);
String guid = input.getGuid();
}
}
MATCH (start:Block{name:'block_3'})
CALL apoc.path.subgraphNodes(start, {relationshipFilter:'PART_OF|hasOutPort>|connectsTo>|<hasInPort'}) YIELD node as block
WITH
block,
[(block)-[:PART_OF]->(prop) | prop] as properties,
[(block)-[:hasOutPort]->(output) | output] as outputs,
[(block)-[:hasInPort]->(input) | input] as inputs
RETURN block, properties, outputs, inputs
匹配(开始:块{name:'Block_3'})
调用apoc.path.subgraphNodes(start,{relationshipFilter:'PART|u OF | hasOutPort>| connectsTo>|),首先需要指定这些关系的别名并像节点一样返回它们。简化示例:
MATCH (a:Block)-[r:PART_OF]->(b:Block) RETURN a, r, b
这样,您的记录实例将包含a、r和b的数据(值实例)。在提取逻辑中,您将执行以下操作以获取关系数据:
Relationship r = record.get("r").asRelationship();