Skip to content
topofocus edited this page Apr 19, 2019 · 6 revisions

Lets start with a simple graph:

10 V2-vertices, with an attritute node: 1 .. 10 connected via E2-Edges to a V1-Vertex with an attribute item: 1

  ORD.create_vertex_class  :v1 
  ORD.create_class( :v2 ){ V1 } 
  ORD.create_edge_class "e1"
  ORD.create_class( :e2 ){ E1 }
  ORD.create_class( :e3 ){ E1 }
  vertices =  (1..10).map{|y| V2.create node: y}  
  E2.create from: V1.create( item: 1  ), to: vertices  

A Match-Query starts at a given Vertex-Class. The where-cause narrows the sample to certain records. In its simplest version this is returned:

> V2.match( where:{node: 8} ).to_human
  INFO->MATCH {class: v2, as: v2s, where:( node = 8)} RETURN v2s
  => ["<V2[40:0]: in: {E2=>1}, node : 8>"] 

ét voila: The V2-record with attribute node: 8

Lets inspect the next layer.

The adjacent node is connected via :in. So

> V2.match( where:{ node: 8}) {|q| q.connect( :in, as: :b); q }.to_human 
  INFO->MATCH {class: v2, as: v2s, where:( node = 8)} <-- { as: b }  RETURN v2s, b
  => [["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>"]]

We get a table with two columns, displaying the start vertex and the connected one (containing 10 E2-Edges).

To inspect the next layer, we have to follow the :out-path. This is realised by adding another connect to the query

> V2.match( where:{ node: 8}) do |q| 
             q.connect( :in, as: :b)
             q.connect(:out, as: :c)
             q 
       end.to_human 

 => INFO->MATCH {class: v2, as: v2s, where:( node = 8)} <-- { as: b }  --> { as: c }  RETURN v2s, b, c
 => [["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[33:0]: in: {E2=>1}, node : 1>"], 
     ["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[34:0]: in: {E2=>1}, node : 2>"], 
     ["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[35:0]: in: {E2=>1}, node : 3>"], 
     ["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[36:0]: in: {E2=>1}, node : 4>"], 
     ["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[37:0]: in: {E2=>1}, node : 5>"], 
     ["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[38:0]: in: {E2=>1}, node : 6>"], 
     ["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[39:0]: in: {E2=>1}, node : 7>"], 
     ["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[40:0]: in: {E2=>1}, node : 8>"], 
     ["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[33:1]: in: {E2=>1}, node : 9>"], 
     ["<V2[40:0]: in: {E2=>1}, node : 8>", "<V1[25:0]: out: {E2=>10}, item : 1>", "<V2[34:1]: in: {E2=>1}, node : 10>"]] 

(to be continued ..)

Clone this wiki locally