Module: Pacer::Core::Graph::VerticesRoute

Included in:
Wrappers::VertexWrapper
Defined in:
lib/pacer/core/graph/vertices_route.rb

Overview

Basic methods for routes that contain only vertices.

Instance Method Summary collapse

Instance Method Details

#add_edges_to(label, to_vertices, props = {}) ⇒ EdgesRoute?

Create associations with the given label from all vertices matching this route to all vertices matching the given to_route. If any properties are given, they will be applied to each created edge.

If this route emits more than one element and the to_vertices param also emits (or contains) more than one element, the resulting edges will represent a cross-product between the two collections.

If a vertex appears in either the this route or in to_vertices, it will be linked once for each time it appears.

Parameters:

  • label (#to_s)

    the label to use for the new edges

  • to_vertices (VerticesRoute, Enumerable, java.util.Iterator)

    collection of vertices that should have edges connecting them from the source edges.

  • optional (Hash)

    props properties that should be set for each created edge

Returns:

  • (EdgesRoute, nil)

    includes all created edges or nil if no edges were created



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/pacer/core/graph/vertices_route.rb', line 178

def add_edges_to(label, to_vertices, props = {})
  case to_vertices
  when Pacer::Core::Route, Enumerable, java.util.Iterator
  else
    to_vertices = [to_vertices].compact
  end
  has_props = !props.empty?
  edge_ids = []
  counter = 0
  graph.transaction(nesting: true) do |commit, rollback|
    v.each do |from_v|
      to_vertices.each do |to_v|
        counter += 1
        if counter == graph.bulk_job_size
          commit.call
          counter = 0
        end
        begin
          edge = graph.create_edge(nil, from_v, to_v, label.to_s, props)
          edge_ids << edge.element_id
        end
      end
    end
  end
  if edge_ids.any?
    edge_ids.id_to_element_route(:based_on => graph.e)
  end
end

#both(*filters) {|VertexWrapper| ... } ⇒ VerticesRoute

Extends the route with vertices via all edges from this route’s matching vertices.

Parameters:

  • filter (Array<Hash, String, Symbol, extension>, Hash, String, Symbol, extension)

    see Route#property_filter If string(s) or symbol(s) are given, they will be treated as edge labels. Unlike other property filters which all must be matched, an edge will pass the filter if it matches any of the given labels.

Yields:

  • (VertexWrapper)

    filter proc, see Route#property_filter

Returns:



117
118
119
120
121
122
123
124
125
126
# File 'lib/pacer/core/graph/vertices_route.rb', line 117

def both(*filters, &block)
  filters = extract_labels(filters)
  Pacer::Route.property_filter(chain_route(:element_type => :vertex,
                                           :pipe_class => BothPipe,
                                           :pipe_args => route_labels,
                                           :wrapper => nil,
                                           :extensions => [],
                                           :route_name => edge_route_name('both', route_labels)),
                              filters, block)
end

#both_e(*filters) {|EdgeWrapper| ... } ⇒ EdgesRoute

Extends the route with all edges from this route’s matching vertices.

Parameters:

  • filter (Array<Hash, String, Symbol, extension>, Hash, String, Symbol, extension)

    see Route#property_filter If string(s) or symbol(s) are given, they will be treated as edge labels. Unlike other property filters which all must be matched, an edge will pass the filter if it matches any of the given labels.

Yields:

  • (EdgeWrapper)

    filter proc, see Route#property_filter

Returns:



100
101
102
103
104
105
106
107
# File 'lib/pacer/core/graph/vertices_route.rb', line 100

def both_e(*filters, &block)
  filters = extract_labels(filters)
  Pacer::Route.property_filter(chain_route(:element_type => :edge,
                                           :pipe_class => BothEdgesPipe,
                                           :pipe_args => route_labels,
                                           :route_name => edge_route_name('bothE', route_labels)),
                              filters, block)
end

#delete!Object

Delete all matching vertices and all edges which link to this vertex.



150
151
152
153
154
155
# File 'lib/pacer/core/graph/vertices_route.rb', line 150

def delete!
  count = 0
  uniq.both_e.uniq.bulk_job { |e| count += 1; e.delete! }
  uniq.bulk_job { |e| count += 1; e.delete! }
  count
end

#element_typeelement_type(:vertex)

The element type of this route for this graph implementation.

which graph is in use.

Returns:

  • (element_type(:vertex))

    The actual type varies based on



144
145
146
# File 'lib/pacer/core/graph/vertices_route.rb', line 144

def element_type
  :vertex
end

#in(*filters) {|VertexWrapper| ... } ⇒ VerticesRoute

Extends the route with vertices via the in edges from this route’s matching vertices.

Parameters:

  • filter (Array<Hash, String, Symbol, extension>, Hash, String, Symbol, extension)

    see Route#property_filter If string(s) or symbol(s) are given, they will be treated as edge labels. Unlike other property filters which all must be matched, an edge will pass the filter if it matches any of the given labels.

Yields:

  • (VertexWrapper)

    filter proc, see Route#property_filter

Returns:



81
82
83
84
85
86
87
88
89
90
# File 'lib/pacer/core/graph/vertices_route.rb', line 81

def in(*filters, &block)
  filters = extract_labels(filters)
  Pacer::Route.property_filter(chain_route(:element_type => :vertex,
                                           :pipe_class => InPipe,
                                           :pipe_args => route_labels,
                                           :wrapper => nil,
                                           :extensions => [],
                                           :route_name => edge_route_name('in', route_labels)),
                              filters, block)
end

#in_e(*filters) {|EdgeWrapper| ... } ⇒ EdgesRoute

Extends the route with in edges from this route’s matching vertices.

Parameters:

  • filter (Array<Hash, String, Symbol, extension>, Hash, String, Symbol, extension)

    see Route#property_filter If string(s) or symbol(s) are given, they will be treated as edge labels. Unlike other property filters which all must be matched, an edge will pass the filter if it matches any of the given labels.

Yields:

  • (EdgeWrapper)

    filter proc, see Route#property_filter

Returns:



60
61
62
63
64
# File 'lib/pacer/core/graph/vertices_route.rb', line 60

def in_e(*filters, &block)
  filters = extract_labels(filters)
  Pacer::Route.property_filter(inE(route_labels),
                              filters, block)
end

#inE(labels) ⇒ Object



66
67
68
69
70
71
# File 'lib/pacer/core/graph/vertices_route.rb', line 66

def inE(labels)
  chain_route(:element_type => :edge,
              :pipe_class => InEdgesPipe,
              :pipe_args => (labels || []),
              :route_name => edge_route_name('inE', labels))
end

#out(*filters) {|VertexWrapper| ... } ⇒ VerticesRoute

Extends the route with vertices via the out edges from this route’s matching vertices.

Parameters:

  • filter (Array<Hash, String, Symbol, extension>, Hash, String, Symbol, extension)

    see Route#property_filter If string(s) or symbol(s) are given, they will be treated as edge labels. Unlike other property filters which all must be matched, an edge will pass the filter if it matches any of the given labels.

Yields:

  • (VertexWrapper)

    filter proc, see Route#property_filter

Returns:



41
42
43
44
45
46
47
48
49
50
# File 'lib/pacer/core/graph/vertices_route.rb', line 41

def out(*filters, &block)
  filters = extract_labels(filters)
  Pacer::Route.property_filter(chain_route(:element_type => :vertex,
                                           :pipe_class => OutPipe,
                                           :pipe_args => route_labels,
                                           :wrapper => nil,
                                           :extensions => [],
                                           :route_name => edge_route_name('out', route_labels)),
                              filters, block)
end

#out_e(*filters) {|EdgeWrapper| ... } ⇒ EdgesRoute

Extends the route with out edges from this route’s matching vertices.

Parameters:

  • filter (Array<Hash, String, Symbol, extension>, Hash, String, Symbol, extension)

    see Route#property_filter If string(s) or symbol(s) are given, they will be treated as edge labels. Unlike other property filters which all must be matched, an edge will pass the filter if it matches any of the given labels.

Yields:

  • (EdgeWrapper)

    filter proc, see Route#property_filter

Returns:



20
21
22
23
24
# File 'lib/pacer/core/graph/vertices_route.rb', line 20

def out_e(*filters, &block)
  filters = extract_labels(filters)
  Pacer::Route.property_filter(outE(route_labels),
                              filters, block)
end

#outE(labels) ⇒ Object



26
27
28
29
30
31
# File 'lib/pacer/core/graph/vertices_route.rb', line 26

def outE(labels)
  chain_route(:element_type => :edge,
              :pipe_class => OutEdgesPipe,
              :pipe_args => (labels || []),
              :route_name => edge_route_name('outE', labels))
end

#route_labelsObject



207
208
209
# File 'lib/pacer/core/graph/vertices_route.rb', line 207

def route_labels
  @route_labels
end

#v(*filters) {|VertexWrapper| ... } ⇒ VerticesRoute

Extend route with the additional vertex property and block filters.

Parameters:

  • filter (Array<Hash, String, Symbol, extension>, Hash, String, Symbol, extension)

    see Route#property_filter If string(s) or symbol(s) are given, they will be treated as edge labels. Unlike other property filters which all must be matched, an edge will pass the filter if it matches any of the given labels.

Yields:

  • (VertexWrapper)

    filter proc, see Route#property_filter

Returns:



136
137
138
# File 'lib/pacer/core/graph/vertices_route.rb', line 136

def v(*filters, &block)
  filter(*filters, &block)
end