2017-06-23 5 views
0

Wie extrahiere ich Beziehungen aus einem StatementResult?Extrahieren von Beziehungen aus einem neo4J StatementResult

Im Moment habe ich so etwas wie dieses:

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

      } 

Meine ursprüngliche Abfrage so etwas wie das war:

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 

Ich brauche alle "connectsTo" Beziehungen

Hoffnung, dass macht Sinn.

Antwort

0

Zuerst müssen Sie die Aliase dieser Beziehungen angeben und sie wie Knoten zurückgeben. Vereinfachtes Beispiel:

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

Auf diese Weise enthalten Ihre Record-Instanzen Daten (Value-Instanzen) für a, r und b. Und in Ihrer Extraktionslogik machen Sie Folgendes, um die Beziehungsdaten zu erhalten:

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