neography 0.0.23 → 0.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +6 -1
- data/lib/neography/config.rb +13 -11
- data/lib/neography/rest.rb +16 -5
- data/lib/neography/tasks.rb +1 -1
- data/lib/neography/version.rb +1 -1
- data/spec/integration/rest_batch_spec.rb +14 -3
- data/spec/integration/rest_path_spec.rb +22 -0
- metadata +16 -16
data/README.rdoc
CHANGED
@@ -86,7 +86,9 @@ to your Rakefile to have access to these tasks.
|
|
86
86
|
:password => 'your password', #leave out for default
|
87
87
|
:log_file => 'neography.log',
|
88
88
|
:log_enabled => false,
|
89
|
-
:max_threads => 20
|
89
|
+
:max_threads => 20,
|
90
|
+
:cypher_path => '/cypher',
|
91
|
+
:gremlin_path => '/ext/GremlinPlugin/graphdb/execute_script'})
|
90
92
|
|
91
93
|
Quick initializer (assumes basic authorization if username is given):
|
92
94
|
|
@@ -159,6 +161,9 @@ To Use:
|
|
159
161
|
|
160
162
|
@neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
|
161
163
|
@neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes
|
164
|
+
@neo.get_shortest_weighted_path(node1, node2, relationships, # find the shortest path between two nodes
|
165
|
+
weight_attr='weight', depth=2, # accounting for weight in the relationships
|
166
|
+
algorithm='dijkstra') # using 'weight' as the attribute
|
162
167
|
|
163
168
|
nodes = @neo.traverse(node1, # the node where the traversal starts
|
164
169
|
"nodes", # return_type "nodes", "relationships" or "paths"
|
data/lib/neography/config.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
module Neography
|
2
2
|
class Config
|
3
|
-
class << self; attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password end
|
3
|
+
class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password end
|
4
4
|
|
5
|
-
@protocol
|
6
|
-
@server
|
7
|
-
@port
|
8
|
-
@directory
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
5
|
+
@protocol = 'http://'
|
6
|
+
@server = 'localhost'
|
7
|
+
@port = 7474
|
8
|
+
@directory = ''
|
9
|
+
@cypher_path = '/cypher'
|
10
|
+
@gremlin_path = '/ext/GremlinPlugin/graphdb/execute_script'
|
11
|
+
@log_file = 'neography.log'
|
12
|
+
@log_enabled = false
|
13
|
+
@logger = Logger.new(@log_file) if @log_enabled
|
14
|
+
@max_threads = 20
|
13
15
|
@authentication = {}
|
14
|
-
@username
|
15
|
-
@password
|
16
|
+
@username = nil
|
17
|
+
@password = nil
|
16
18
|
end
|
17
19
|
end
|
data/lib/neography/rest.rb
CHANGED
@@ -2,13 +2,15 @@ module Neography
|
|
2
2
|
class Rest
|
3
3
|
include HTTParty
|
4
4
|
|
5
|
-
attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password
|
5
|
+
attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password
|
6
6
|
|
7
7
|
def initialize(options=ENV['NEO4J_URL'] || {})
|
8
8
|
init = {:protocol => Neography::Config.protocol,
|
9
9
|
:server => Neography::Config.server,
|
10
10
|
:port => Neography::Config.port,
|
11
|
-
:directory => Neography::Config.directory,
|
11
|
+
:directory => Neography::Config.directory,
|
12
|
+
:cypher_path => Neography::Config.cypher_path,
|
13
|
+
:gremlin_path => Neography::Config.gremlin_path,
|
12
14
|
:log_file => Neography::Config.log_file,
|
13
15
|
:log_enabled => Neography::Config.log_enabled,
|
14
16
|
:max_threads => Neography::Config.max_threads,
|
@@ -34,6 +36,8 @@ module Neography
|
|
34
36
|
@server = init[:server]
|
35
37
|
@port = init[:port]
|
36
38
|
@directory = init[:directory]
|
39
|
+
@cypher_path = init[:cypher_path]
|
40
|
+
@gremlin_path = init[:gremlin_path]
|
37
41
|
@log_file = init[:log_file]
|
38
42
|
@log_enabled = init[:log_enabled]
|
39
43
|
@logger = Logger.new(@log_file) if @log_enabled
|
@@ -353,15 +357,20 @@ module Neography
|
|
353
357
|
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
358
|
paths = post("/node/#{get_id(from)}/paths", options) || Array.new
|
355
359
|
end
|
360
|
+
|
361
|
+
def get_shortest_weighted_path(from, to, relationships, weight_attr='weight', depth=1, algorithm="dijkstra")
|
362
|
+
options = { :body => {"to" => self.configuration + "/node/#{get_id(to)}", "relationships" => relationships, "cost_property" => weight_attr, "max_depth" => depth, "algorithm" => get_algorithm(algorithm) }.to_json, :headers => {'Content-Type' => 'application/json'} }
|
363
|
+
paths = post("/node/#{get_id(from)}/paths", options) || Hash.new
|
364
|
+
end
|
356
365
|
|
357
366
|
def execute_query(query, params = {})
|
358
367
|
options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json'} }
|
359
|
-
result = post(
|
368
|
+
result = post(@cypher_path, options)
|
360
369
|
end
|
361
370
|
|
362
371
|
def execute_script(script, params = {})
|
363
372
|
options = { :body => {:script => script, :params => params}.to_json , :headers => {'Content-Type' => 'application/json'} }
|
364
|
-
result = post(
|
373
|
+
result = post(@gremlin_path, options)
|
365
374
|
result == "null" ? nil : result
|
366
375
|
end
|
367
376
|
|
@@ -397,7 +406,7 @@ module Neography
|
|
397
406
|
when :set_relationship_property
|
398
407
|
{:method => "PUT", :to => "/relationship/#{get_id(args[1])}/properties/#{args[2].keys.first}", :body => args[2].values.first}
|
399
408
|
when :reset_relationship_properties
|
400
|
-
{:method => "PUT", :to => "/relationship
|
409
|
+
{:method => "PUT", :to => (args[1].is_a?(String) && args[1].start_with?("{") ? "" : "/relationship/") + "#{get_id(args[1])}/properties", :body => args[2]}
|
401
410
|
when :add_node_to_index
|
402
411
|
{: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] } }
|
403
412
|
when :add_relationship_to_index
|
@@ -482,6 +491,8 @@ module Neography
|
|
482
491
|
"shortestPath"
|
483
492
|
when :allSimplePaths, "allSimplePaths", :simple, "simple"
|
484
493
|
"allSimplePaths"
|
494
|
+
when :dijkstra, "dijkstra"
|
495
|
+
"dijkstra"
|
485
496
|
else
|
486
497
|
"allPaths"
|
487
498
|
end
|
data/lib/neography/tasks.rb
CHANGED
@@ -4,7 +4,7 @@ require 'os'
|
|
4
4
|
namespace :neo4j do
|
5
5
|
desc "Install Neo4j"
|
6
6
|
task :install, :edition, :version do |t, args|
|
7
|
-
args.with_defaults(:edition => "community", :version => "1.
|
7
|
+
args.with_defaults(:edition => "community", :version => "1.7.M01")
|
8
8
|
puts "Installing Neo4j-#{args[:edition]}-#{args[:version]}"
|
9
9
|
|
10
10
|
if OS::Underlying.windows?
|
data/lib/neography/version.rb
CHANGED
@@ -235,9 +235,6 @@ describe Neography::Rest do
|
|
235
235
|
batch_result.first["body"].first["end"].split('/').last.should == node2["self"].split('/').last
|
236
236
|
end
|
237
237
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
238
|
describe "referenced batch" do
|
242
239
|
it "can create a relationship from two newly created nodes" do
|
243
240
|
batch_result = @neo.batch [:create_node, {"name" => "Max"}], [:create_node, {"name" => "Marc"}], [:create_relationship, "friends", "{0}", "{1}", {:since => "high school"}]
|
@@ -285,7 +282,21 @@ describe Neography::Rest do
|
|
285
282
|
existing_index = @neo.find_relationship_index("test_relationship_index", key, value)
|
286
283
|
existing_index.should_not be_nil
|
287
284
|
existing_index.first["self"].should == batch_result.first["body"]["self"]
|
285
|
+
end
|
288
286
|
|
287
|
+
it "can reset the properties of a newly created relationship" do
|
288
|
+
node1 = @neo.create_node
|
289
|
+
node2 = @neo.create_node
|
290
|
+
batch_result = @neo.batch [:create_relationship, "friends", node1, node2, {:since => "high school"}], [:reset_relationship_properties, "{0}", {"since" => "college", "dated" => "yes"}]
|
291
|
+
batch_result.first.should have_key("id")
|
292
|
+
batch_result.first.should have_key("from")
|
293
|
+
existing_relationship = @neo.get_relationship(batch_result.first["body"]["self"].split('/').last)
|
294
|
+
existing_relationship["type"].should == "friends"
|
295
|
+
existing_relationship["data"]["since"].should == "college"
|
296
|
+
existing_relationship["data"]["dated"].should == "yes"
|
297
|
+
existing_relationship["start"].split('/').last.should == node1["self"].split('/').last
|
298
|
+
existing_relationship["end"].split('/').last.should == node2["self"].split('/').last
|
299
|
+
existing_relationship["self"].should == batch_result.first["body"]["self"]
|
289
300
|
end
|
290
301
|
|
291
302
|
it "can kitchen sink" do
|
@@ -33,6 +33,28 @@ describe Neography::Rest do
|
|
33
33
|
path["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node5["self"]]
|
34
34
|
end
|
35
35
|
|
36
|
+
it "can get the shortest weighted path between two nodes" do
|
37
|
+
new_node1 = @neo.create_node
|
38
|
+
new_node2 = @neo.create_node
|
39
|
+
new_node3 = @neo.create_node
|
40
|
+
new_node4 = @neo.create_node
|
41
|
+
new_node5 = @neo.create_node
|
42
|
+
rel1_2 = @neo.create_relationship("friends", new_node1, new_node2)
|
43
|
+
rel2_3 = @neo.create_relationship("friends", new_node2, new_node3)
|
44
|
+
rel3_4 = @neo.create_relationship("friends", new_node3, new_node4)
|
45
|
+
rel4_5 = @neo.create_relationship("friends", new_node4, new_node5)
|
46
|
+
rel3_5 = @neo.create_relationship("friends", new_node3, new_node5)
|
47
|
+
@neo.set_relationship_properties(rel1_2, {:weight => 1})
|
48
|
+
@neo.set_relationship_properties(rel2_3, {:weight => 1})
|
49
|
+
@neo.set_relationship_properties(rel3_4, {:weight => 1})
|
50
|
+
@neo.set_relationship_properties(rel4_5, {:weight => 1})
|
51
|
+
@neo.set_relationship_properties(rel3_5, {:weight => 3})
|
52
|
+
path = @neo.get_shortest_weighted_path(new_node1, new_node5, {"type"=> "friends", "direction" => "out"})
|
53
|
+
path.first["start"].should == new_node1["self"]
|
54
|
+
path.first["end"].should == new_node5["self"]
|
55
|
+
path.first["nodes"].should == [new_node1["self"], new_node2["self"], new_node3["self"], new_node4["self"], new_node5["self"]]
|
56
|
+
end
|
57
|
+
|
36
58
|
it "can get a simple path between two nodes" do
|
37
59
|
new_node1 = @neo.create_node
|
38
60
|
new_node2 = @neo.create_node
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neography
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.24
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-22 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &81537140 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *81537140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: net-http-spy
|
27
|
-
requirement: &
|
27
|
+
requirement: &81536810 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.2.1
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *81536810
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &81536470 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.8.7
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *81536470
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: httparty
|
49
|
-
requirement: &
|
49
|
+
requirement: &81535920 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.7.8
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *81535920
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: json
|
60
|
-
requirement: &
|
60
|
+
requirement: &81535730 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *81535730
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: os
|
71
|
-
requirement: &
|
71
|
+
requirement: &81518230 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :runtime
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *81518230
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rubyzip
|
82
|
-
requirement: &
|
82
|
+
requirement: &81517920 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *81517920
|
91
91
|
description: A Ruby wrapper to the Neo4j Rest API see http://components.neo4j.org/neo4j-rest/
|
92
92
|
for more details.
|
93
93
|
email: maxdemarzi@gmail.com
|