neography-calamitates 1.2.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. data/.gitignore +15 -0
  2. data/.project +12 -0
  3. data/.travis.yml +4 -0
  4. data/CONTRIBUTORS +18 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +19 -0
  7. data/README.md +261 -0
  8. data/Rakefile +14 -0
  9. data/examples/facebook.rb +40 -0
  10. data/examples/facebook_v2.rb +25 -0
  11. data/examples/greatest.rb +43 -0
  12. data/examples/linkedin.rb +39 -0
  13. data/examples/linkedin_v2.rb +22 -0
  14. data/examples/traversal_example1.rb +65 -0
  15. data/examples/traversal_example2.rb +54 -0
  16. data/lib/neography.rb +45 -0
  17. data/lib/neography/config.rb +52 -0
  18. data/lib/neography/connection.rb +203 -0
  19. data/lib/neography/equal.rb +21 -0
  20. data/lib/neography/errors.rb +45 -0
  21. data/lib/neography/index.rb +52 -0
  22. data/lib/neography/multi_json_parser.rb +28 -0
  23. data/lib/neography/neography.rb +10 -0
  24. data/lib/neography/node.rb +53 -0
  25. data/lib/neography/node_path.rb +29 -0
  26. data/lib/neography/node_relationship.rb +37 -0
  27. data/lib/neography/node_traverser.rb +146 -0
  28. data/lib/neography/path_traverser.rb +100 -0
  29. data/lib/neography/property.rb +61 -0
  30. data/lib/neography/property_container.rb +29 -0
  31. data/lib/neography/railtie.rb +19 -0
  32. data/lib/neography/relationship.rb +70 -0
  33. data/lib/neography/relationship_traverser.rb +80 -0
  34. data/lib/neography/rest.rb +470 -0
  35. data/lib/neography/rest/auto_indexes.rb +64 -0
  36. data/lib/neography/rest/batch.rb +277 -0
  37. data/lib/neography/rest/clean.rb +19 -0
  38. data/lib/neography/rest/cypher.rb +33 -0
  39. data/lib/neography/rest/extensions.rb +25 -0
  40. data/lib/neography/rest/gremlin.rb +24 -0
  41. data/lib/neography/rest/helpers.rb +38 -0
  42. data/lib/neography/rest/indexes.rb +100 -0
  43. data/lib/neography/rest/node_auto_indexes.rb +14 -0
  44. data/lib/neography/rest/node_indexes.rb +50 -0
  45. data/lib/neography/rest/node_labels.rb +60 -0
  46. data/lib/neography/rest/node_paths.rb +57 -0
  47. data/lib/neography/rest/node_properties.rb +11 -0
  48. data/lib/neography/rest/node_relationships.rb +42 -0
  49. data/lib/neography/rest/node_traversal.rb +81 -0
  50. data/lib/neography/rest/nodes.rb +102 -0
  51. data/lib/neography/rest/other_node_relationships.rb +48 -0
  52. data/lib/neography/rest/paths.rb +36 -0
  53. data/lib/neography/rest/properties.rb +56 -0
  54. data/lib/neography/rest/relationship_auto_indexes.rb +14 -0
  55. data/lib/neography/rest/relationship_indexes.rb +35 -0
  56. data/lib/neography/rest/relationship_properties.rb +11 -0
  57. data/lib/neography/rest/relationship_types.rb +18 -0
  58. data/lib/neography/rest/relationships.rb +23 -0
  59. data/lib/neography/rest/schema_indexes.rb +34 -0
  60. data/lib/neography/rest/transactions.rb +102 -0
  61. data/lib/neography/tasks.rb +158 -0
  62. data/lib/neography/version.rb +3 -0
  63. data/neography.gemspec +32 -0
  64. data/spec/integration/authorization_spec.rb +48 -0
  65. data/spec/integration/index_spec.rb +70 -0
  66. data/spec/integration/neography_spec.rb +10 -0
  67. data/spec/integration/node_encoding_spec.rb +71 -0
  68. data/spec/integration/node_path_spec.rb +222 -0
  69. data/spec/integration/node_relationship_spec.rb +381 -0
  70. data/spec/integration/node_spec.rb +251 -0
  71. data/spec/integration/parsing_spec.rb +13 -0
  72. data/spec/integration/performance_spec.rb +17 -0
  73. data/spec/integration/relationship_spec.rb +37 -0
  74. data/spec/integration/rest_batch_spec.rb +512 -0
  75. data/spec/integration/rest_batch_streaming_spec.rb +32 -0
  76. data/spec/integration/rest_bulk_spec.rb +106 -0
  77. data/spec/integration/rest_experimental_spec.rb +22 -0
  78. data/spec/integration/rest_gremlin_fail_spec.rb +46 -0
  79. data/spec/integration/rest_header_spec.rb +14 -0
  80. data/spec/integration/rest_index_spec.rb +468 -0
  81. data/spec/integration/rest_labels_spec.rb +128 -0
  82. data/spec/integration/rest_node_spec.rb +274 -0
  83. data/spec/integration/rest_other_node_relationship_spec.rb +137 -0
  84. data/spec/integration/rest_path_spec.rb +231 -0
  85. data/spec/integration/rest_plugin_spec.rb +177 -0
  86. data/spec/integration/rest_relationship_spec.rb +354 -0
  87. data/spec/integration/rest_relationship_types_spec.rb +18 -0
  88. data/spec/integration/rest_schema_index_spec.rb +32 -0
  89. data/spec/integration/rest_transaction_spec.rb +166 -0
  90. data/spec/integration/rest_traverse_spec.rb +149 -0
  91. data/spec/matchers.rb +33 -0
  92. data/spec/neography_spec.rb +23 -0
  93. data/spec/spec_helper.rb +45 -0
  94. data/spec/unit/config_spec.rb +46 -0
  95. data/spec/unit/connection_spec.rb +211 -0
  96. data/spec/unit/node_spec.rb +100 -0
  97. data/spec/unit/properties_spec.rb +140 -0
  98. data/spec/unit/relationship_spec.rb +118 -0
  99. data/spec/unit/rest/batch_spec.rb +243 -0
  100. data/spec/unit/rest/clean_spec.rb +17 -0
  101. data/spec/unit/rest/cypher_spec.rb +21 -0
  102. data/spec/unit/rest/extensions_spec.rb +29 -0
  103. data/spec/unit/rest/gremlin_spec.rb +26 -0
  104. data/spec/unit/rest/labels_spec.rb +73 -0
  105. data/spec/unit/rest/node_auto_indexes_spec.rb +67 -0
  106. data/spec/unit/rest/node_indexes_spec.rb +141 -0
  107. data/spec/unit/rest/node_paths_spec.rb +80 -0
  108. data/spec/unit/rest/node_properties_spec.rb +80 -0
  109. data/spec/unit/rest/node_relationships_spec.rb +78 -0
  110. data/spec/unit/rest/node_traversal_spec.rb +128 -0
  111. data/spec/unit/rest/nodes_spec.rb +188 -0
  112. data/spec/unit/rest/paths_spec.rb +69 -0
  113. data/spec/unit/rest/relationship_auto_indexes_spec.rb +67 -0
  114. data/spec/unit/rest/relationship_indexes_spec.rb +132 -0
  115. data/spec/unit/rest/relationship_properties_spec.rb +80 -0
  116. data/spec/unit/rest/relationship_types_spec.rb +16 -0
  117. data/spec/unit/rest/relationships_spec.rb +22 -0
  118. data/spec/unit/rest/schema_index_spec.rb +31 -0
  119. data/spec/unit/rest/transactions_spec.rb +44 -0
  120. metadata +372 -0
@@ -0,0 +1,15 @@
1
+ coverage
2
+ .DS_Store
3
+ TAGS
4
+ *.rbc
5
+ Gemfile.lock
6
+ .idea
7
+ *.iml
8
+ neo4j
9
+ pkg/*
10
+ *.gem
11
+ .bundle
12
+ log/*
13
+ .rvmrc
14
+ Gemfile.lock
15
+ *.swp
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>neography</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ <nature>com.aptana.ruby.core.rubynature</nature>
11
+ </natures>
12
+ </projectDescription>
@@ -0,0 +1,4 @@
1
+ script: "bundle exec rake neo4j:install['enterprise','2.0.0-M06'] neo4j:start spec --trace"
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3
@@ -0,0 +1,18 @@
1
+ Maintainer:
2
+ Max De Marzi <maxdemarzi at gmail dot com>
3
+
4
+ Contributors:
5
+ * Peter Neubauer
6
+ * Ian Dees
7
+ * Phuong CAO
8
+ * Carlo Alberto Degli Atti
9
+ * Stephen Becker IV
10
+ * Thomas Baum
11
+ * Maximilian Schulz
12
+ * Hesham Amiri
13
+ * Pablo Fernandez
14
+ * Nick Reavill
15
+ * Marcel Sherf
16
+ * David Pitman
17
+ * Garrett Heaver
18
+ * Roel van Dijk
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in neography.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Max De Marzi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,261 @@
1
+ Neography
2
+ =========
3
+
4
+ - [![Gem Version](https://badge.fury.io/rb/neography.png)](https://rubygems.org/gems/neography)
5
+ - [![Build Status](https://secure.travis-ci.org/maxdemarzi/neography.png?branch=master)](http://travis-ci.org/maxdemarzi/neography)
6
+ - [![Code Climate](https://codeclimate.com/github/maxdemarzi/neography.png)](https://codeclimate.com/github/maxdemarzi/neography)
7
+ - [![Coverage Status](https://coveralls.io/repos/maxdemarzi/neography/badge.png?branch=master)](https://coveralls.io/r/maxdemarzi/neography)
8
+
9
+ ## Welcome to Neography
10
+
11
+ Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:
12
+
13
+ * [Getting Started with Neo4j Server](http://neo4j.org/community/)
14
+ * [Neo4j Rest API Reference](http://docs.neo4j.org/chunked/milestone/rest-api.html)
15
+
16
+ If you want to utilize 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
17
+
18
+
19
+ ## Installation
20
+
21
+ ### Gemfile
22
+
23
+ Add `neography` to your Gemfile:
24
+
25
+ ```ruby
26
+ gem 'neography'
27
+ ```
28
+
29
+ And run Bundler:
30
+
31
+ ```sh
32
+ $ bundle
33
+ ```
34
+
35
+ ### Manually:
36
+
37
+ Or install `neography` manually:
38
+
39
+ ```sh
40
+ $ gem install 'neography'
41
+ ```
42
+
43
+ And require the gem in your Ruby code:
44
+
45
+ ```ruby
46
+ require 'rubygems'
47
+ require 'neography'
48
+ ```
49
+
50
+ Read the wiki for information about [dependencies](https://github.com/maxdemarzi/neography/wiki/Dependencies).
51
+
52
+ [Rake tasks](https://github.com/maxdemarzi/neography/wiki/Rake-tasks) are available for downloading, installing and running Neo4j.
53
+
54
+
55
+ ## Usage
56
+
57
+ ### Configuration and initialization
58
+
59
+ Configure Neography as follows:
60
+
61
+ ```ruby
62
+ # these are the default values:
63
+ Neography.configure do |config|
64
+ config.protocol = "http://"
65
+ config.server = "localhost"
66
+ config.port = 7474
67
+ config.directory = "" # prefix this path with '/'
68
+ config.cypher_path = "/cypher"
69
+ config.gremlin_path = "/ext/GremlinPlugin/graphdb/execute_script"
70
+ config.log_file = "neography.log"
71
+ config.log_enabled = false
72
+ config.max_threads = 20
73
+ config.authentication = nil # 'basic' or 'digest'
74
+ config.username = nil
75
+ config.password = nil
76
+ config.parser = MultiJsonParser
77
+ end
78
+ ```
79
+
80
+ Then initialize a `Rest` instance:
81
+
82
+ ```ruby
83
+ @neo = Neography::Rest.new
84
+ ```
85
+
86
+ For overriding these default and other initialization methods, see the
87
+ [configuration and initialization](https://github.com/maxdemarzi/neography/wiki/Configuration-and-initialization) page in the Wiki.
88
+
89
+
90
+ ### REST API
91
+
92
+ Neography supports the creation and retrieval of nodes and relationships through the Neo4j REST interface.
93
+ It supports indexes, Gremlin scripts, Cypher queries and batch operations.
94
+
95
+ Some of this functionality is shown here, but all of it is explained in the following Wiki pages:
96
+
97
+ 2.0 Only features:
98
+
99
+ * [Schema indexes](https://github.com/maxdemarzi/neography/wiki/Schema-indexes) - Create, get and delete schema indexes.
100
+ * [Node labels](https://github.com/maxdemarzi/neography/wiki/Node-labels) - Create, get and delete node labels.
101
+ * [Transactions](https://github.com/maxdemarzi/neography/wiki/Transactions) - Begin, add to, commit, rollback transactions.
102
+
103
+ 1.8+ features:
104
+
105
+ * [Nodes](https://github.com/maxdemarzi/neography/wiki/Nodes) - Create, get and delete nodes.
106
+ * [Node properties](https://github.com/maxdemarzi/neography/wiki/Node-properties) - Set, get and remove node properties.
107
+ * [Node relationships](https://github.com/maxdemarzi/neography/wiki/Node-relationships) - Create and get relationships between nodes.
108
+ * [Relationship](https://github.com/maxdemarzi/neography/wiki/Relationships) - Get and delete relationships.
109
+ * [Relationship properties](https://github.com/maxdemarzi/neography/wiki/Relationship-properties) - Create, get and delete relationship properties.
110
+ * [Relationship types](https://github.com/maxdemarzi/neography/wiki/Relationship-types) - List relationship types.
111
+ * [Node indexes](https://github.com/maxdemarzi/neography/wiki/Node-indexes) - List and create node indexes. Add, remove, get and search nodes in indexes.
112
+ * [Relationship indexes](https://github.com/maxdemarzi/neography/wiki/Relationship-indexes) - List and create relationships indexes. Add, remove, get and search relationships in indexes.
113
+ * [Auto indexes](https://github.com/maxdemarzi/neography/wiki/Auto-indexes) - Get, set and remove auto indexes.
114
+ * [Scripts and queries](https://github.com/maxdemarzi/neography/wiki/Scripts-and-queries) - Run Gremlin scripts and Cypher queries.
115
+ * [Paths and traversal](https://github.com/maxdemarzi/neography/wiki/Paths-and-traversal) - Paths between nodes and path traversal.
116
+ * [Batch](https://github.com/maxdemarzi/neography/wiki/Batch) - Execute multiple calls at once.
117
+ * [Errors](https://github.com/maxdemarzi/neography/wiki/Errors) - Errors raised if REST API calls fail.
118
+
119
+
120
+ Some example usage:
121
+
122
+ ```ruby
123
+ # Node creation:
124
+ node1 = @neo.create_node("age" => 31, "name" => "Max")
125
+ node2 = @neo.create_node("age" => 33, "name" => "Roel")
126
+
127
+ # Node properties:
128
+ @neo.set_node_properties(node1, {"weight" => 200})
129
+
130
+ # Relationships between nodes:
131
+ @neo.create_relationship("coding_buddies", node1, node2)
132
+
133
+ # Get node relationships:
134
+ @neo.get_node_relationships(node2, "in", "coding_buddies")
135
+
136
+ # Use indexes:
137
+ @neo.add_node_to_index("people", "name", "max", node1)
138
+ @neo.get_node_index("people", "name", "max")
139
+
140
+ # Cypher queries:
141
+ @neo.execute_query("start n=node(0) return n")
142
+
143
+ # Batches:
144
+ @neo.batch [:create_node, {"name" => "Max"}],
145
+ [:create_node, {"name" => "Marc"}]
146
+ ```
147
+
148
+ This is just a small sample of the full API, see the [Wiki documentation](https://github.com/maxdemarzi/neography/wiki) for the full API.
149
+
150
+ Neography raises REST API errors as Ruby errors, see the wiki page about [errors](https://github.com/maxdemarzi/neography/wiki/Errors).
151
+ (**Note**: older versions of Neography did not raise any errors!)
152
+
153
+
154
+ ## *Phase 2*
155
+
156
+ Trying to mimic the [Neo4j.rb API](https://github.com/andreasronge/neo4j/wiki/Neo4j%3A%3ACore-Nodes-Properties-Relationships).
157
+
158
+ Now we are returning full objects. The properties of the node or relationship can be accessed directly (`node.name`).
159
+ The Neo4j ID is available by using `node.neo_id`.
160
+
161
+ Some of this functionality is shown here, but all of it is explained in the following Wiki pages:
162
+
163
+ * [Nodes](https://github.com/maxdemarzi/neography/wiki/Phase-2-Nodes) - Create, load and delete nodes.
164
+ * [Node properties](https://github.com/maxdemarzi/neography/wiki/Phase-2-Node-properties) - Add, get and remove node properties.
165
+ * [Node relationships](https://github.com/maxdemarzi/neography/wiki/Phase-2-Node-relationships) - Create and retrieve node relationships.
166
+ * [Node paths](https://github.com/maxdemarzi/neography/wiki/Phase-2-Node-paths) - Gets paths between nodes.
167
+
168
+
169
+ ```ruby
170
+ # create two nodes:
171
+ n1 = Neography::Node.create("age" => 31, "name" => "Max")
172
+ n2 = Neography::Node.create("age" => 33, "name" => "Roel")
173
+
174
+ n1.exist? # => true
175
+
176
+ # get and change some properties:
177
+ n1[:age] # => 31
178
+ n1.name # => "Max"
179
+ n1[:age] = 32 # change property
180
+ n1.weight = 190 # new property
181
+ n1.age = nil # remove property
182
+
183
+ # add a relationship between nodes:
184
+ new_rel = Neography::Relationship.create(:coding_buddies, n1, n2)
185
+
186
+ # remove a relationship:
187
+ new_rel.del
188
+
189
+ # add a relationship on nodes:
190
+ n1.outgoing(:coding_buddies) << n2
191
+
192
+ # more advanced relationship traversal:
193
+ n1.outgoing(:friends) # Get nodes related by outgoing friends relationship
194
+ n1.outgoing(:friends).depth(2).include_start_node # Get n1 and nodes related by friends and friends of friends
195
+
196
+ n1.rel?(:outgoing, :friends) # Has outgoing friends relationship
197
+ n1.rels(:friends,:work).outgoing # Get outgoing friends and work relationships
198
+
199
+ n1.all_paths_to(n2).incoming(:friends).depth(4) # Gets all paths of a specified type
200
+ n1.shortest_path_to(n2).incoming(:friends).depth(4).nodes # Gets just nodes in path
201
+ ```
202
+
203
+ This is just a small sample of the full API, see the [Wiki documentation](https://github.com/maxdemarzi/neography/wiki) for the full API.
204
+
205
+ ## More
206
+
207
+ ### Examples
208
+
209
+ Some [example code](https://github.com/maxdemarzi/neography/wiki/Examples).
210
+
211
+
212
+ ### Testing
213
+
214
+ Some [tips about testing](https://github.com/maxdemarzi/neography/wiki/Testing).
215
+
216
+
217
+ ### Related Neo4j projects
218
+
219
+ Complement to Neography are the:
220
+
221
+ * [Neo4j Active Record Adapter](https://github.com/yournextleap/activerecord-neo4j-adapter) by Nikhil Lanjewar
222
+ * [Neology](https://github.com/lordkada/neology) by Carlo Alberto Degli Atti
223
+ * [Neoid](https://github.com/elado/neoid) by Elad Ossadon
224
+
225
+ An alternative to Neography is [Architect4r](https://github.com/namxam/architect4r) by Maximilian Schulz
226
+
227
+
228
+ ### Neography in the Wild
229
+
230
+ * [Vouched](http://getvouched.com)
231
+ * [Neovigator](http://neovigator.herokuapp.com) fork it at https://github.com/maxdemarzi/neovigator
232
+ * [Neoflix](http://neoflix.herokuapp.com) fork it at https://github.com/maxdemarzi/neoflix
233
+
234
+
235
+ ### Getting started with Neography
236
+
237
+ * [Getting Started with Ruby and Neo4j](http://maxdemarzi.com/2012/01/04/getting-started-with-ruby-and-neo4j/)
238
+ * [Graph visualization with Neo4j](http://maxdemarzi.com/2012/01/11/graph-visualization-and-neo4j/)
239
+ * [Neo4j on Heroku](http://maxdemarzi.com/2012/01/13/neo4j-on-heroku-part-one/)
240
+
241
+
242
+ ## Contributing
243
+
244
+ Please create a [new issue](https://github.com/maxdemarzi/neography/issues) if you run into any bugs.
245
+
246
+ Contribute patches via [pull requests](https://github.com/maxdemarzi/neography/pulls).
247
+
248
+
249
+ ## Help
250
+
251
+ If you are just starting out, or need help send me an e-mail at maxdemarzi@gmail.com.
252
+
253
+ Check you my blog at http://maxdemarzi.com where I have more Neography examples.
254
+
255
+
256
+ ## Licenses
257
+
258
+ * Neography - MIT, see the LICENSE file http://github.com/maxdemarzi/neography/tree/master/LICENSE.
259
+ * Lucene - Apache, see http://lucene.apache.org/java/docs/features.html
260
+ * Neo4j - Dual free software/commercial license, see http://neo4j.org
261
+
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ require 'neography/tasks'
6
+
7
+ RSpec::Core::RakeTask.new(:spec) do |t|
8
+ t.rspec_opts = "--color"
9
+ t.pattern = "spec/**/*_spec.rb"
10
+ end
11
+
12
+ desc "Run Tests"
13
+ task :default => :spec
14
+
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'neography'
3
+
4
+ @neo = Neography::Rest.new
5
+
6
+ def create_person(name)
7
+ @neo.create_node("name" => name)
8
+ end
9
+
10
+ def make_mutual_friends(node1, node2)
11
+ @neo.create_relationship("friends", node1, node2)
12
+ @neo.create_relationship("friends", node2, node1)
13
+ end
14
+
15
+ def suggestions_for(node)
16
+ @neo.traverse(node,"nodes", {"order" => "breadth first",
17
+ "uniqueness" => "node global",
18
+ "relationships" => {"type"=> "friends", "direction" => "in"},
19
+ "return filter" => {
20
+ "language" => "javascript",
21
+ "body" => "position.length() == 2;"},
22
+ "depth" => 2})
23
+ end
24
+
25
+ johnathan = create_person('Johnathan')
26
+ mark = create_person('Mark')
27
+ phill = create_person('Phill')
28
+ mary = create_person('Mary')
29
+ luke = create_person('Luke')
30
+
31
+ make_mutual_friends(johnathan, mark)
32
+ make_mutual_friends(mark, mary)
33
+ make_mutual_friends(mark, phill)
34
+ make_mutual_friends(phill, mary)
35
+ make_mutual_friends(phill, luke)
36
+
37
+ puts "Johnathan should become friends with #{suggestions_for(johnathan).map{|n| n["data"]["name"]}.join(', ')}"
38
+
39
+ # RESULT
40
+ # Johnathan should become friends with Mary, Phill
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ require 'neography'
3
+
4
+ @neo = Neography::Rest.new
5
+
6
+ def suggestions_for(node)
7
+ node.incoming(:friends).order("breadth first").uniqueness("node global").filter("position.length() == 2;").depth(2)
8
+ end
9
+
10
+ johnathan = Neography::Node.create("name" =>'Johnathan')
11
+ mark = Neography::Node.create("name" =>'Mark')
12
+ phill = Neography::Node.create("name" =>'Phill')
13
+ mary = Neography::Node.create("name" =>'Mary')
14
+ luke = Neography::Node.create("name" =>'Luke')
15
+
16
+ johnathan.both(:friends) << mark
17
+ mark.both(:friends) << mary
18
+ mark.both(:friends) << phill
19
+ phill.both(:friends) << mary
20
+ phill.both(:friends) << luke
21
+
22
+ puts "Johnathan should become friends with #{suggestions_for(johnathan).map{|n| n.name }.join(', ')}"
23
+
24
+ # RESULT
25
+ # Johnathan should become friends with Mary, Phill
@@ -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}"