pacer 0.9.1.1-java → 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +4 -1
- data/.gitignore +4 -0
- data/.rspec +1 -1
- data/Gemfile-dev +33 -0
- data/Gemfile-release +4 -0
- data/README.md +27 -9
- data/Rakefile +26 -8
- data/bin/autotest +1 -1
- data/lib/pacer/blueprints/multi_graph.rb +7 -19
- data/lib/pacer/blueprints/ruby_graph.rb +77 -52
- data/lib/pacer/blueprints/tg.rb +6 -93
- data/lib/pacer/blueprints.rb +0 -1
- data/lib/pacer/core/graph/edges_route.rb +10 -12
- data/lib/pacer/core/graph/element_route.rb +14 -21
- data/lib/pacer/core/graph/graph_index_route.rb +12 -8
- data/lib/pacer/core/graph/graph_route.rb +2 -5
- data/lib/pacer/core/graph/mixed_route.rb +3 -5
- data/lib/pacer/core/graph/vertices_route.rb +26 -27
- data/lib/pacer/core/route.rb +35 -66
- data/lib/pacer/exceptions.rb +13 -6
- data/lib/pacer/extensions/block_filter_element.rb +0 -5
- data/lib/pacer/filter/collection_filter.rb +9 -2
- data/lib/pacer/filter/empty_filter.rb +12 -3
- data/lib/pacer/filter/future_filter.rb +5 -5
- data/lib/pacer/filter/loop_filter.rb +7 -13
- data/lib/pacer/filter/object_filter.rb +10 -16
- data/lib/pacer/filter/property_filter/filters.rb +134 -93
- data/lib/pacer/filter/property_filter.rb +22 -19
- data/lib/pacer/filter/where_filter/node_visitor.rb +47 -26
- data/lib/pacer/filter/where_filter.rb +24 -3
- data/lib/pacer/function_resolver.rb +7 -2
- data/lib/pacer/graph/graph_ml.rb +39 -0
- data/lib/pacer/graph/graph_transactions_mixin.rb +107 -175
- data/lib/pacer/graph/pacer_graph.rb +438 -0
- data/lib/pacer/graph/simple_encoder.rb +20 -0
- data/lib/pacer/graph/yaml_encoder.rb +81 -0
- data/lib/pacer/graph.rb +8 -10
- data/lib/pacer/pipe/blackbox_pipeline.rb +11 -4
- data/lib/pacer/pipe/block_filter_pipe.rb +5 -22
- data/lib/pacer/pipe/cross_product_transform_pipe.rb +5 -7
- data/lib/pacer/pipe/edges_pipe.rb +22 -0
- data/lib/pacer/pipe/enumerable_pipe.rb +3 -9
- data/lib/pacer/pipe/expandable_pipe.rb +2 -14
- data/lib/pacer/pipe/id_collection_filter_pipe.rb +2 -8
- data/lib/pacer/pipe/is_empty_pipe.rb +5 -12
- data/lib/pacer/pipe/is_unique_pipe.rb +3 -13
- data/lib/pacer/pipe/label_collection_filter_pipe.rb +1 -7
- data/lib/pacer/pipe/label_prefix_pipe.rb +0 -6
- data/lib/pacer/pipe/loop_pipe.rb +27 -25
- data/lib/pacer/pipe/never_pipe.rb +1 -1
- data/lib/pacer/pipe/path_wrapping_pipe.rb +40 -0
- data/lib/pacer/pipe/process_pipe.rb +2 -20
- data/lib/pacer/pipe/property_comparison_pipe.rb +0 -6
- data/lib/pacer/pipe/ruby_pipe.rb +10 -3
- data/lib/pacer/pipe/simple_visitor_pipe.rb +12 -11
- data/lib/pacer/pipe/stream_sort_pipe.rb +1 -7
- data/lib/pacer/pipe/stream_uniq_pipe.rb +0 -6
- data/lib/pacer/pipe/type_filter_pipe.rb +1 -7
- data/lib/pacer/pipe/unary_transform_pipe.rb +6 -8
- data/lib/pacer/pipe/unwrapping_pipe.rb +13 -0
- data/lib/pacer/pipe/vertices_pipe.rb +22 -0
- data/lib/pacer/pipe/visitor_pipe.rb +3 -7
- data/lib/pacer/pipe/wrapping_pipe.rb +37 -0
- data/lib/pacer/pipes.rb +17 -12
- data/lib/pacer/route/mixin/bulk_operations.rb +8 -9
- data/lib/pacer/route/mixin/route_operations.rb +17 -11
- data/lib/pacer/route/mixins.rb +0 -1
- data/lib/pacer/route.rb +198 -121
- data/lib/pacer/side_effect/aggregate.rb +22 -2
- data/lib/pacer/side_effect/as.rb +73 -0
- data/lib/pacer/side_effect/group_count.rb +0 -3
- data/lib/pacer/side_effect/is_unique.rb +7 -6
- data/lib/pacer/side_effect.rb +1 -1
- data/lib/pacer/support/enumerable.rb +14 -12
- data/lib/pacer/support/nil_class.rb +5 -0
- data/lib/pacer/support/proc.rb +2 -2
- data/lib/pacer/support.rb +1 -1
- data/lib/pacer/transform/cap.rb +1 -1
- data/lib/pacer/transform/has_count_cap.rb +1 -1
- data/lib/pacer/transform/join.rb +20 -16
- data/lib/pacer/transform/map.rb +6 -2
- data/lib/pacer/transform/path.rb +44 -20
- data/lib/pacer/transform/sort_section.rb +58 -51
- data/lib/pacer/utils/tsort.rb +7 -2
- data/lib/pacer/utils.rb +0 -1
- data/lib/pacer/version.rb +4 -3
- data/lib/pacer/visitors/section.rb +42 -0
- data/lib/pacer/visitors/visits_section.rb +32 -0
- data/lib/pacer/visitors.rb +7 -0
- data/lib/pacer/wrappers/edge_wrapper.rb +164 -11
- data/lib/pacer/wrappers/element_wrapper.rb +133 -8
- data/lib/pacer/wrappers/index_wrapper.rb +47 -0
- data/lib/pacer/wrappers/vertex_wrapper.rb +175 -12
- data/lib/pacer/wrappers/wrapper_selector.rb +40 -0
- data/lib/pacer/wrappers/wrapping_pipe_function.rb +90 -0
- data/lib/pacer/wrappers.rb +3 -1
- data/lib/pacer-1.0.0-standalone.jar +0 -0
- data/lib/pacer.rb +13 -47
- data/pacer.gemspec +0 -8
- data/pom.xml +10 -3
- data/spec/pacer/blueprints/dex_spec.rb +12 -26
- data/spec/pacer/blueprints/neo4j_spec.rb +14 -28
- data/spec/pacer/blueprints/tg_spec.rb +6 -54
- data/spec/pacer/core/graph/edges_route_spec.rb +1 -1
- data/spec/pacer/core/graph/element_route_spec.rb +2 -2
- data/spec/pacer/core/graph/graph_route_spec.rb +2 -2
- data/spec/pacer/core/graph/vertices_route_spec.rb +10 -3
- data/spec/pacer/core/route_spec.rb +35 -58
- data/spec/pacer/filter/empty_filter_spec.rb +5 -6
- data/spec/pacer/filter/future_filter_spec.rb +8 -8
- data/spec/pacer/filter/loop_filter_spec.rb +120 -6
- data/spec/pacer/filter/object_filter_spec.rb +15 -0
- data/spec/pacer/filter/property_filter/filters_spec.rb +169 -0
- data/spec/pacer/filter/property_filter_spec.rb +15 -12
- data/spec/pacer/filter/uniq_filter_spec.rb +1 -1
- data/spec/pacer/filter/where_filter_spec.rb +55 -7
- data/spec/pacer/graph/{graph_mixin_spec.rb → pacer_graph_spec.rb} +114 -185
- data/spec/pacer/route/mixin/base_spec.rb +36 -35
- data/spec/pacer/route/mixin/route_operations_spec.rb +4 -46
- data/spec/pacer/side_effect/as_spec.rb +34 -0
- data/spec/pacer/support/enumerable_spec.rb +6 -6
- data/spec/pacer/transform/join_spec.rb +7 -5
- data/spec/pacer/transform/map_spec.rb +55 -0
- data/spec/pacer/transform/path_spec.rb +30 -15
- data/spec/pacer/transform/process_spec.rb +42 -0
- data/spec/pacer/transform/sort_section_spec.rb +82 -0
- data/spec/pacer/wrapper/edge_wrapper_spec.rb +122 -2
- data/spec/pacer/wrapper/element_wrapper_spec.rb +289 -3
- data/spec/pacer/wrapper/vertex_wrapper_spec.rb +289 -2
- data/spec/spec_helper.rb +16 -7
- data/spec/support/graph_runner.rb +80 -29
- data/tags +1165 -0
- metadata +46 -107
- data/.rvmrc +0 -0
- data/lib/pacer/blueprints/extensions.rb +0 -77
- data/lib/pacer/graph/edge_mixin.rb +0 -127
- data/lib/pacer/graph/element_mixin.rb +0 -202
- data/lib/pacer/graph/graph_indices_mixin.rb +0 -93
- data/lib/pacer/graph/graph_mixin.rb +0 -361
- data/lib/pacer/graph/index_mixin.rb +0 -30
- data/lib/pacer/graph/vertex_mixin.rb +0 -119
- data/lib/pacer/pipe/map_pipe.rb +0 -36
- data/lib/pacer/pipe/variable_store_iterator_wrapper.rb +0 -26
- data/lib/pacer/route/mixin/variable_route_module.rb +0 -26
- data/lib/pacer/side_effect/section.rb +0 -25
- data/lib/pacer/support/iterator_mixins.rb +0 -110
- data/lib/pacer/wrappers/new_element.rb +0 -106
- data/lib/pacer-0.9.1.1-standalone.jar +0 -0
- data/spec/pacer/graph/edge_mixin_spec.rb +0 -116
- data/spec/pacer/graph/element_mixin_spec.rb +0 -297
- data/spec/pacer/graph/index_mixin_spec.rb +0 -0
- data/spec/pacer/graph/vertex_mixin_spec.rb +0 -192
@@ -1,202 +0,0 @@
|
|
1
|
-
module Pacer
|
2
|
-
# This module is mixed into the raw Blueprints Edge and Vertex classes
|
3
|
-
# from any graph implementation.
|
4
|
-
#
|
5
|
-
# Adds more convenient/rubyish methods and adds support for extensions
|
6
|
-
# to some methods where needed.
|
7
|
-
module ElementMixin
|
8
|
-
class << self
|
9
|
-
protected
|
10
|
-
def included(target)
|
11
|
-
target.send :include, Enumerable unless target.is_a? Enumerable
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Which extensions does this element have?
|
16
|
-
# @return [Set[extensions]]
|
17
|
-
def extensions
|
18
|
-
Set[]
|
19
|
-
end
|
20
|
-
|
21
|
-
# See {Core::Graph::VerticesRoute#v}
|
22
|
-
# @return [Route]
|
23
|
-
def v(*args)
|
24
|
-
route = super
|
25
|
-
if args.empty? and not block_given?
|
26
|
-
route.add_extensions extensions
|
27
|
-
end
|
28
|
-
route
|
29
|
-
end
|
30
|
-
|
31
|
-
# See {Core::Graph::EdgesRoute#e}
|
32
|
-
# @return [Route]
|
33
|
-
def e(*args)
|
34
|
-
route = super
|
35
|
-
if args.empty? and not block_given?
|
36
|
-
route.add_extensions extensions
|
37
|
-
end
|
38
|
-
route
|
39
|
-
end
|
40
|
-
|
41
|
-
# For internal use only.
|
42
|
-
#
|
43
|
-
# Specify the graph the element belongs to.
|
44
|
-
def graph=(graph)
|
45
|
-
@graph = graph
|
46
|
-
end
|
47
|
-
|
48
|
-
# The graph the element belongs to.
|
49
|
-
#
|
50
|
-
# Used to help prevent objects from different graphs from being
|
51
|
-
# accidentally associated, as well as to get graph-specific data for
|
52
|
-
# the element.
|
53
|
-
#
|
54
|
-
# @return [GraphMixin]
|
55
|
-
def graph
|
56
|
-
@graph
|
57
|
-
end
|
58
|
-
|
59
|
-
# Convenience method to retrieve a property by name.
|
60
|
-
#
|
61
|
-
# @param [#to_s] key the property name
|
62
|
-
# @return [Object]
|
63
|
-
def [](key)
|
64
|
-
if key.is_a? Array
|
65
|
-
key.map { |k| self[k] }
|
66
|
-
else
|
67
|
-
value = element.getProperty(key.to_s)
|
68
|
-
if graph
|
69
|
-
graph.decode_property(value)
|
70
|
-
else
|
71
|
-
value
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Convenience method to set a property by name to the given value.
|
77
|
-
# @param [#to_s] key the property name
|
78
|
-
# @param [Object] value the value to set the property to
|
79
|
-
def []=(key, value)
|
80
|
-
value = graph.encode_property(value) if graph
|
81
|
-
key = key.to_s
|
82
|
-
if value
|
83
|
-
if value != element.getProperty(key)
|
84
|
-
element.setProperty(key, value)
|
85
|
-
end
|
86
|
-
else
|
87
|
-
element.removeProperty(key) if element.getPropertyKeys.include? key
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# Specialize result to return self for elements.
|
92
|
-
# @return [ElementMixin] self
|
93
|
-
def result(name = nil)
|
94
|
-
self
|
95
|
-
end
|
96
|
-
|
97
|
-
# Query whether the current node belongs to the given graph.
|
98
|
-
#
|
99
|
-
# @param [Object] g the object to compare to {#graph}
|
100
|
-
def from_graph?(g)
|
101
|
-
g.equal? graph
|
102
|
-
end
|
103
|
-
|
104
|
-
# Returns a hash of property values by name.
|
105
|
-
#
|
106
|
-
# @return [Hash]
|
107
|
-
def properties
|
108
|
-
element.getPropertyKeys.inject({}) { |h, name| h[name] = element.getProperty(name); h }
|
109
|
-
end
|
110
|
-
|
111
|
-
# Replace the element's properties with the given hash
|
112
|
-
#
|
113
|
-
# @param [Hash] props the element's new properties
|
114
|
-
def properties=(props)
|
115
|
-
(element.getPropertyKeys - props.keys.collect { |k| k.to_s }).each do |key|
|
116
|
-
element.removeProperty key
|
117
|
-
end
|
118
|
-
props.each do |key, value|
|
119
|
-
self[key] = value
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def property_keys
|
124
|
-
getPropertyKeys
|
125
|
-
end
|
126
|
-
|
127
|
-
# The id of the current element
|
128
|
-
# @return [Object] element id (type varies by graph implementation.
|
129
|
-
def element_id
|
130
|
-
element.getId
|
131
|
-
end
|
132
|
-
|
133
|
-
# Sort objects semi arbitrarily based on {VertexMixin#display_name}
|
134
|
-
# or {EdgeMixin#display_name}.
|
135
|
-
# @param other
|
136
|
-
#
|
137
|
-
# @return [Fixnum]
|
138
|
-
def <=>(other)
|
139
|
-
display_name.to_s <=> other.display_name.to_s
|
140
|
-
end
|
141
|
-
|
142
|
-
# Test equality to another object.
|
143
|
-
#
|
144
|
-
# Elements are equal if they are the same type and have the same id
|
145
|
-
# and the same graph, regardless of extensions.
|
146
|
-
#
|
147
|
-
# If the graphdb instantiates multiple copies of the same element
|
148
|
-
# this method will return true when comparing them.
|
149
|
-
#
|
150
|
-
# @see #eql?
|
151
|
-
# @param other
|
152
|
-
def ==(other)
|
153
|
-
if other.respond_to?(:element) and other.element.class == element.class and other.element_id == element_id
|
154
|
-
if graph and other.graph
|
155
|
-
other.graph == graph
|
156
|
-
else
|
157
|
-
true
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
# Test object equality of the element instance.
|
163
|
-
#
|
164
|
-
# Wrappers/extensions (if any) are ignored, the underlying element
|
165
|
-
# only is compared
|
166
|
-
#
|
167
|
-
# If the graphdb instantiates multiple copies of the same element
|
168
|
-
# this method will return false when comparing them.
|
169
|
-
#
|
170
|
-
# @see #==
|
171
|
-
# @param other
|
172
|
-
def eql?(other)
|
173
|
-
if other.respond_to? :element
|
174
|
-
super(other.element)
|
175
|
-
else
|
176
|
-
super
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# Yields the element once or returns an enumerator if no block is
|
181
|
-
# given. Follows Ruby conventions and is meant to be used along
|
182
|
-
# with the Enumerable mixin.
|
183
|
-
#
|
184
|
-
# @yield [ElementMixin] this element
|
185
|
-
# @return [Enumerator] only if no block is given
|
186
|
-
def each
|
187
|
-
if block_given?
|
188
|
-
yield self
|
189
|
-
else
|
190
|
-
[self].to_enum
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
# Returns the underlying element. For unwrapped elements, returns
|
195
|
-
# self.
|
196
|
-
# @return [ElementMixin]
|
197
|
-
def element
|
198
|
-
self
|
199
|
-
end
|
200
|
-
alias no_extensions element
|
201
|
-
end
|
202
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
module Pacer
|
2
|
-
module GraphIndicesMixin
|
3
|
-
# Return an index by name.
|
4
|
-
#
|
5
|
-
# @param [#to_s] name of the index
|
6
|
-
# @param [:vertex, :edge, element type] type guarantees that the index returned is of the type specified.
|
7
|
-
# @param [Hash] opts
|
8
|
-
# @option opts [true] :create create the index if it doesn't exist
|
9
|
-
# @return [Pacer::IndexMixin]
|
10
|
-
def index_name(name, type = nil, opts = {})
|
11
|
-
name = name.to_s
|
12
|
-
if type
|
13
|
-
idx = getIndices.detect { |i| i.index_name == name and i.index_class == index_class(type) }
|
14
|
-
if idx.nil? and opts[:create]
|
15
|
-
idx = createManualIndex name, element_type(type)
|
16
|
-
end
|
17
|
-
else
|
18
|
-
idx = getIndices.detect { |i| i.index_name == name }
|
19
|
-
end
|
20
|
-
idx.graph = self if idx
|
21
|
-
idx
|
22
|
-
end
|
23
|
-
|
24
|
-
# Drops and recreates an automatic index with the same keys.
|
25
|
-
#
|
26
|
-
# In some earlier graphdb versions it was possible to corrupt
|
27
|
-
# automatic indices. This method provided a fast way to recreate
|
28
|
-
# them.
|
29
|
-
#
|
30
|
-
# @param [Index] old_index this index will be dropped
|
31
|
-
# @return [Index] rebuilt index
|
32
|
-
def rebuild_automatic_index(old_index)
|
33
|
-
name = old_index.getIndexName
|
34
|
-
index_class = old_index.getIndexClass
|
35
|
-
keys = old_index.getAutoIndexKeys
|
36
|
-
drop_index name
|
37
|
-
build_automatic_index(name, index_class, keys)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Creates a new automatic index.
|
41
|
-
#
|
42
|
-
# @param [#to_s] name index name
|
43
|
-
# @param [:vertex, :edge, element type] et element type
|
44
|
-
# @param [[#to_s], nil] keys The keys to be indexed. If nil then
|
45
|
-
# index all keys
|
46
|
-
def build_automatic_index(name, et, keys = nil)
|
47
|
-
if keys and not keys.is_a? java.util.Set
|
48
|
-
set = java.util.HashSet.new
|
49
|
-
keys.each { |k| set.add k.to_s }
|
50
|
-
keys = set
|
51
|
-
end
|
52
|
-
index = createAutomaticIndex name.to_s, index_class(et), keys
|
53
|
-
index.graph = self
|
54
|
-
if index_class(et) == element_type(:vertex).java_class
|
55
|
-
v.bulk_job do |v|
|
56
|
-
Pacer::Utils::AutomaticIndexHelper.addElement(index, v)
|
57
|
-
end
|
58
|
-
else
|
59
|
-
e.bulk_job do |e|
|
60
|
-
Pacer::Utils::AutomaticIndexHelper.addElement(index, e)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
index
|
64
|
-
end
|
65
|
-
|
66
|
-
# Return an object that can be compared to the return value of
|
67
|
-
# Index#index_class.
|
68
|
-
def index_class(et)
|
69
|
-
element_type(et).java_class.to_java
|
70
|
-
end
|
71
|
-
|
72
|
-
# Does this graph allow me to create or modify automatic indices?
|
73
|
-
#
|
74
|
-
# Specific graphs may override this method to return false.
|
75
|
-
def supports_automatic_indices?
|
76
|
-
true
|
77
|
-
end
|
78
|
-
|
79
|
-
# Does this graph allow me to create or modify manual indices?
|
80
|
-
#
|
81
|
-
# Specific graphs may override this method to return false.
|
82
|
-
def supports_manual_indices?
|
83
|
-
true
|
84
|
-
end
|
85
|
-
|
86
|
-
# Does this graph support indices on edges?
|
87
|
-
#
|
88
|
-
# Specific graphs may override this method to return false.
|
89
|
-
def supports_edge_indices?
|
90
|
-
true
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,361 +0,0 @@
|
|
1
|
-
module Pacer
|
2
|
-
# Methods to be mixed into Blueprints Graph objects from any
|
3
|
-
# implementation.
|
4
|
-
#
|
5
|
-
# Adds more convenient/rubyish methods and adds support for extensions
|
6
|
-
# to some methods where needed.
|
7
|
-
module GraphMixin
|
8
|
-
def self.included(target)
|
9
|
-
target.class_eval do
|
10
|
-
protected :addVertex, :addEdge
|
11
|
-
protected :add_vertex, :add_edge rescue nil
|
12
|
-
protected :getVertex, :getEdge
|
13
|
-
protected :get_vertex, :get_edge rescue nil
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
attr_accessor :in_bulk_job
|
18
|
-
|
19
|
-
def graph_id
|
20
|
-
@graph_id = Pacer.next_graph_id unless defined? @graph_id
|
21
|
-
@graph_id
|
22
|
-
end
|
23
|
-
|
24
|
-
# Get a vertex by id.
|
25
|
-
#
|
26
|
-
# @overload vertex(id)
|
27
|
-
# @param [element id] id
|
28
|
-
# @overload vertex(id, *modules)
|
29
|
-
# @param [element id] id
|
30
|
-
# @param [Module, Class] *modules extensions to add to the returned
|
31
|
-
# vertex.
|
32
|
-
def vertex(id, *modules)
|
33
|
-
v = getVertex(id) rescue nil
|
34
|
-
if v
|
35
|
-
wrapper = modules.detect { |obj| obj.ancestors.include? Pacer::Wrappers::VertexWrapper }
|
36
|
-
if wrapper
|
37
|
-
v = wrapper.new v
|
38
|
-
modules.delete wrapper
|
39
|
-
end
|
40
|
-
v.graph = self
|
41
|
-
v.add_extensions modules
|
42
|
-
else
|
43
|
-
v
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Get an edge by id.
|
48
|
-
#
|
49
|
-
# @overload edge(id)
|
50
|
-
# @param [element id] id
|
51
|
-
# @overload edge(id, *modules)
|
52
|
-
# @param [element id] id
|
53
|
-
# @param [Module, Class] *modules extensions to add to the returned
|
54
|
-
# edge.
|
55
|
-
def edge(id, *modules)
|
56
|
-
v = getEdge(id) rescue nil
|
57
|
-
if v
|
58
|
-
wrapper = modules.detect { |obj| obj.ancestors.include? Pacer::Wrappers::EdgeWrapper }
|
59
|
-
if wrapper
|
60
|
-
v = wrapper.new v
|
61
|
-
modules.delete wrapper
|
62
|
-
end
|
63
|
-
v.graph = self
|
64
|
-
v.add_extensions modules
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
# Create a vertex in the graph.
|
69
|
-
#
|
70
|
-
# @overload create_vertex(*args)
|
71
|
-
# @param [extension, Hash] *args extension (Module/Class) arguments will be
|
72
|
-
# added to the current vertex. A Hash will be
|
73
|
-
# treated as element properties.
|
74
|
-
# @overload create_vertex(id, *args)
|
75
|
-
# @param [element id] id the desired element id. Some graphs
|
76
|
-
# ignore this.
|
77
|
-
# @param [extension, Hash] *args extension (Module/Class) arguments will be
|
78
|
-
# added to the current vertex. A Hash will be
|
79
|
-
# treated as element properties.
|
80
|
-
def create_vertex(*args)
|
81
|
-
id, wrapper, modules, props = id_modules_properties(args)
|
82
|
-
vertex = creating_elements { addVertex(id) }
|
83
|
-
vertex = wrapper.new vertex if wrapper
|
84
|
-
vertex.graph = self
|
85
|
-
props.each { |k, v| vertex[k.to_s] = v } if props
|
86
|
-
if modules.any?
|
87
|
-
vertex.add_extensions modules
|
88
|
-
else
|
89
|
-
vertex
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# Create an edge in the graph.
|
94
|
-
#
|
95
|
-
# @param [element id] id some graphs allow you to specify your own edge id.
|
96
|
-
# @param [Pacer::VertexMixin] from_v the new edge's out_vertex
|
97
|
-
# @param [Pacer::VertexMixin] to_v the new edge's in_vertex
|
98
|
-
# @param [#to_s] label the edge label
|
99
|
-
# @param [extension, Hash] *args extension (Module/Class) arguments will be
|
100
|
-
# added to the returned edge. A Hash will be
|
101
|
-
# treated as element properties.
|
102
|
-
#
|
103
|
-
# @todo make id param optional
|
104
|
-
def create_edge(id, from_v, to_v, label, *args)
|
105
|
-
_, wrapper, modules, props = id_modules_properties(args)
|
106
|
-
edge = creating_elements { addEdge(id, from_v.element, to_v.element, label) }
|
107
|
-
edge = wrapper.new edge if wrapper
|
108
|
-
edge.graph = self
|
109
|
-
props.each { |k, v| edge[k.to_s] = v } if props
|
110
|
-
if modules.any?
|
111
|
-
edge.add_extensions modules
|
112
|
-
else
|
113
|
-
edge
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
# Import the data in a GraphML file.
|
118
|
-
#
|
119
|
-
# Will fail if the data already exsts in the current graph.
|
120
|
-
#
|
121
|
-
# @param [String] path
|
122
|
-
def import(path)
|
123
|
-
path = File.expand_path path
|
124
|
-
begin
|
125
|
-
stream = java.net.URL.new(path).open_stream
|
126
|
-
rescue java.net.MalformedURLException
|
127
|
-
stream = java.io.FileInputStream.new path
|
128
|
-
end
|
129
|
-
creating_elements do
|
130
|
-
com.tinkerpop.blueprints.pgm.util.graphml.GraphMLReader.input_graph self, stream
|
131
|
-
end
|
132
|
-
true
|
133
|
-
ensure
|
134
|
-
stream.close if stream
|
135
|
-
end
|
136
|
-
|
137
|
-
# Export the graph to GraphML
|
138
|
-
#
|
139
|
-
# @param [String] path will be replaced if it exists
|
140
|
-
def export(path)
|
141
|
-
path = File.expand_path path
|
142
|
-
stream = java.io.FileOutputStream.new path
|
143
|
-
com.tinkerpop.blueprints.pgm.util.graphml.GraphMLWriter.outputGraph self, stream
|
144
|
-
ensure
|
145
|
-
stream.close if stream
|
146
|
-
end
|
147
|
-
|
148
|
-
# Set how many elements should go into each transaction in a bulk
|
149
|
-
# job.
|
150
|
-
#
|
151
|
-
# @param [Fixnum] size number of elements
|
152
|
-
def bulk_job_size=(size)
|
153
|
-
@bulk_job_size = size
|
154
|
-
end
|
155
|
-
|
156
|
-
# The currently configured bulk job size.
|
157
|
-
def bulk_job_size
|
158
|
-
if defined? @bulk_job_size
|
159
|
-
@bulk_job_size
|
160
|
-
else
|
161
|
-
5000
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
# Are we currently in the midst of a bulk job?
|
166
|
-
def in_bulk_job?
|
167
|
-
@in_bulk_job if defined? @in_bulk_job
|
168
|
-
end
|
169
|
-
|
170
|
-
# Directly loads an array of vertices by id.
|
171
|
-
#
|
172
|
-
# @param [[vertex ids]] ids
|
173
|
-
# @return [[Pacer::VertexMixin]]
|
174
|
-
def load_vertices(ids)
|
175
|
-
ids.map do |id|
|
176
|
-
vertex id
|
177
|
-
end.compact
|
178
|
-
end
|
179
|
-
|
180
|
-
# Directly loads an array of edges by id.
|
181
|
-
#
|
182
|
-
# @param [[edge ids]] ids
|
183
|
-
# @return [[Pacer::EdgeMixin]]
|
184
|
-
def load_edges(ids)
|
185
|
-
ids.map do |id|
|
186
|
-
edge id
|
187
|
-
end.compact
|
188
|
-
end
|
189
|
-
|
190
|
-
# The current graph
|
191
|
-
#
|
192
|
-
# @return [Graph] returns self
|
193
|
-
def graph
|
194
|
-
self
|
195
|
-
end
|
196
|
-
|
197
|
-
def equals(other)
|
198
|
-
self == other
|
199
|
-
end
|
200
|
-
|
201
|
-
# The proc used to name vertices.
|
202
|
-
#
|
203
|
-
# @return [Proc]
|
204
|
-
def vertex_name
|
205
|
-
@vertex_name if defined? @vertex_name
|
206
|
-
end
|
207
|
-
|
208
|
-
# Set the proc used to name vertices.
|
209
|
-
#
|
210
|
-
# @param [Proc(vertex)] a_proc returns a string given a vertex
|
211
|
-
def vertex_name=(a_proc)
|
212
|
-
@vertex_name = a_proc
|
213
|
-
end
|
214
|
-
|
215
|
-
# The proc used to name edges.
|
216
|
-
#
|
217
|
-
# @return [Proc]
|
218
|
-
def edge_name
|
219
|
-
@edge_name if defined? @edge_name
|
220
|
-
end
|
221
|
-
|
222
|
-
# Set the proc used to name edges.
|
223
|
-
#
|
224
|
-
# @param [Proc(edge)] a_proc returns a string given an edge
|
225
|
-
def edge_name=(a_proc)
|
226
|
-
@edge_name = a_proc
|
227
|
-
end
|
228
|
-
|
229
|
-
# Is the element type given supported by this graph?
|
230
|
-
#
|
231
|
-
# @param [:edge, :vertex, :mixed, element_type, Object] et the
|
232
|
-
# object we're testing
|
233
|
-
def element_type?(et)
|
234
|
-
if [element_type(:vertex), element_type(:edge), element_type(:mixed)].include? element_type(et)
|
235
|
-
true
|
236
|
-
else
|
237
|
-
false
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
# Does this graph support edges where the in_vertex and the
|
242
|
-
# out_vertex are the same?
|
243
|
-
#
|
244
|
-
# Specific graphs may override this method to return false.
|
245
|
-
def supports_circular_edges?
|
246
|
-
true
|
247
|
-
end
|
248
|
-
|
249
|
-
# When creating an element, does this graph allow me to specify the
|
250
|
-
# element_id?
|
251
|
-
#
|
252
|
-
# Specific graphs may override this method to return false.
|
253
|
-
def supports_custom_element_ids?
|
254
|
-
true
|
255
|
-
end
|
256
|
-
|
257
|
-
# Does this graph allow me to create or modify automatic indices?
|
258
|
-
#
|
259
|
-
# Specific graphs may override this method to return false.
|
260
|
-
def supports_automatic_indices?
|
261
|
-
false
|
262
|
-
end
|
263
|
-
|
264
|
-
# Does this graph allow me to create or modify manual indices?
|
265
|
-
#
|
266
|
-
# Specific graphs may override this method to return false.
|
267
|
-
def supports_manual_indices?
|
268
|
-
false
|
269
|
-
end
|
270
|
-
|
271
|
-
# Does this graph support indices on edges?
|
272
|
-
#
|
273
|
-
# Specific graphs may override this method to return false.
|
274
|
-
def supports_edge_indices?
|
275
|
-
false
|
276
|
-
end
|
277
|
-
|
278
|
-
def element_type(et = nil)
|
279
|
-
return nil unless et
|
280
|
-
result = if et == vertex_class or et == edge_class or et == element_class
|
281
|
-
et
|
282
|
-
else
|
283
|
-
case et
|
284
|
-
when :vertex, Pacer::Vertex, VertexMixin
|
285
|
-
vertex_class
|
286
|
-
when :edge, Pacer::Edge, EdgeMixin
|
287
|
-
edge_class
|
288
|
-
when :mixed, Pacer::Element, ElementMixin
|
289
|
-
element_class
|
290
|
-
when :object
|
291
|
-
Object
|
292
|
-
else
|
293
|
-
if et == Object
|
294
|
-
Object
|
295
|
-
elsif vertex_class.respond_to? :java_class
|
296
|
-
if et == vertex_class.java_class.to_java
|
297
|
-
vertex_class
|
298
|
-
elsif et == edge_class.java_class.to_java
|
299
|
-
edge_class
|
300
|
-
elsif et == Pacer::Vertex.java_class.to_java
|
301
|
-
vertex_class
|
302
|
-
elsif et == Pacer::Edge.java_class.to_java
|
303
|
-
edge_class
|
304
|
-
end
|
305
|
-
end
|
306
|
-
end
|
307
|
-
end
|
308
|
-
if result
|
309
|
-
result
|
310
|
-
else
|
311
|
-
raise ArgumentError, 'Element type may be one of :vertex, :edge, :mixed or :object'
|
312
|
-
end
|
313
|
-
end
|
314
|
-
|
315
|
-
def sanitize_properties(props)
|
316
|
-
props
|
317
|
-
end
|
318
|
-
|
319
|
-
def encode_property(value)
|
320
|
-
if value.is_a? String
|
321
|
-
value = value.strip
|
322
|
-
value unless value == ''
|
323
|
-
else
|
324
|
-
value
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
def decode_property(value)
|
329
|
-
value
|
330
|
-
end
|
331
|
-
|
332
|
-
def edges
|
333
|
-
getEdges
|
334
|
-
end
|
335
|
-
|
336
|
-
protected
|
337
|
-
|
338
|
-
# Helper method to wrap element creation in exception handling.
|
339
|
-
def creating_elements
|
340
|
-
begin
|
341
|
-
yield
|
342
|
-
rescue NativeException => e
|
343
|
-
if e.message =~ /already exists/
|
344
|
-
raise ElementExists, e.message
|
345
|
-
else
|
346
|
-
raise
|
347
|
-
end
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
def id_modules_properties(args)
|
352
|
-
props = args.last if args.last.is_a? Hash
|
353
|
-
modules = args.select { |obj| obj.is_a? Module or obj.is_a? Class }
|
354
|
-
wrapper = modules.detect { |obj| obj.is_a? Class and obj.ancestors.include? Pacer::Wrappers::ElementWrapper }
|
355
|
-
modules.delete wrapper
|
356
|
-
id = args.first
|
357
|
-
id = nil if id == props or modules.include? id or id == wrapper
|
358
|
-
[id, wrapper, modules, props]
|
359
|
-
end
|
360
|
-
end
|
361
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module Pacer
|
2
|
-
module IndexMixin
|
3
|
-
def graph=(graph)
|
4
|
-
@graph = graph
|
5
|
-
end
|
6
|
-
|
7
|
-
def graph
|
8
|
-
@graph if defined? @graph
|
9
|
-
end
|
10
|
-
|
11
|
-
def first(key, value, extensions = nil)
|
12
|
-
e = get(key, value).first
|
13
|
-
if e and (graph or extensions)
|
14
|
-
e.graph = graph
|
15
|
-
e.add_extensions extensions
|
16
|
-
end
|
17
|
-
e
|
18
|
-
end
|
19
|
-
|
20
|
-
def all(key, value, extensions = nil)
|
21
|
-
iter = get(key, value)
|
22
|
-
if graph or extensions
|
23
|
-
iter.extend Pacer::Core::Route::IteratorExtensionsMixin
|
24
|
-
iter.graph = graph
|
25
|
-
iter.extensions = extensions
|
26
|
-
end
|
27
|
-
iter
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|