neography 0.0.31 → 1.0.0
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/.gitignore +3 -0
- data/.travis.yml +1 -1
- data/CONTRIBUTORS +2 -1
- data/README.md +247 -0
- data/Rakefile +1 -2
- data/lib/neography/config.rb +48 -16
- data/lib/neography/connection.rb +151 -0
- data/lib/neography/errors.rb +42 -0
- data/lib/neography/node.rb +17 -14
- data/lib/neography/node_relationship.rb +3 -1
- data/lib/neography/node_traverser.rb +24 -20
- data/lib/neography/property.rb +31 -28
- data/lib/neography/property_container.rb +1 -1
- data/lib/neography/relationship.rb +16 -19
- data/lib/neography/rest/auto_indexes.rb +64 -0
- data/lib/neography/rest/batch.rb +262 -0
- data/lib/neography/rest/clean.rb +19 -0
- data/lib/neography/rest/cypher.rb +24 -0
- data/lib/neography/rest/gremlin.rb +24 -0
- data/lib/neography/rest/helpers.rb +26 -0
- data/lib/neography/rest/indexes.rb +97 -0
- data/lib/neography/rest/node_auto_indexes.rb +14 -0
- data/lib/neography/rest/node_indexes.rb +35 -0
- data/lib/neography/rest/node_paths.rb +57 -0
- data/lib/neography/rest/node_properties.rb +11 -0
- data/lib/neography/rest/node_relationships.rb +53 -0
- data/lib/neography/rest/node_traversal.rb +81 -0
- data/lib/neography/rest/nodes.rb +102 -0
- data/lib/neography/rest/paths.rb +36 -0
- data/lib/neography/rest/properties.rb +56 -0
- data/lib/neography/rest/relationship_auto_indexes.rb +14 -0
- data/lib/neography/rest/relationship_indexes.rb +35 -0
- data/lib/neography/rest/relationship_properties.rb +11 -0
- data/lib/neography/rest/relationships.rb +23 -0
- data/lib/neography/rest.rb +285 -615
- data/lib/neography/tasks.rb +1 -1
- data/lib/neography/version.rb +1 -1
- data/lib/neography.rb +13 -2
- data/neography.gemspec +8 -8
- data/spec/integration/authorization_spec.rb +2 -2
- data/spec/integration/index_spec.rb +4 -4
- data/spec/integration/neography_spec.rb +2 -2
- data/spec/integration/node_path_spec.rb +2 -2
- data/spec/integration/node_relationship_spec.rb +5 -3
- data/spec/integration/node_spec.rb +20 -19
- data/spec/integration/parsing_spec.rb +2 -2
- data/spec/integration/relationship_spec.rb +2 -2
- data/spec/integration/rest_batch_spec.rb +28 -28
- data/spec/integration/rest_bulk_spec.rb +2 -2
- data/spec/integration/rest_experimental_spec.rb +2 -2
- data/spec/integration/rest_gremlin_fail_spec.rb +2 -2
- data/spec/integration/rest_header_spec.rb +4 -9
- data/spec/integration/rest_index_spec.rb +21 -1
- data/spec/integration/rest_node_spec.rb +58 -44
- data/spec/integration/rest_path_spec.rb +5 -5
- data/spec/integration/rest_plugin_spec.rb +8 -2
- data/spec/integration/rest_relationship_spec.rb +35 -30
- data/spec/integration/rest_traverse_spec.rb +2 -2
- data/spec/matchers.rb +33 -0
- data/spec/neography_spec.rb +23 -0
- data/spec/spec_helper.rb +19 -1
- data/spec/unit/config_spec.rb +46 -0
- data/spec/unit/connection_spec.rb +205 -0
- data/spec/unit/node_spec.rb +100 -0
- data/spec/unit/properties_spec.rb +136 -0
- data/spec/unit/relationship_spec.rb +118 -0
- data/spec/unit/rest/batch_spec.rb +243 -0
- data/spec/unit/rest/clean_spec.rb +17 -0
- data/spec/unit/rest/cypher_spec.rb +21 -0
- data/spec/unit/rest/gremlin_spec.rb +26 -0
- data/spec/unit/rest/node_auto_indexes_spec.rb +67 -0
- data/spec/unit/rest/node_indexes_spec.rb +126 -0
- data/spec/unit/rest/node_paths_spec.rb +80 -0
- data/spec/unit/rest/node_properties_spec.rb +80 -0
- data/spec/unit/rest/node_relationships_spec.rb +78 -0
- data/spec/unit/rest/node_traversal_spec.rb +128 -0
- data/spec/unit/rest/nodes_spec.rb +188 -0
- data/spec/unit/rest/paths_spec.rb +69 -0
- data/spec/unit/rest/relationship_auto_indexes_spec.rb +67 -0
- data/spec/unit/rest/relationship_indexes_spec.rb +128 -0
- data/spec/unit/rest/relationship_properties_spec.rb +80 -0
- data/spec/unit/rest/relationships_spec.rb +22 -0
- metadata +86 -19
- data/Gemfile.lock +0 -44
- data/README.rdoc +0 -420
data/README.rdoc
DELETED
|
@@ -1,420 +0,0 @@
|
|
|
1
|
-
== Welcome to Neography
|
|
2
|
-
|
|
3
|
-
Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:
|
|
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
|
-
|
|
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
|
-
|
|
9
|
-
{<img src="https://secure.travis-ci.org/maxdemarzi/neography.png?branch=master" alt="Build Status" />}[http://travis-ci.org/maxdemarzi/neography]
|
|
10
|
-
{<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/maxdemarzi/neography]
|
|
11
|
-
|
|
12
|
-
Complement to Neography are the:
|
|
13
|
-
|
|
14
|
-
* {Neo4j Active Record Adapter}[https://github.com/yournextleap/activerecord-neo4j-adapter] by Nikhil Lanjewar
|
|
15
|
-
* {Neology}[https://github.com/lordkada/neology] by Carlo Alberto Degli Atti
|
|
16
|
-
* {Neoid}[https://github.com/elado/neoid] by Elad Ossadon
|
|
17
|
-
|
|
18
|
-
An alternative is the Architect4r Gem at https://github.com/namxam/architect4r by Maximilian Schulz
|
|
19
|
-
|
|
20
|
-
=== Neography in the Wild
|
|
21
|
-
|
|
22
|
-
* {Vouched}[http://getvouched.com]
|
|
23
|
-
* {Neovigator}[http://neovigator.herokuapp.com] fork it at https://github.com/maxdemarzi/neovigator
|
|
24
|
-
* {Neoflix}[http://neoflix.herokuapp.com] fork it at https://github.com/maxdemarzi/neoflix
|
|
25
|
-
|
|
26
|
-
=== Getting started with Neography
|
|
27
|
-
|
|
28
|
-
* {Getting Started with Ruby and Neo4j}[http://maxdemarzi.com/2012/01/04/getting-started-with-ruby-and-neo4j/]
|
|
29
|
-
* {Graph visualization with Neo4j}[http://maxdemarzi.com/2012/01/11/graph-visualization-and-neo4j/]
|
|
30
|
-
* {Neo4j on Heroku}[http://maxdemarzi.com/2012/01/13/neo4j-on-heroku-part-one/]
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
=== Installation
|
|
34
|
-
|
|
35
|
-
gem install 'neography'
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
After that, in your ruby script:
|
|
39
|
-
|
|
40
|
-
require 'rubygems'
|
|
41
|
-
require 'neography'
|
|
42
|
-
|
|
43
|
-
in order to access the functionality.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
=== Dependencies
|
|
47
|
-
|
|
48
|
-
for use:
|
|
49
|
-
os
|
|
50
|
-
rake
|
|
51
|
-
json
|
|
52
|
-
httparty
|
|
53
|
-
|
|
54
|
-
for development:
|
|
55
|
-
rspec
|
|
56
|
-
net-http-spy
|
|
57
|
-
|
|
58
|
-
==== Rails
|
|
59
|
-
|
|
60
|
-
Just add gem 'neography' to your Gemfile and run bundle install.
|
|
61
|
-
|
|
62
|
-
The following tasks will be available to you:
|
|
63
|
-
|
|
64
|
-
rake neo4j:install # Install Neo4j to the neo4j directory under your project
|
|
65
|
-
rake neo4j:install[community,1.6.M03] # Install Neo4j Community edition, version 1.6.M03
|
|
66
|
-
rake neo4j:install[advanced,1.5] # Install Neo4j Advanced edition, version 1.5
|
|
67
|
-
rake neo4j:install[enterprise,1.5] # Install Neo4j Enterprise edition, version 1.5
|
|
68
|
-
rake neo4j:start # Start Neo4j
|
|
69
|
-
rake neo4j:stop # Stop Neo4j
|
|
70
|
-
rake neo4j:restart # Restart Neo4j
|
|
71
|
-
rake neo4j:reset_yes_i_am_sure # Wipe your Neo4j Database
|
|
72
|
-
|
|
73
|
-
Windows users will need to run in a command prompt with Administrative Privileges
|
|
74
|
-
in order to install Neo4j as a Service.
|
|
75
|
-
|
|
76
|
-
If you are not using Rails, then add:
|
|
77
|
-
|
|
78
|
-
require 'neography/tasks'
|
|
79
|
-
|
|
80
|
-
to your Rakefile to have access to these tasks.
|
|
81
|
-
|
|
82
|
-
rake neo4j:install requires wget to be installed. It will download and install Neo4j into a neo4j directory in your project regardless of what version you choose.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
=== Documentation
|
|
86
|
-
|
|
87
|
-
@neo = Neography::Rest.new({:protocol => 'http://',
|
|
88
|
-
:server => 'localhost',
|
|
89
|
-
:port => 7474,
|
|
90
|
-
:directory => '', # use '/<my directory>' or leave out for default
|
|
91
|
-
:authentication => 'basic', # 'basic', 'digest' or leave out for default
|
|
92
|
-
:username => 'your username', #leave out for default
|
|
93
|
-
:password => 'your password', #leave out for default
|
|
94
|
-
:log_file => 'neography.log',
|
|
95
|
-
:log_enabled => false,
|
|
96
|
-
:max_threads => 20,
|
|
97
|
-
:cypher_path => '/cypher',
|
|
98
|
-
:gremlin_path => '/ext/GremlinPlugin/graphdb/execute_script'})
|
|
99
|
-
|
|
100
|
-
Quick initializer (assumes basic authorization if username is given):
|
|
101
|
-
|
|
102
|
-
@neo = Neography::Rest.new("http://username:password@myserver.com:7474/mydirectory")
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
To Use:
|
|
106
|
-
|
|
107
|
-
@neo = Neography::Rest.new # Inialize using all default parameters
|
|
108
|
-
|
|
109
|
-
@neo.get_root # Get the root node
|
|
110
|
-
@neo.create_node # Create an empty node
|
|
111
|
-
@neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties
|
|
112
|
-
@neo.create_unique_node(index_name, key, unique_value, # Create a unique node
|
|
113
|
-
{"age" => 31, "name" => "Max"}) # this needs an existing index
|
|
114
|
-
|
|
115
|
-
@neo.get_node(node2) # Get a node and its properties
|
|
116
|
-
@neo.delete_node(node2) # Delete an unrelated node
|
|
117
|
-
@neo.delete_node!(node2) # Delete a node and all its relationships
|
|
118
|
-
|
|
119
|
-
@neo.reset_node_properties(node1, {"age" => 31}) # Reset a node's properties
|
|
120
|
-
@neo.set_node_properties(node1, {"weight" => 200}) # Set a node's properties
|
|
121
|
-
@neo.get_node_properties(node1) # Get just the node properties
|
|
122
|
-
@neo.get_node_properties(node1, ["weight","age"]) # Get some of the node properties
|
|
123
|
-
@neo.remove_node_properties(node1) # Remove all properties of a node
|
|
124
|
-
@neo.remove_node_properties(node1, "weight") # Remove one property of a node
|
|
125
|
-
@neo.remove_node_properties(node1, ["weight","age"]) # Remove multiple properties of a node
|
|
126
|
-
|
|
127
|
-
@neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2
|
|
128
|
-
@neo.create_unique_relationship(index_name, key, value, # Create a unique relationship between nodes
|
|
129
|
-
"friends", new_node1, new_node2) # this needs an existing index
|
|
130
|
-
|
|
131
|
-
@neo.get_relationship(rel1) # Get a relationship
|
|
132
|
-
@neo.get_node_relationships(node1) # Get all relationships
|
|
133
|
-
@neo.get_node_relationships(node1, "in") # Get only incoming relationships
|
|
134
|
-
@neo.get_node_relationships(node1, "all", "enemies") # Get all relationships of type enemies
|
|
135
|
-
@neo.get_node_relationships(node1, "in", "enemies") # Get only incoming relationships of type enemies
|
|
136
|
-
@neo.delete_relationship(rel1) # Delete a relationship
|
|
137
|
-
|
|
138
|
-
@neo.reset_relationship_properties(rel1, {"age" => 31}) # Reset a relationship's properties
|
|
139
|
-
@neo.set_relationship_properties(rel1, {"weight" => 200}) # Set a relationship's properties
|
|
140
|
-
@neo.get_relationship_properties(rel1) # Get just the relationship properties
|
|
141
|
-
@neo.get_relationship_properties(rel1, ["since","met"]) # Get some of the relationship properties
|
|
142
|
-
@neo.remove_relationship_properties(rel1) # Remove all properties of a relationship
|
|
143
|
-
@neo.remove_relationship_properties(rel1, "since") # Remove one property of a relationship
|
|
144
|
-
@neo.remove_relationship_properties(rel1, ["since","met"]) # Remove multiple properties of a relationship
|
|
145
|
-
|
|
146
|
-
@neo.list_node_indexes # gives names and query templates for all defined indices
|
|
147
|
-
@neo.create_node_index(name, type, provider) # creates an index, defaults are "exact" and "lucene"
|
|
148
|
-
@neo.create_node_auto_index(type, provider) # creates an auto index, defaults are "exact" and "lucene"
|
|
149
|
-
@neo.add_node_to_index(index, key, value, node1) # adds a node to the index with the given key/value pair
|
|
150
|
-
@neo.remove_node_from_index(index, key, value, node1) # removes a node from the index with the given key/value pair
|
|
151
|
-
@neo.remove_node_from_index(index, key, node1) # removes a node from the index with the given key
|
|
152
|
-
@neo.remove_node_from_index(index, node1) # removes a node from the index
|
|
153
|
-
@neo.get_node_index(index, key, value) # exact query of the node index with the given key/value pair
|
|
154
|
-
@neo.find_node_index(index, key, value) # advanced query of the node index with the given key/value pair
|
|
155
|
-
@neo.find_node_index(index, query) # advanced query of the node index with the given query
|
|
156
|
-
@neo.get_node_auto_index(key, value) # exact query of the node auto index with the given key/value pair
|
|
157
|
-
@neo.find_node_auto_index(query) # advanced query of the node auto index with the given query
|
|
158
|
-
@neo.list_relationship_indexes # gives names and query templates for relationship indices
|
|
159
|
-
@neo.create_relationship_index(name, "fulltext", provider) # creates a relationship index with "fulltext" option
|
|
160
|
-
@neo.create_relationship_auto_index("fulltext", provider) # creates a relationship auto index with "fulltext" option
|
|
161
|
-
@neo.add_relationship_to_index(index, key, value, rel1) # adds a relationship to the index with the given key/value pair
|
|
162
|
-
@neo.remove_relationship_from_index(index, key, value, rel1) # removes a relationship from the index with the given key/value pair
|
|
163
|
-
@neo.remove_relationship_from_index(index, key, rel1) # removes a relationship from the index with the given key
|
|
164
|
-
@neo.remove_relationship_from_index(index, rel1) # removes a relationship from the index
|
|
165
|
-
@neo.get_relationship_index(index, key, value) # exact query of the relationship index with the given key/value pair
|
|
166
|
-
@neo.find_relationship_index(index, key, value) # advanced query of the relationship index with the given key/value pair
|
|
167
|
-
@neo.find_relationship_index(index, query) # advanced query of the relationship index with the given query
|
|
168
|
-
@neo.get_relationship_auto_index(key, value) # exact query of the relationship auto index with the given key/value pair
|
|
169
|
-
@neo.find_relationship_auto_index(query) # advanced query of the relationship auto index with the given query
|
|
170
|
-
|
|
171
|
-
@neo.get_node_auto_index_status # true or false depending on node auto index setting
|
|
172
|
-
@neo.get_relationship_auto_index_status # true or false depending on relationship auto index setting
|
|
173
|
-
@neo.set_node_auto_index_status(true) # set the node auto index setting to true
|
|
174
|
-
@neo.set_relationship_auto_index_status(false) # set the relationship auto index setting to false
|
|
175
|
-
@neo.get_node_auto_index_properties # array of currently auto indexed node properties
|
|
176
|
-
@neo.get_relationship_auto_index_properties # array of currently auto indexed relationship properties
|
|
177
|
-
@neo.add_node_auto_index_property(property) # add to auto indexed node properties
|
|
178
|
-
@neo.remove_node_auto_index_property(property) # remove from auto indexed node properties
|
|
179
|
-
@neo.add_relationship_auto_index_property(property) # add to auto indexed relationship properties
|
|
180
|
-
@neo.remove_relationship_auto_index_property(property) # remove from auto indexed relationship properties
|
|
181
|
-
|
|
182
|
-
@neo.execute_script("g.v(0)") # sends a Groovy script (through the Gremlin plugin)
|
|
183
|
-
@neo.execute_script("g.v(id)", {:id => 3}) # sends a parameterized Groovy script (optimized for repeated calls)
|
|
184
|
-
@neo.execute_query("start n=node(0) return n") # sends a Cypher query (through the Cypher plugin)
|
|
185
|
-
@neo.execute_query("start n=node(id) return n", {:id => 3}) # sends a parameterized Cypher query (optimized for repeated calls)
|
|
186
|
-
|
|
187
|
-
@neo.get_path(node1, node2, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
|
|
188
|
-
@neo.get_paths(node1, node2, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes
|
|
189
|
-
@neo.get_shortest_weighted_path(node1, node2, relationships, # find the shortest path between two nodes
|
|
190
|
-
weight_attr='weight', depth=2, # accounting for weight in the relationships
|
|
191
|
-
algorithm='dijkstra') # using 'weight' as the attribute
|
|
192
|
-
|
|
193
|
-
nodes = @neo.traverse(node1, # the node where the traversal starts
|
|
194
|
-
"nodes", # return_type "nodes", "relationships" or "paths"
|
|
195
|
-
{"order" => "breadth first", # "breadth first" or "depth first" traversal order
|
|
196
|
-
"uniqueness" => "node global", # See Uniqueness in API documentation for options.
|
|
197
|
-
"relationships" => [{"type"=> "roommates", # A hash containg a description of the traversal
|
|
198
|
-
"direction" => "all"}, # two relationships.
|
|
199
|
-
{"type"=> "friends", #
|
|
200
|
-
"direction" => "out"}], #
|
|
201
|
-
"prune evaluator" => {"language" => "javascript", # A prune evaluator (when to stop traversing)
|
|
202
|
-
"body" => "position.endNode().getProperty('age') < 21;"},
|
|
203
|
-
"return filter" => {"language" => "builtin", # "all" or "all but start node"
|
|
204
|
-
"name" => "all"},
|
|
205
|
-
"depth" => 4})
|
|
206
|
-
|
|
207
|
-
# "depth" is a short-hand way of specifying a prune evaluator which prunes after a certain depth.
|
|
208
|
-
# 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.
|
|
209
|
-
|
|
210
|
-
@neo.batch [:get_node, node1], [:get_node, node2] # Gets two nodes in a batch
|
|
211
|
-
@neo.batch [:create_node, {"name" => "Max"}],
|
|
212
|
-
[:create_node, {"name" => "Marc"}] # Creates two nodes in a batch
|
|
213
|
-
@neo.batch [:set_node_property, node1, {"name" => "Tom"}],
|
|
214
|
-
[:set_node_property, node2, {"name" => "Jerry"}] # Sets the property of two nodes
|
|
215
|
-
@neo.batch [:create_unique_node, index_name, key, value,
|
|
216
|
-
{"age" => 33, "name" => "Max"}] # Creates a unique node
|
|
217
|
-
@neo.batch [:get_node_relationships, node1, "out",
|
|
218
|
-
[:get_node_relationships, node2, "out"] # Get node relationships in a batch
|
|
219
|
-
@neo.batch [:get_relationship, rel1],
|
|
220
|
-
[:get_relationship, rel2] # Gets two relationships in a batch
|
|
221
|
-
@neo.batch [:create_relationship, "friends",
|
|
222
|
-
node1, node2, {:since => "high school"}],
|
|
223
|
-
[:create_relationship, "friends",
|
|
224
|
-
node1, node3, {:since => "college"}] # Creates two relationships in a batch
|
|
225
|
-
@neo.batch [:create_unique_relationship, index_name,
|
|
226
|
-
key, value, "friends", node1, node2] # Creates a unique relationship
|
|
227
|
-
@neo.batch [:get_node_index, index_name, key, value] # Get node index
|
|
228
|
-
@neo.batch [:get_relationship_index, index_name, key, value] # Get relationship index
|
|
229
|
-
|
|
230
|
-
@neo.batch [:create_node, {"name" => "Max"}],
|
|
231
|
-
[:create_node, {"name" => "Marc"}], # Creates two nodes and index them
|
|
232
|
-
[:add_node_to_index, "test_node_index", key, value, "{0}"],
|
|
233
|
-
[:add_node_to_index, "test_node_index", key, value, "{1}"],
|
|
234
|
-
[:create_relationship, "friends", # and create a relationship for those
|
|
235
|
-
"{0}", "{1}", {:since => "college"}], # newly created nodes
|
|
236
|
-
[:add_relationship_to_index,
|
|
237
|
-
"test_relationship_index", key, value, "{4}"] # and index the new relationship
|
|
238
|
-
|
|
239
|
-
@neo.batch *[[:create_node, {"name" => "Max"}],
|
|
240
|
-
[:create_node, {"name" => "Marc"}]] # Use the Splat (*) with Arrays of Arrays
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
See http://docs.neo4j.org/chunked/milestone/rest-api-batch-ops.html for Neo4j Batch operations documentation.
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
Please see the specs for more examples.
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
Experimental:
|
|
250
|
-
|
|
251
|
-
nodes = @neo.create_nodes(5) # Create 5 empty nodes
|
|
252
|
-
nodes = @neo.create_nodes_threaded(5) # Create 5 empty nodes using threads
|
|
253
|
-
nodes = @neo.create_node_nodes([{"age" => 31, "name" => "Max"},
|
|
254
|
-
{"age" => 24, "name" => "Alex"}) # Create two nodes with properties
|
|
255
|
-
nodes = @neo.create_node_nodes_threaded([{"age" => 31, "name" => "Max"},
|
|
256
|
-
{"age" => 24, "name" => "Alex"}) # Create two nodes with properties threaded
|
|
257
|
-
nodes = @neo.get_nodes([17,86,397,33]) # Get four nodes by their id
|
|
258
|
-
|
|
259
|
-
one_set_nodes = @neo.create_nodes(3)
|
|
260
|
-
another_node = @neo.create_node("age" => 31, "name" => "Max")
|
|
261
|
-
nodes = @neo.get_nodes([one_set_nodes, another_node]) # Get four nodes
|
|
262
|
-
|
|
263
|
-
=== Phase 2
|
|
264
|
-
|
|
265
|
-
Trying to mimic the Neo4j.rb API.
|
|
266
|
-
|
|
267
|
-
Now we are returning full objects. The properties of the node or relationship can be accessed directly (node.name).
|
|
268
|
-
The Neo4j ID is available by using node.neo_id .
|
|
269
|
-
|
|
270
|
-
@neo2 = Neography::Rest.new ({:server => '192.168.10.1'})
|
|
271
|
-
|
|
272
|
-
Neography::Node.create # Create an empty node
|
|
273
|
-
Neography::Node.create("age" => 31, "name" => "Max") # Create a node with some properties
|
|
274
|
-
Neography::Node.create(@neo2, {"age" => 31, "name" => "Max"}) # Create a node on the server defined in @neo2
|
|
275
|
-
Neography::Node.create({"age" => 31, "name" => "Max"}, @neo2) # Same as above, but different order
|
|
276
|
-
|
|
277
|
-
Neography::Node.load(5) # Get a node and its properties by id
|
|
278
|
-
Neography::Node.load(existing_node) # Get a node and its properties by Node
|
|
279
|
-
Neography::Node.load("http://localhost:7474/db/data/node/2") # Get a node and its properties by String
|
|
280
|
-
|
|
281
|
-
Neography::Node.load(@neo2, 5) # Get a node on the server defined in @neo2
|
|
282
|
-
Neography::Node.load(5, @neo2) # Same as above, but different order
|
|
283
|
-
|
|
284
|
-
n1 = Node.create
|
|
285
|
-
n1.del # Deletes the node
|
|
286
|
-
n1.exist? # returns true/false if node exists in Neo4j
|
|
287
|
-
|
|
288
|
-
n1 = Node.create("age" => 31, "name" => "Max")
|
|
289
|
-
n1[:age] #returns 31 # Get a node property using [:key]
|
|
290
|
-
n1.name #returns "Max" # Get a node property as a method
|
|
291
|
-
n1[:age] = 24 # Set a node property using [:key] =
|
|
292
|
-
n1.name = "Alex" # Set a node property as a method
|
|
293
|
-
n1[:hair] = "black" # Add a node property using [:key] =
|
|
294
|
-
n1.weight = 190 # Add a node property as a method
|
|
295
|
-
n1[:name] = nil # Delete a node property using [:key] = nil
|
|
296
|
-
n1.name = nil # Delete a node property by setting it to nil
|
|
297
|
-
|
|
298
|
-
n2 = Neography::Node.create
|
|
299
|
-
new_rel = Neography::Relationship.create(:family, n1, n2) # Create a relationship from my_node to node2
|
|
300
|
-
new_rel.start_node # Get the start/from node of a relationship
|
|
301
|
-
new_rel.end_node # Get the end/to node of a relationship
|
|
302
|
-
new_rel.other_node(n2) # Get the other node of a relationship
|
|
303
|
-
new_rel.attributes # Get the attributes of the relationship as an array
|
|
304
|
-
|
|
305
|
-
existing_rel = Neography::Relationship.load(12) # Get an existing relationship by id
|
|
306
|
-
existing_rel.del # Delete a relationship
|
|
307
|
-
|
|
308
|
-
Neography::Relationship.create(:friends, n1, n2)
|
|
309
|
-
n1.outgoing(:friends) << n2 # Create outgoing relationship
|
|
310
|
-
n1.incoming(:friends) << n2 # Create incoming relationship
|
|
311
|
-
n1.both(:friends) << n2 # Create both relationships
|
|
312
|
-
|
|
313
|
-
n1.outgoing # Get nodes related by outgoing relationships
|
|
314
|
-
n1.incoming # Get nodes related by incoming relationships
|
|
315
|
-
n1.both # Get nodes related by any relationships
|
|
316
|
-
|
|
317
|
-
n1.outgoing(:friends) # Get nodes related by outgoing friends relationship
|
|
318
|
-
n1.incoming(:friends) # Get nodes related by incoming friends relationship
|
|
319
|
-
n1.both(:friends) # Get nodes related by friends relationship
|
|
320
|
-
|
|
321
|
-
n1.outgoing(:friends).incoming(:enemies) # Get nodes related by one of multiple relationships
|
|
322
|
-
n1.outgoing(:friends).depth(2) # Get nodes related by friends and friends of friends
|
|
323
|
-
n1.outgoing(:friends).depth(:all) # Get nodes related by friends until the end of the graph
|
|
324
|
-
n1.outgoing(:friends).depth(2).include_start_node # Get n1 and nodes related by friends and friends of friends
|
|
325
|
-
|
|
326
|
-
n1.outgoing(:friends).prune("position.endNode().getProperty('name') == 'Tom';")
|
|
327
|
-
n1.outgoing(:friends).filter("position.length() == 2;")
|
|
328
|
-
|
|
329
|
-
n1.rel?(:friends) # Has a friends relationship
|
|
330
|
-
n1.rel?(:outgoing, :friends) # Has outgoing friends relationship
|
|
331
|
-
n1.rel?(:friends, :outgoing) # same, just the other way
|
|
332
|
-
n1.rel?(:outgoing) # Has any outgoing relationships
|
|
333
|
-
n1.rel?(:both) # Has any relationships
|
|
334
|
-
n1.rel?(:all) # same as above
|
|
335
|
-
n1.rel? # same as above
|
|
336
|
-
|
|
337
|
-
n1.rels # Get node relationships
|
|
338
|
-
n1.rels(:friends) # Get friends relationships
|
|
339
|
-
n1.rels(:friends).outgoing # Get outgoing friends relationships
|
|
340
|
-
n1.rels(:friends).incoming # Get incoming friends relationships
|
|
341
|
-
n1.rels(:friends,:work) # Get friends and work relationships
|
|
342
|
-
n1.rels(:friends,:work).outgoing # Get outgoing friends and work relationships
|
|
343
|
-
|
|
344
|
-
n1.all_paths_to(n2).incoming(:friends).depth(4) # Gets all paths of a specified type
|
|
345
|
-
n1.all_simple_paths_to(n2).incoming(:friends).depth(4) # for the relationships defined
|
|
346
|
-
n1.all_shortest_paths_to(n2).incoming(:friends).depth(4) # at a maximum depth
|
|
347
|
-
n1.path_to(n2).incoming(:friends).depth(4) # Same as above, but just one path.
|
|
348
|
-
n1.simple_path_to(n2).incoming(:friends).depth(4)
|
|
349
|
-
n1.shortest_path_to(n2).incoming(:friends).depth(4)
|
|
350
|
-
|
|
351
|
-
n1.shortest_path_to(n2).incoming(:friends).depth(4).rels # Gets just relationships in path
|
|
352
|
-
n1.shortest_path_to(n2).incoming(:friends).depth(4).nodes # Gets just nodes in path
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
See Neo4j API for:
|
|
356
|
-
* {Order}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/graphdb/Traverser.Order.html]
|
|
357
|
-
* {Uniqueness}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/kernel/Uniqueness.html]
|
|
358
|
-
* {Prune Evaluator}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/graphdb/StopEvaluator.html]
|
|
359
|
-
* {Return Filter}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/graphdb/ReturnableEvaluator.html]
|
|
360
|
-
|
|
361
|
-
=== Examples
|
|
362
|
-
|
|
363
|
-
A couple of examples borrowed from Matthew Deiters's Neo4jr-social:
|
|
364
|
-
|
|
365
|
-
* {Facebook}[https://github.com/maxdemarzi/neography/blob/master/examples/facebook.rb]
|
|
366
|
-
* {Linked In}[https://github.com/maxdemarzi/neography/blob/master/examples/linkedin.rb]
|
|
367
|
-
|
|
368
|
-
Phase 2 way of doing these:
|
|
369
|
-
|
|
370
|
-
* {Facebook}[https://github.com/maxdemarzi/neography/blob/master/examples/facebook_v2.rb]
|
|
371
|
-
* {Linked In}[https://github.com/maxdemarzi/neography/blob/master/examples/linkedin_v2.rb]
|
|
372
|
-
|
|
373
|
-
=== Testing
|
|
374
|
-
|
|
375
|
-
To run testing locally you will need to have two instances of the server running. There is some
|
|
376
|
-
good advice on how to set up the a second instance on the
|
|
377
|
-
{neo4j site}[http://docs.neo4j.org/chunked/stable/server-installation.html#_multiple_server_instances_on_one_machine].
|
|
378
|
-
Connect to the second instance in your testing environment, for example:
|
|
379
|
-
|
|
380
|
-
if Rails.env.development?
|
|
381
|
-
@neo = Neography::Rest.new({:port => 7474})
|
|
382
|
-
elsif Rails.env.test?
|
|
383
|
-
@neo = Neography::Rest.new({:port => 7475})
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
Install the test-delete-db-extension plugin, as mentioned in the neo4j.org docs, if you want to use
|
|
387
|
-
the Rest clean_database method to empty your database between tests. In Rspec, for example,
|
|
388
|
-
put this in your spec_helper.rb:
|
|
389
|
-
|
|
390
|
-
config.before(:each) do
|
|
391
|
-
@neo.clean_database("yes_i_really_want_to_clean_the_database")
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
=== To Do
|
|
395
|
-
|
|
396
|
-
* Batch functions
|
|
397
|
-
* Phase 2 Index functionality
|
|
398
|
-
* More Tests
|
|
399
|
-
* More Examples
|
|
400
|
-
* Mixins ?
|
|
401
|
-
|
|
402
|
-
=== Contributing
|
|
403
|
-
|
|
404
|
-
{<img src="https://secure.travis-ci.org/maxdemarzi/neography.png" />}[http://travis-ci.org/maxdemarzi/neography]
|
|
405
|
-
|
|
406
|
-
Please create a {new issue}[https://github.com/maxdemarzi/neography/issues] if you run into any bugs.
|
|
407
|
-
Contribute patches via pull requests.
|
|
408
|
-
|
|
409
|
-
=== Help
|
|
410
|
-
|
|
411
|
-
If you are just starting out, or need help send me an e-mail at maxdemarzi@gmail.com.
|
|
412
|
-
Check you my blog at http://maxdemarzi.com where I have more Neography examples.
|
|
413
|
-
|
|
414
|
-
=== Licenses
|
|
415
|
-
|
|
416
|
-
* Neography - MIT, see the LICENSE file http://github.com/maxdemarzi/neography/tree/master/LICENSE.
|
|
417
|
-
* Lucene - Apache, see http://lucene.apache.org/java/docs/features.html
|
|
418
|
-
* Neo4j - Dual free software/commercial license, see http://neo4j.org
|
|
419
|
-
|
|
420
|
-
|