neo4jr-social 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ begin
15
15
  gem.authors = ["Matthew Deiters"]
16
16
  gem.add_development_dependency "rspec", ">= 1.2.9"
17
17
  gem.add_development_dependency "rest-client"
18
- gem.add_dependency 'neo4jr-simple', ">= 0.1.6" unless ENV['neo4jr_simple']
18
+ gem.add_dependency 'neo4jr-simple', "0.2.1" unless ENV['neo4jr_simple']
19
19
  gem.add_dependency 'sinatra'
20
20
  gem.add_dependency 'json_pure'
21
21
  end
data/TODO CHANGED
@@ -1,5 +1,4 @@
1
1
  * Validate requests, check parameters, etc
2
- * Retrieve Node by identifier other then node id
3
2
  * Figure out how to handle the Neo4j nodes classname
4
3
  * More querying potential: Enable solr type parameters with lt gt eq etc or enable gremlin
5
4
  Examples
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/config/warble.rb CHANGED
@@ -5,7 +5,7 @@ Warbler::Config.new do |config|
5
5
 
6
6
  config.gems['sinatra'] = '0.9.4'
7
7
  config.gems['json_pure'] = '1.2.0'
8
- config.gems['neo4jr-simple'] = '0.1.7'
8
+ config.gems['neo4jr-simple'] = '0.2.1'
9
9
 
10
10
  config.gem_dependencies = true
11
11
  config.webxml.booter = :rack
@@ -1,5 +1,6 @@
1
1
  module Neo4jr
2
2
  class Service < Sinatra::Base
3
+ include Neo4jr::PathRater
3
4
  helpers ParamHelper
4
5
  register SelfDocumentor, FormatHandler
5
6
 
@@ -21,7 +22,7 @@ module Neo4jr
21
22
  nodes.to_json
22
23
  end
23
24
 
24
- describe "Creates a new node in the neo4j database. Any parameters based in the body of the POST will be treated as properties for the node and will be stored in the database."
25
+ describe "Creates a new node in the neo4j database. Any parameters based in the body of the POST will be treated as properties for the node and will be stored in the database. The response will be the neo4j node id. Additionally you can add the identifier property which if exsists can be used as the node_id for other requests."
25
26
  post '/nodes' do
26
27
  node = Neo4jr::DB.execute do |neo|
27
28
  node = neo.create_node(params)
@@ -29,17 +30,17 @@ module Neo4jr
29
30
  node.to_hash.to_json
30
31
  end
31
32
 
32
- describe "Returns the properties for the specified node, where :node_id is the numeric id for the node."
33
+ describe "Returns the properties for the specified node, where :node_id is the value of the identifier propery of the node or if no identifier is specified you can use the numeric neo4j id."
33
34
  get '/nodes/:node_id' do
34
35
  node = Neo4jr::DB.execute do |neo|
35
- neo.getNodeById(param_node_id).to_hash.to_json
36
+ neo.find_node(param_node_id).to_hash.to_json
36
37
  end
37
38
  end
38
39
 
39
- describe "Updates the properties of the specified node, where :node_id is the numeric id for the node. Any parameters pased in the body of the PUT will be treated as properties for the node. If you add a new parameters (i.e. age=4) which previously were not on the node, neo4jr-social will still add that property to the node."
40
+ describe "Updates the properties of the specified node, where :node_id is the value of the identifier propery of the node or if no identifier is specified you can use the numeric neo4j id. Any parameters pased in the body of the PUT will be treated as properties for the node. If you add a new parameters (i.e. age=4) which previously were not on the node, neo4jr-social will still add that property to the node."
40
41
  put '/nodes/:node_id' do
41
42
  node = Neo4jr::DB.execute do |neo|
42
- node = neo.getNodeById(param_node_id)
43
+ node = neo.find_node(param_node_id)
43
44
  node.update_properties(params)
44
45
  end
45
46
  node.to_hash.to_json
@@ -48,19 +49,19 @@ module Neo4jr
48
49
  describe "Deletes the specified node, where :node_id is the numeric id for the node."
49
50
  delete '/nodes/:node_id' do
50
51
  Neo4jr::DB.execute do |neo|
51
- node = neo.getNodeById(param_node_id)
52
+ node = neo.find_node(param_node_id)
52
53
  node.get_relationships.each { |r| r.delete }
53
54
  node.delete
54
55
  end
55
56
  end
56
57
 
57
- describe "Creates a relations for the specified node, where :node_id is the numeric id for the node. This is how you designate how two nodes are related to each other."
58
+ describe "Creates a relations for the specified node, where :node_id is the value of the identifier propery of the node or if no identifier is specified you can use the numeric neo4j id. This is how you designate how two nodes are related to each other."
58
59
  required_param :to, 'This is the node id of the node you want to make a relationship to. This is a one-way relationship. If you want both nodes to be.'
59
60
  required_param :type, "this is the type of the relationship, i.e. 'friends'. This can be any string that is sensible in your domain."
60
61
  optional_param "Any other parameters you supply in the body of the POST will be added as properties to the relationship. For example if you were making 'friend' relationships and wanted to add a date since the friendship started you could pass a 'since' parameter in the POST."
61
62
  get '/nodes/:node_id/relationships' do
62
63
  relationships = Neo4jr::DB.execute do |neo|
63
- node = neo.getNodeById(param_node_id)
64
+ node = neo.find_node(param_node_id)
64
65
  if param_relationship_type
65
66
  relationship_type = RelationshipType.instance(param_relationship_type)
66
67
  node.getRelationships(param_relationship_type.to_a).hashify_objects
@@ -71,12 +72,12 @@ module Neo4jr
71
72
  relationships.to_json
72
73
  end
73
74
 
74
- describe "Returns relationships to other nodes for the specified node, where :node_id is the numeric id for the node."
75
+ describe "Returns relationships to other nodes for the specified node, where :node_id is the value of the identifier propery of the node or if no identifier is specified you can use the numeric neo4j id."
75
76
  optional_param :type, "Specify a type if only certain relationships are of interest"
76
77
  post '/nodes/:node_id/relationships' do
77
78
  relationships = Neo4jr::DB.execute do |neo|
78
- node = neo.getNodeById(param_node_id)
79
- to_node = neo.getNodeById(param_to_node_id)
79
+ node = neo.find_node(param_node_id)
80
+ to_node = neo.find_node(param_to_node_id)
80
81
  relationship_type = RelationshipType.instance(param_relationship_type)
81
82
  relationship = node.create_relationship_to to_node, relationship_type
82
83
  relationship.update_properties(params)
@@ -92,8 +93,8 @@ module Neo4jr
92
93
  optional_param :direction, "hat direction of relationships to follow, the default is 'both'"
93
94
  get '/nodes/:node_id/paths' do
94
95
  paths = Neo4jr::DB.execute do |neo|
95
- start_node = neo.getNodeById(param_node_id)
96
- end_node = neo.getNodeById(param_to_node_id)
96
+ start_node = neo.find_node(param_node_id)
97
+ end_node = neo.find_node(param_to_node_id)
97
98
  shortest_path = AllSimplePaths.new(start_node, end_node, param_depth, param_direction, relationship_types)
98
99
  to_hash shortest_path.getPaths
99
100
  end
@@ -107,14 +108,14 @@ module Neo4jr
107
108
  path = Neo4jr::DB.execute do |neo|
108
109
  dijkstra = Dijkstra.new(
109
110
  0.0,
110
- neo.getNodeById(param_node_id),
111
- neo.getNodeById(param_to_node_id),
111
+ neo.find_node(param_node_id),
112
+ neo.find_node(param_to_node_id),
112
113
  Neo4jr::SimpleEvaluator.new,
113
114
  DoubleAdder.new,
114
115
  DoubleComparator.new,
115
116
  direction,
116
117
  relationship_types)
117
- (p=dijkstra.getPath) and p.map{|n| n.to_hash }
118
+ (p=dijkstra.getPath) and {:path => p.map{|n| n.to_hash }, :cost => dijkstra.getCost}
118
119
  end
119
120
  path.to_json
120
121
  end
@@ -125,7 +126,7 @@ module Neo4jr
125
126
  get '/nodes/:node_id/recommendations' do
126
127
  suggestions = Neo4jr::DB.execute do |neo|
127
128
  relationship = Neo4jr::RelationshipType.incoming(param_relationship_type)
128
- start_node = neo.getNodeById(param_node_id)
129
+ start_node = neo.find_node(param_node_id)
129
130
  order = Order::BREADTH_FIRST
130
131
  return_when = Return.when do |current_position|
131
132
  current_position.depth > param_level
@@ -137,6 +138,15 @@ module Neo4jr
137
138
  end
138
139
 
139
140
  private
141
+
142
+ def to_rated_hash path, start_cost=0.0, cost_evaluator=Neo4jr::SimpleEvaluator.new, cost_accumulator=DoubleAdder.new
143
+ {:path => path.map{|n| n.to_hash}, :cost => get_cost(path, start_cost, cost_evaluator, cost_accumulator)}
144
+ end
145
+
146
+ def to_rated_hashes paths, start_cost=0.0, cost_evaluator=Neo4jr::SimpleEvaluator.new, cost_accumulator=DoubleAdder.new
147
+ paths and paths.map{|p| to_rated_hash p, start_cost, cost_evaluator, cost_accumulator}
148
+ end
149
+
140
150
  def to_hash paths
141
151
  paths and paths.map{|p| p.map{|n| n.to_hash }}
142
152
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{neo4jr-social}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matthew Deiters"]
12
- s.date = %q{2010-01-19}
12
+ s.date = %q{2010-01-26}
13
13
  s.default_executable = %q{start-neo4jr-social}
14
14
  s.description = %q{A self-containted lightweight REST interface to Neo4j using JRuby }
15
15
  s.email = %q{matthew_deiters@mckinsey.com}
@@ -77,17 +77,20 @@ Gem::Specification.new do |s|
77
77
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
78
78
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
79
79
  s.add_development_dependency(%q<rest-client>, [">= 0"])
80
+ s.add_runtime_dependency(%q<neo4jr-simple>, ["= 0.2.1"])
80
81
  s.add_runtime_dependency(%q<sinatra>, [">= 0"])
81
82
  s.add_runtime_dependency(%q<json_pure>, [">= 0"])
82
83
  else
83
84
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
84
85
  s.add_dependency(%q<rest-client>, [">= 0"])
86
+ s.add_dependency(%q<neo4jr-simple>, ["= 0.2.1"])
85
87
  s.add_dependency(%q<sinatra>, [">= 0"])
86
88
  s.add_dependency(%q<json_pure>, [">= 0"])
87
89
  end
88
90
  else
89
91
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
90
92
  s.add_dependency(%q<rest-client>, [">= 0"])
93
+ s.add_dependency(%q<neo4jr-simple>, ["= 0.2.1"])
91
94
  s.add_dependency(%q<sinatra>, [">= 0"])
92
95
  s.add_dependency(%q<json_pure>, [">= 0"])
93
96
  end
data/spec/service_spec.rb CHANGED
@@ -97,7 +97,7 @@ describe Neo4jr::Service do
97
97
  @create_mutual_friends.call(hanks, cruise)
98
98
 
99
99
  get "/nodes/#{hoffman['node_id']}/shortest_path?type=friends&to=#{cruise['node_id']}"
100
- path_to_cruise = response_to_ruby
100
+ path_to_cruise = response_to_ruby['path']
101
101
  path_to_cruise[0]['name'].should == 'Philip Seymour Hoffman'
102
102
  path_to_cruise[1]['type'].should == 'friends'
103
103
  path_to_cruise[2]['name'].should == 'Tina Fey'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4jr-social
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Deiters
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-19 00:00:00 -08:00
12
+ date: 2010-01-26 00:00:00 -08:00
13
13
  default_executable: start-neo4jr-social
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -32,6 +32,16 @@ dependencies:
32
32
  - !ruby/object:Gem::Version
33
33
  version: "0"
34
34
  version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: neo4jr-simple
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.2.1
44
+ version:
35
45
  - !ruby/object:Gem::Dependency
36
46
  name: sinatra
37
47
  type: :runtime