简体   繁体   English

从neo4J StatementResult中提取关系

[英]Extracting relationships from a neo4J StatementResult

How do I extract relationships from a StatementResult? 如何从StatementResult中提取关系?

For the moment I have something like this: 目前,我有这样的事情:

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

            }

My original query was something like this: 我原来的查询是这样的:

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

I need all the "connectsTo" relationships 我需要所有的“ connectsTo”关系

Hope that makes sense. 希望有道理。

First you need to specify those relations' aliases and return them like nodes. 首先,您需要指定这些关系的别名,并像节点一样返回它们。 Simplified example: 简化示例:

MATCH (a:Block)-[r:PART_OF]->(b:Block) RETURN a, r, b

This way, your Record instances will contain data (Value instances) for a, r and b. 这样,您的Record实例将包含a,r和b的数据(值实例)。 And in your extraction logic you do the following to get the relationship data: 然后在提取逻辑中执行以下操作以获取关系数据:

Relationship r = record.get("r").asRelationship();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM