neography 0.0.21 → 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,12 +1,14 @@
1
1
  == Welcome to Neography
2
2
 
3
3
  Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:
4
- * {Getting Started with Neo4j Server}[http://wiki.neo4j.org/content/Getting_Started_with_Neo4j_Server]
5
- * {Neo4j Rest API Reference}[http://components.neo4j.org/neo4j-server/milestone/rest.html]
4
+ * {Getting Started with Neo4j Server}[http://neo4j.org/community/]
5
+ * {Neo4j Rest API Reference}[http://docs.neo4j.org/chunked/milestone/rest-api.html]
6
6
 
7
7
  If you want to the full power of Neo4j, you will want to use JRuby and the excellent Neo4j.rb gem at https://github.com/andreasronge/neo4j by Andreas Ronge
8
8
 
9
- A complement to Neography is the Neology Gem at https://github.com/lordkada/neology by Carlo Alberto Degli Atti
9
+ Complement to Neography are the:
10
+ Neology Gem at https://github.com/lordkada/neology by Carlo Alberto Degli Atti
11
+ Neoid Gem at https://github.com/elado/neoid by Elad Ossadon
10
12
 
11
13
  An alternative is the Architect4r Gem at https://github.com/namxam/architect4r by Maximilian Schulz
12
14
 
@@ -96,8 +98,11 @@ To Use:
96
98
  @neo = Neography::Rest.new # Inialize using all default parameters
97
99
 
98
100
  @neo.get_root # Get the root node
99
- node1 = @neo.create_node # Create an empty node
100
- node2 = @neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties
101
+ @neo.create_node # Create an empty node
102
+ @neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties
103
+ @neo.create_unique_node(index_name, key, unique_value, # Create a unique node
104
+ {"age" => 31, "name" => "Max"}) # this needs an existing index
105
+
101
106
  @neo.get_node(node2) # Get a node and its properties
102
107
  @neo.delete_node(node2) # Delete an unrelated node
103
108
  @neo.delete_node!(node2) # Delete a node and all its relationships
@@ -110,8 +115,11 @@ To Use:
110
115
  @neo.remove_node_properties(node1, "weight") # Remove one property of a node
111
116
  @neo.remove_node_properties(node1, ["weight","age"]) # Remove multiple properties of a node
112
117
 
113
- rel1 = @neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2
114
- rel2 = @neo.get_relationship(rel1) # Get a relationship
118
+ @neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2
119
+ @neo.create_unique_relationship(index_name, key, value, # Create a unique relationship between nodes
120
+ "friends", new_node1, new_node2) # this needs an existing index
121
+
122
+ @neo.get_relationship(rel1) # Get a relationship
115
123
  @neo.get_node_relationships(node1) # Get all relationships
116
124
  @neo.get_node_relationships(node1, "in") # Get only incoming relationships
117
125
  @neo.get_node_relationships(node1, "all", "enemies") # Get all relationships of type enemies
@@ -169,10 +177,6 @@ To Use:
169
177
  # "depth" is a short-hand way of specifying a prune evaluator which prunes after a certain depth.
170
178
  # If not specified a depth of 1 is used and if a "prune evaluator" is specified instead of a depth, no depth limit is set.
171
179
 
172
- Please see the specs for more examples.
173
-
174
- Batch (in progress):
175
-
176
180
  @neo.batch [:get_node, node1], [:get_node, node2] # Gets two nodes in a batch
177
181
  @neo.batch [:create_node, {"name" => "Max"}],
178
182
  [:create_node, {"name" => "Marc"}] # Creates two nodes in a batch
@@ -198,6 +202,10 @@ Batch (in progress):
198
202
 
199
203
  See http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.html for Neo4j Batch operations documentation.
200
204
 
205
+
206
+ Please see the specs for more examples.
207
+
208
+
201
209
  Experimental:
202
210
 
203
211
  nodes = @neo.create_nodes(5) # Create 5 empty nodes
@@ -0,0 +1,43 @@
1
+ require 'rubygems'
2
+ require 'neography'
3
+
4
+ def create_great(name)
5
+ Neography::Node.create("name" => name)
6
+ end
7
+
8
+ game = create_great('The 1958 NFL Championship Game')
9
+ brando = create_great('Marlon Brando')
10
+ alex = create_great('Alexander the Great')
11
+ circus = create_great('The Ringling Bros. and Barnum and Bailey')
12
+ beatles = create_great('The Beatles')
13
+ ali = create_great('Muhammad Ali')
14
+ bread = create_great('Sliced Bread')
15
+ gatsby = create_great('The Great Gatsby')
16
+
17
+ greats = [game,brando,alex,circus,beatles,ali,bread,gatsby]
18
+
19
+ def as_great(great, other_greats)
20
+ other_greats.each do |og|
21
+ great.outgoing(:as_great) << og
22
+ end
23
+ end
24
+
25
+ greats.each do |g|
26
+ ogs = greats.select{|v| v != g }.sample(1 + rand(5))
27
+ as_great(g, ogs)
28
+ end
29
+
30
+ def the_greatest
31
+ neo = Neography::Rest.new
32
+ neo.execute_script("m = [:];
33
+ c = 0;
34
+ g.
35
+ V.
36
+ out.
37
+ groupCount(m).
38
+ loop(2){c++ < 1000}.iterate();
39
+
40
+ m.sort{a,b -> b.value <=> a.value}.keySet().name[0];")
41
+ end
42
+
43
+ puts "The greatest is #{the_greatest}"
@@ -172,6 +172,14 @@ module Neography
172
172
  post("/node/#{get_id(from)}/relationships", options)
173
173
  end
174
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
+
175
183
  def get_relationship(id)
176
184
  get("/relationship/#{get_id(id)}")
177
185
  end
@@ -256,6 +264,11 @@ module Neography
256
264
  post("/index/node/#{index}", options)
257
265
  end
258
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
+
259
272
  def remove_node_from_index(*args)
260
273
  case args.size
261
274
  when 4 then delete("/index/node/#{args[0]}/#{args[1]}/#{args[2]}/#{get_id(args[3])}")
@@ -343,7 +356,7 @@ module Neography
343
356
 
344
357
  def execute_query(query, params = {})
345
358
  options = { :body => {:query => query, :params => params}.to_json, :headers => {'Content-Type' => 'application/json'} }
346
- result = post("/ext/CypherPlugin/graphdb/execute_query", options)
359
+ result = post("/cypher", options)
347
360
  end
348
361
 
349
362
  def execute_script(script, params = {})
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "0.0.21"
2
+ VERSION = "0.0.22"
3
3
  end
data/lib/neography.rb CHANGED
@@ -40,7 +40,7 @@ require 'neography/index'
40
40
  require 'neography/node'
41
41
  require 'neography/relationship'
42
42
 
43
- require 'neography/railtie' if defined? Rails
43
+ require 'neography/railtie' if defined? Rails::Railtie
44
44
 
45
45
  find_and_require_user_defined_code
46
46
 
@@ -36,6 +36,17 @@ describe Neography::Rest do
36
36
  new_node["data"]["name"].should == "Max"
37
37
  new_node["data"]["age"].should == 31
38
38
  end
39
+
40
+ it "can create a unique node with more than one property" do
41
+ index_name = generate_text(6)
42
+ key = generate_text(6)
43
+ value = generate_text
44
+ @neo.create_node_index(index_name)
45
+ new_node = @neo.create_unique_node(index_name, key, value, {"age" => 31, "name" => "Max"})
46
+ new_node["data"]["name"].should == "Max"
47
+ new_node["data"]["age"].should == 31
48
+ end
49
+
39
50
  end
40
51
 
41
52
  describe "get_node" do
@@ -30,6 +30,28 @@ describe Neography::Rest do
30
30
  new_relationship["data"]["since"].should == '10-1-2010'
31
31
  new_relationship["data"]["met"].should == "college"
32
32
  end
33
+
34
+ it "can create a unique node with more than one property" do
35
+ index_name = generate_text(6)
36
+ key = generate_text(6)
37
+ value = generate_text
38
+ @neo.create_node_index(index_name)
39
+ new_node = @neo.create_unique_node(index_name, key, value, {"age" => 31, "name" => "Max"})
40
+ new_node["data"]["name"].should == "Max"
41
+ new_node["data"]["age"].should == 31
42
+ end
43
+
44
+ it "can create a unique relationship" do
45
+ index_name = generate_text(6)
46
+ key = generate_text(6)
47
+ value = generate_text
48
+ new_node1 = @neo.create_node
49
+ new_node2 = @neo.create_node
50
+ new_relationship = @neo.create_unique_relationship(index_name, key, value, "friends", new_node1, new_node2)
51
+ new_relationship["data"][key].should == value
52
+ end
53
+
54
+
33
55
  end
34
56
 
35
57
  describe "get_relationship" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neography
3
3
  version: !ruby/object:Gem::Version
4
- hash: 53
4
+ hash: 51
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 21
10
- version: 0.0.21
9
+ - 22
10
+ version: 0.0.22
11
11
  platform: ruby
12
12
  authors:
13
13
  - Max De Marzi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-25 00:00:00 Z
18
+ date: 2012-02-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -141,6 +141,7 @@ files:
141
141
  - Rakefile
142
142
  - examples/facebook.rb
143
143
  - examples/facebook_v2.rb
144
+ - examples/greatest.rb
144
145
  - examples/linkedin.rb
145
146
  - examples/linkedin_v2.rb
146
147
  - examples/traversal_example1.rb