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



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/pacer/core/graph/vertices_route.rb', line 170

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:



109
110
111
112
113
114
115
116
117
118
# File 'lib/pacer/core/graph/vertices_route.rb', line 109

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')),
                              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:



92
93
94
95
96
97
98
99
# File 'lib/pacer/core/graph/vertices_route.rb', line 92

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')),
                              filters, block)
end

#delete!Object

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



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

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



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

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:



73
74
75
76
77
78
79
80
81
82
# File 'lib/pacer/core/graph/vertices_route.rb', line 73

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')),
                              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:



56
57
58
59
60
61
62
63
# File 'lib/pacer/core/graph/vertices_route.rb', line 56

def in_e(*filters, &block)
  filters = extract_labels(filters)
  Pacer::Route.property_filter(chain_route(:element_type => :edge,
                                           :pipe_class => InEdgesPipe,
                                           :pipe_args => route_labels,
                                           :route_name => edge_route_name('inE')),
                              filters, block)
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:



37
38
39
40
41
42
43
44
45
46
# File 'lib/pacer/core/graph/vertices_route.rb', line 37

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')),
                              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
25
26
27
# File 'lib/pacer/core/graph/vertices_route.rb', line 20

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

#route_labelsObject



199
200
201
# File 'lib/pacer/core/graph/vertices_route.rb', line 199

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:



128
129
130
# File 'lib/pacer/core/graph/vertices_route.rb', line 128

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