neography-ajaycb 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +5 -0
  2. data/.project +12 -0
  3. data/.travis.yml +1 -0
  4. data/CONTRIBUTORS +12 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +39 -0
  7. data/LICENSE +19 -0
  8. data/README.rdoc +350 -0
  9. data/Rakefile +15 -0
  10. data/examples/facebook.rb +40 -0
  11. data/examples/facebook_v2.rb +25 -0
  12. data/examples/greatest.rb +43 -0
  13. data/examples/linkedin.rb +39 -0
  14. data/examples/linkedin_v2.rb +22 -0
  15. data/examples/traversal_example1.rb +65 -0
  16. data/examples/traversal_example2.rb +54 -0
  17. data/lib/neography.rb +46 -0
  18. data/lib/neography/config.rb +17 -0
  19. data/lib/neography/equal.rb +21 -0
  20. data/lib/neography/index.rb +13 -0
  21. data/lib/neography/neography.rb +10 -0
  22. data/lib/neography/node.rb +45 -0
  23. data/lib/neography/node_path.rb +29 -0
  24. data/lib/neography/node_relationship.rb +35 -0
  25. data/lib/neography/node_traverser.rb +142 -0
  26. data/lib/neography/path_traverser.rb +94 -0
  27. data/lib/neography/property.rb +53 -0
  28. data/lib/neography/property_container.rb +17 -0
  29. data/lib/neography/railtie.rb +8 -0
  30. data/lib/neography/relationship.rb +68 -0
  31. data/lib/neography/relationship_traverser.rb +80 -0
  32. data/lib/neography/rest.rb +534 -0
  33. data/lib/neography/tasks.rb +131 -0
  34. data/lib/neography/version.rb +3 -0
  35. data/neography.gemspec +29 -0
  36. data/spec/integration/authorization_spec.rb +48 -0
  37. data/spec/integration/index_spec.rb +32 -0
  38. data/spec/integration/neography_spec.rb +10 -0
  39. data/spec/integration/node_path_spec.rb +222 -0
  40. data/spec/integration/node_relationship_spec.rb +374 -0
  41. data/spec/integration/node_spec.rb +215 -0
  42. data/spec/integration/relationship_spec.rb +37 -0
  43. data/spec/integration/rest_batch_spec.rb +221 -0
  44. data/spec/integration/rest_bulk_spec.rb +106 -0
  45. data/spec/integration/rest_experimental_spec.rb +22 -0
  46. data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
  47. data/spec/integration/rest_index_spec.rb +297 -0
  48. data/spec/integration/rest_node_spec.rb +232 -0
  49. data/spec/integration/rest_path_spec.rb +209 -0
  50. data/spec/integration/rest_plugin_spec.rb +67 -0
  51. data/spec/integration/rest_relationship_spec.rb +327 -0
  52. data/spec/integration/rest_traverse_spec.rb +149 -0
  53. data/spec/spec_helper.rb +18 -0
  54. metadata +222 -0
@@ -0,0 +1,80 @@
1
+ module Neography
2
+ class RelationshipTraverser
3
+ include Enumerable
4
+
5
+ def initialize(node, types, direction)
6
+ @node = node
7
+ @types = [types]
8
+ @direction = direction
9
+ end
10
+
11
+ def to_s
12
+ if @types.size == 1 && !@types.empty?
13
+ "#{self.class} [type: #{@type} dir:#{@direction}]"
14
+ elsif !@types.empty?
15
+ "#{self.class} [types: #{@types.join(',')} dir:#{@direction}]"
16
+ else
17
+ "#{self.class} [types: ANY dir:#{@direction}]"
18
+ end
19
+ end
20
+
21
+ def each
22
+ iterator.each do |i|
23
+ rel = Neography::Relationship.new(i, @node.neo_server)
24
+ rel.start_node = Neography::Node.load(rel.start_node, @node.neo_server)
25
+ rel.end_node = Neography::Node.load(rel.end_node, @node.neo_server)
26
+
27
+ yield rel if match_to_other?(rel)
28
+ end
29
+ end
30
+
31
+ def empty?
32
+ first == nil
33
+ end
34
+
35
+ def iterator
36
+ Array(@node.neo_server.get_node_relationships(@node, @direction, @types))
37
+ end
38
+
39
+ def match_to_other?(rel)
40
+ if @to_other.nil?
41
+ true
42
+ elsif @direction == :outgoing
43
+ rel.end_node == @to_other
44
+ elsif @direction == :incoming
45
+ rel.start_node == @to_other
46
+ else
47
+ rel.start_node == @to_other || rel.end_node == @to_other
48
+ end
49
+ end
50
+
51
+ def to_other(to_other)
52
+ @to_other = to_other
53
+ self
54
+ end
55
+
56
+ def del
57
+ each { |rel| @node.neo_server.delete_relationship(rel) }
58
+ end
59
+
60
+ def size
61
+ [*self].size
62
+ end
63
+
64
+ def both
65
+ @direction = :both
66
+ self
67
+ end
68
+
69
+ def incoming
70
+ @direction = :incoming
71
+ self
72
+ end
73
+
74
+ def outgoing
75
+ @direction = :outgoing
76
+ self
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,534 @@
1
+ module Neography
2
+ class Rest
3
+ include HTTParty
4
+
5
+ attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password
6
+
7
+ def initialize(options=ENV['NEO4J_URL'] || {})
8
+ init = {:protocol => Neography::Config.protocol,
9
+ :server => Neography::Config.server,
10
+ :port => Neography::Config.port,
11
+ :directory => Neography::Config.directory,
12
+ :log_file => Neography::Config.log_file,
13
+ :log_enabled => Neography::Config.log_enabled,
14
+ :max_threads => Neography::Config.max_threads,
15
+ :authentication => Neography::Config.authentication,
16
+ :username => Neography::Config.username,
17
+ :password => Neography::Config.password}
18
+
19
+ unless options.respond_to?(:each_pair)
20
+ url = URI.parse(options)
21
+ options = Hash.new
22
+ options[:protocol] = url.scheme + "://"
23
+ options[:server] = url.host
24
+ options[:port] = url.port
25
+ options[:directory] = url.path
26
+ options[:username] = url.user
27
+ options[:password] = url.password
28
+ options[:authentication] = 'basic' unless url.user.nil?
29
+ end
30
+
31
+ init.merge!(options)
32
+
33
+ @protocol = init[:protocol]
34
+ @server = init[:server]
35
+ @port = init[:port]
36
+ @directory = init[:directory]
37
+ @log_file = init[:log_file]
38
+ @log_enabled = init[:log_enabled]
39
+ @logger = Logger.new(@log_file) if @log_enabled
40
+ @max_threads = init[:max_threads]
41
+ @authentication = Hash.new
42
+ @authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty?
43
+ end
44
+
45
+ def configure(protocol, server, port, directory)
46
+ @protocol = protocol
47
+ @server = server
48
+ @port = port
49
+ @directory = directory
50
+ end
51
+
52
+ def configuration
53
+ @protocol + @server + ':' + @port.to_s + @directory + "/db/data"
54
+ end
55
+
56
+ def get_root
57
+ get("/node/#{get_id(get('/')["reference_node"])}")
58
+ end
59
+
60
+ def create_node(*args)
61
+ if args[0].respond_to?(:each_pair) && args[0]
62
+ options = { :body => args[0].delete_if { |k, v| v.nil? }.to_json, :headers => {'Content-Type' => 'application/json'} }
63
+ post("/node", options)
64
+ else
65
+ post("/node")
66
+ end
67
+ end
68
+
69
+ def create_nodes(nodes)
70
+ nodes = Array.new(nodes) if nodes.kind_of? Fixnum
71
+ created_nodes = Array.new
72
+ nodes.each do |node|
73
+ created_nodes << create_node(node)
74
+ end
75
+ created_nodes
76
+ end
77
+
78
+ def create_nodes_threaded(nodes)
79
+ nodes = Array.new(nodes) if nodes.kind_of? Fixnum
80
+
81
+ node_queue = Queue.new
82
+ thread_pool = []
83
+ responses = Queue.new
84
+
85
+ nodes.each do |node|
86
+ node_queue.push node
87
+ end
88
+
89
+ [nodes.size, @max_threads].min.times do
90
+ thread_pool << Thread.new do
91
+ until node_queue.empty? do
92
+ node = node_queue.pop
93
+ if node.respond_to?(:each_pair)
94
+ responses.push( post("/node", { :body => node.to_json, :headers => {'Content-Type' => 'application/json'} } ) )
95
+ else
96
+ responses.push( post("/node") )
97
+ end
98
+ end
99
+ self.join
100
+ end
101
+ end
102
+
103
+ created_nodes = Array.new
104
+
105
+ while created_nodes.size < nodes.size
106
+ created_nodes << responses.pop
107
+ end
108
+ created_nodes
109
+ end
110
+
111
+ # This is not yet implemented in the REST API
112
+ #
113
+ # def get_all_node
114
+ # puts "get all nodes"
115
+ # get("/nodes/")
116
+ # end
117
+
118
+ def get_node(id)
119
+ get("/node/#{get_id(id)}")
120
+ end
121
+
122
+ def get_nodes(*nodes)
123
+ gotten_nodes = Array.new
124
+ Array(nodes).flatten.each do |node|
125
+ gotten_nodes << get_node(node)
126
+ end
127
+ gotten_nodes
128
+ end
129
+
130
+ def reset_node_properties(id, properties)
131
+ options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} }
132
+ put("/node/#{get_id(id)}/properties", options)
133
+ end
134
+
135
+ def get_node_properties(id, properties = nil)
136
+ if properties.nil?
137
+ get("/node/#{get_id(id)}/properties")
138
+ else
139
+ node_properties = Hash.new
140
+ Array(properties).each do |property|
141
+ value = get("/node/#{get_id(id)}/properties/#{property}")
142
+ node_properties[property] = value unless value.nil?
143
+ end
144
+ return nil if node_properties.empty?
145
+ node_properties
146
+ end
147
+ end
148
+
149
+ def remove_node_properties(id, properties = nil)
150
+ if properties.nil?
151
+ delete("/node/#{get_id(id)}/properties")
152
+ else
153
+ Array(properties).each do |property|
154
+ delete("/node/#{get_id(id)}/properties/#{property}")
155
+ end
156
+ end
157
+ end
158
+
159
+ def set_node_properties(id, properties)
160
+ properties.each do |key, value|
161
+ options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} }
162
+ put("/node/#{get_id(id)}/properties/#{key}", options)
163
+ end
164
+ end
165
+
166
+ def delete_node(id)
167
+ delete("/node/#{get_id(id)}")
168
+ end
169
+
170
+ def create_relationship(type, from, to, props = nil)
171
+ options = { :body => {:to => self.configuration + "/node/#{get_id(to)}", :data => props, :type => type }.to_json, :headers => {'Content-Type' => 'application/json'} }
172
+ post("/node/#{get_id(from)}/relationships", options)
173
+ end
174
+
175
+ def create_unique_relationship(index, key, value, type, from, to)
176
+ body = {:key=>key,:value=>value, :type => type }
177
+ body[:start] = self.configuration + "/node/#{get_id(from)}"
178
+ body[:end] = self.configuration + "/node/#{get_id(to)}"
179
+ options = { :body => body.to_json, :headers => {'Content-Type' => 'application/json'} }
180
+ post("/index/relationship/#{index}?unique", options)
181
+ end
182
+
183
+ def get_relationship(id)
184
+ get("/relationship/#{get_id(id)}")
185
+ end
186
+
187
+ def get_relationship_start_node(rel)
188
+ get_node(rel["start"])
189
+ end
190
+
191
+ def get_relationship_end_node(rel)
192
+ get_node(rel["end"])
193
+ end
194
+
195
+ def reset_relationship_properties(id, properties)
196
+ options = { :body => properties.to_json, :headers => {'Content-Type' => 'application/json'} }
197
+ put("/relationship/#{get_id(id)}/properties", options)
198
+ end
199
+
200
+ def get_relationship_properties(id, properties = nil)
201
+ if properties.nil?
202
+ get("/relationship/#{get_id(id)}/properties")
203
+ else
204
+ relationship_properties = Hash.new
205
+ Array(properties).each do |property|
206
+ value = get("/relationship/#{get_id(id)}/properties/#{property}")
207
+ relationship_properties[property] = value unless value.nil?
208
+ end
209
+ return nil if relationship_properties.empty?
210
+ relationship_properties
211
+ end
212
+ end
213
+
214
+ def remove_relationship_properties(id, properties = nil)
215
+ if properties.nil?
216
+ delete("/relationship/#{get_id(id)}/properties")
217
+ else
218
+ Array(properties).each do |property|
219
+ delete("/relationship/#{get_id(id)}/properties/#{property}")
220
+ end
221
+ end
222
+ end
223
+
224
+ def set_relationship_properties(id, properties)
225
+ properties.each do |key, value|
226
+ options = { :body => value.to_json, :headers => {'Content-Type' => 'application/json'} }
227
+ put("/relationship/#{get_id(id)}/properties/#{key}", options)
228
+ end
229
+ end
230
+
231
+ def delete_relationship(id)
232
+ delete("/relationship/#{get_id(id)}")
233
+ end
234
+
235
+ def get_node_relationships(id, dir=nil, types=nil)
236
+ dir = get_dir(dir)
237
+
238
+ if types.nil?
239
+ node_relationships = get("/node/#{get_id(id)}/relationships/#{dir}") || Array.new
240
+ else
241
+ node_relationships = get("/node/#{get_id(id)}/relationships/#{dir}/#{Array(types).join('&')}") || Array.new
242
+ end
243
+ return nil if node_relationships.empty?
244
+ node_relationships
245
+ end
246
+
247
+ def delete_node!(id)
248
+ relationships = get_node_relationships(get_id(id))
249
+ relationships.each { |r| delete_relationship(r["self"].split('/').last) } unless relationships.nil?
250
+ delete("/node/#{get_id(id)}")
251
+ end
252
+
253
+ def list_node_indexes
254
+ get("/index/node")
255
+ end
256
+
257
+ def create_node_index(name, type = "exact", provider = "lucene")
258
+ options = { :body => ({:name => name, :config => {:type => type, :provider => provider}}).to_json, :headers => {'Content-Type' => 'application/json'} }
259
+ post("/index/node", options)
260
+ end
261
+
262
+ def add_node_to_index(index, key, value, id)
263
+ options = { :body => ({:uri => self.configuration + "/node/#{get_id(id)}", :key => key, :value => value }).to_json, :headers => {'Content-Type' => 'application/json'} }
264
+ post("/index/node/#{index}", options)
265
+ end
266
+
267
+ def create_unique_node(index, key, value, props={})
268
+ options = { :body => ({:properties=>props, :key => key, :value => value }).to_json, :headers => {'Content-Type' => 'application/json'} }
269
+ post("/index/node/#{index}?unique", options)
270
+ end
271
+
272
+ def remove_node_from_index(*args)
273
+ case args.size
274
+ when 4 then delete("/index/node/#{args[0]}/#{args[1]}/#{args[2]}/#{get_id(args[3])}")
275
+ when 3 then delete("/index/node/#{args[0]}/#{args[1]}/#{get_id(args[2])}")
276
+ when 2 then delete("/index/node/#{args[0]}/#{get_id(args[1])}")
277
+ end
278
+ end
279
+
280
+ def get_node_index(index, key, value)
281
+ index = get("/index/node/#{index}/#{key}/#{value}") || Array.new
282
+ return nil if index.empty?
283
+ index
284
+ end
285
+
286
+ def find_node_index(*args)
287
+ case args.size
288
+ when 3 then index = get("/index/node/#{args[0]}/#{args[1]}?query=#{args[2]}") || Array.new
289
+ when 2 then index = get("/index/node/#{args[0]}?query=#{args[1]}") || Array.new
290
+ end
291
+ return nil if index.empty?
292
+ index
293
+ end
294
+
295
+ alias_method :list_indexes, :list_node_indexes
296
+ alias_method :add_to_index, :add_node_to_index
297
+ alias_method :remove_from_index, :remove_node_from_index
298
+ alias_method :get_index, :get_node_index
299
+
300
+ def list_relationship_indexes
301
+ get("/index/relationship")
302
+ end
303
+
304
+ def create_relationship_index(name, type = "exact", provider = "lucene")
305
+ options = { :body => ({:name => name, :config => {:type => type, :provider => provider}}).to_json, :headers => {'Content-Type' => 'application/json'} }
306
+ post("/index/relationship", options)
307
+ end
308
+
309
+ def add_relationship_to_index(index, key, value, id)
310
+ options = { :body => ({:uri => self.configuration + "/relationship/#{get_id(id)}", :key => key, :value => value}).to_json, :headers => {'Content-Type' => 'application/json'} }
311
+ post("/index/relationship/#{index}", options)
312
+ end
313
+
314
+ def remove_relationship_from_index(*args)
315
+ case args.size
316
+ when 4 then delete("/index/relationship/#{args[0]}/#{args[1]}/#{args[2]}/#{get_id(args[3])}")
317
+ when 3 then delete("/index/relationship/#{args[0]}/#{args[1]}/#{get_id(args[2])}")
318
+ when 2 then delete("/index/relationship/#{args[0]}/#{get_id(args[1])}")
319
+ end
320
+ end
321
+
322
+ def get_relationship_index(index, key, value)
323
+ index = get("/index/relationship/#{index}/#{key}/#{value}") || Array.new
324
+ return nil if index.empty?
325
+ index
326
+ end
327
+
328
+ def find_relationship_index(*args)
329
+ case args.size
330
+ when 3 then index = get("/index/relationship/#{args[0]}/#{args[1]}?query=#{args[2]}") || Array.new
331
+ when 2 then index = get("/index/relationship/#{args[0]}?query=#{args[1]}") || Array.new
332
+ end
333
+ return nil if index.empty?
334
+ index
335
+ end
336
+
337
+ def traverse(id, return_type, description)
338
+ options = { :body => {"order" => get_order(description["order"]),
339
+ "uniqueness" => get_uniqueness(description["uniqueness"]),
340
+ "relationships" => description["relationships"],
341
+ "prune_evaluator" => description["prune evaluator"],
342
+ "return_filter" => description["return filter"],
343
+ "max_depth" => get_depth(description["depth"]), }.to_json, :headers => {'Content-Type' => 'application/json'} }
344
+ traversal = post("/node/#{get_id(id)}/traverse/#{get_type(return_type)}", options) || Array.new
345
+ end
346
+
347
+ def get_path(from, to, relationships, depth=1, algorithm="shortestPath")
348
+ options = { :body => {"to" => self.configuration + "/node/#{get_id(to)}", "relationships" => relationships, "max_depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} }
349
+ path = post("/node/#{get_id(from)}/path", options) || Hash.new
350
+ end
351
+
352
+ def get_paths(from, to, relationships, depth=1, algorithm="allPaths")
353
+ options = { :body => {"to" => self.configuration + "/node/#{get_id(to)}", "relationships" => relationships, "max_depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} }
354
+ paths = post("/node/#{get_id(from)}/paths", options) || Array.new
355
+ end
356
+
357
+ def execute_query(query, params = {})
358
+ options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json'} }
359
+ result = post("/ext/CypherPlugin/graphdb/execute_query", options)
360
+ end
361
+
362
+ def execute_script(script, params = {})
363
+ options = { :body => {:script => script, :params => params}.to_json , :headers => {'Content-Type' => 'application/json'} }
364
+ result = post("/ext/GremlinPlugin/graphdb/execute_script", options)
365
+ result == "null" ? nil : result
366
+ end
367
+
368
+ def batch(*args)
369
+ batch = []
370
+ Array(args).each_with_index do |c,i|
371
+ batch << {:id => i}.merge(get_batch(c))
372
+ end
373
+ options = { :body => batch.to_json, :headers => {'Content-Type' => 'application/json'} }
374
+ post("/batch", options)
375
+ end
376
+
377
+ private
378
+
379
+ def get_batch(args)
380
+ case args[0]
381
+ when :get_node
382
+ {:method => "GET", :to => "/node/#{get_id(args[1])}"}
383
+ when :create_node
384
+ {:method => "POST", :to => "/node/", :body => args[1]}
385
+ when :set_node_property
386
+ {:method => "PUT", :to => "/node/#{get_id(args[1])}/properties/#{args[2].keys.first}", :body => args[2].values.first}
387
+ when :reset_node_properties
388
+ {:method => "PUT", :to => "/node/#{get_id(args[1])}/properties", :body => args[2]}
389
+ when :get_relationship
390
+ {:method => "GET", :to => "/relationship/#{get_id(args[1])}"}
391
+ when :create_relationship
392
+ {:method => "POST", :to => (args[2].is_a?(String) && args[2].start_with?("{") ? "" : "/node/") + "#{get_id(args[2])}/relationships", :body => {:to => (args[3].is_a?(String) && args[3].start_with?("{") ? "" : "/node/") + "#{get_id(args[3])}", :type => args[1], :data => args[4] } }
393
+ when :set_relationship_property
394
+ {:method => "PUT", :to => "/relationship/#{get_id(args[1])}/properties/#{args[2].keys.first}", :body => args[2].values.first}
395
+ when :reset_relationship_properties
396
+ {:method => "PUT", :to => "/relationship/#{get_id(args[1])}/properties", :body => args[2]}
397
+ when :add_node_to_index
398
+ {:method => "POST", :to => "/index/node/#{args[1]}", :body => {:uri => (args[4].is_a?(String) && args[4].start_with?("{") ? "" : "/node/") + "#{get_id(args[4])}", :key => args[2], :value => args[3] } }
399
+ when :add_relationship_to_index
400
+ {:method => "POST", :to => "/index/relationship/#{args[1]}", :body => {:uri => (args[4].is_a?(String) && args[4].start_with?("{") ? "" : "/relationship/") + "#{get_id(args[4])}", :key => args[2], :value => args[3] } }
401
+ end
402
+ end
403
+
404
+ def evaluate_response(response)
405
+ code = response.code
406
+ body = response.body
407
+ case code
408
+ when 200
409
+ @logger.debug "OK" if @log_enabled
410
+ response.parsed_response
411
+ when 201
412
+ @logger.debug "OK, created #{body}" if @log_enabled
413
+ response.parsed_response
414
+ when 204
415
+ @logger.debug "OK, no content returned" if @log_enabled
416
+ nil
417
+ when 400
418
+ @logger.error "Invalid data sent #{body}" if @log_enabled
419
+ nil
420
+ when 404
421
+ @logger.error "#{body}" if @log_enabled
422
+ nil
423
+ when 409
424
+ @logger.error "Node could not be deleted (still has relationships?)" if @log_enabled
425
+ nil
426
+ end
427
+ end
428
+
429
+ def get(path,options={})
430
+ @logger.debug "GET #{path} #{options.to_json}" if @log_enabled
431
+ evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication)))
432
+ end
433
+
434
+ def post(path,options={})
435
+ @logger.debug "POST #{path} #{options.to_json}" if @log_enabled
436
+ evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication)))
437
+ end
438
+
439
+ def put(path,options={})
440
+ @logger.debug "PUT #{path} #{options.to_json}" if @log_enabled
441
+ evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication)))
442
+ end
443
+
444
+ def delete(path,options={})
445
+ @logger.debug "DELETE #{path} #{options.to_json}" if @log_enabled
446
+ evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication)))
447
+ end
448
+
449
+ def get_id(id)
450
+ case id
451
+ when Array
452
+ get_id(id.first)
453
+ when Hash
454
+ id["self"].split('/').last
455
+ when String
456
+ id.split('/').last
457
+ when Neography::Node, Neography::Relationship
458
+ id.neo_id
459
+ else
460
+ id
461
+ end
462
+ end
463
+
464
+ def get_dir(dir)
465
+ case dir
466
+ when :incoming, "incoming", :in, "in"
467
+ "in"
468
+ when :outgoing, "outgoing", :out, "out"
469
+ "out"
470
+ else
471
+ "all"
472
+ end
473
+ end
474
+
475
+ def get_algorithm(algorithm)
476
+ case algorithm
477
+ when :shortest, "shortest", :shortestPath, "shortestPath", :short, "short"
478
+ "shortestPath"
479
+ when :allSimplePaths, "allSimplePaths", :simple, "simple"
480
+ "allSimplePaths"
481
+ else
482
+ "allPaths"
483
+ end
484
+ end
485
+
486
+ def get_order(order)
487
+ case order
488
+ when :breadth, "breadth", "breadth first", "breadthFirst", :wide, "wide"
489
+ "breadth first"
490
+ else
491
+ "depth first"
492
+ end
493
+ end
494
+
495
+ def get_type(type)
496
+ case type
497
+ when :relationship, "relationship", :relationships, "relationships"
498
+ "relationship"
499
+ when :path, "path", :paths, "paths"
500
+ "path"
501
+ when :fullpath, "fullpath", :fullpaths, "fullpaths"
502
+ "fullpath"
503
+ else
504
+ "node"
505
+ end
506
+ end
507
+
508
+ def get_uniqueness(uniqueness)
509
+ case uniqueness
510
+ when :nodeglobal, "node global", "nodeglobal", "node_global"
511
+ "node global"
512
+ when :nodepath, "node path", "nodepath", "node_path"
513
+ "node path"
514
+ when :noderecent, "node recent", "noderecent", "node_recent"
515
+ "node recent"
516
+ when :relationshipglobal, "relationship global", "relationshipglobal", "relationship_global"
517
+ "relationship global"
518
+ when :relationshippath, "relationship path", "relationshippath", "relationship_path"
519
+ "relationship path"
520
+ when :relationshiprecent, "relationship recent", "relationshiprecent", "relationship_recent"
521
+ "relationship recent"
522
+ else
523
+ "none"
524
+ end
525
+ end
526
+
527
+ def get_depth(depth)
528
+ return nil if depth.nil?
529
+ return 1 if depth.to_i == 0
530
+ depth.to_i
531
+ end
532
+
533
+ end
534
+ end