neo4jr-simple 0.1.7 → 0.1.8

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 CHANGED
@@ -38,6 +38,15 @@ Retrieve a Node:
38
38
  node = neo.getNodeById(1234)
39
39
  end
40
40
 
41
+ Find a Node by some value you control:
42
+
43
+ Neo4jr::DB.execute do |neo|
44
+ # If you add a property 'identifier' to a node, the value can be used to retrieve the node by
45
+ # This can by an id or string but the value must be unique to this node
46
+ # e.g. node[:identifier] = user.id
47
+ node = neo.find_node_by_identifier(user.id)
48
+ end
49
+
41
50
  Traverse Database from a node:
42
51
 
43
52
  Neo4jr::DB.execute do |neo|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/lib/neo4jr-simple.rb CHANGED
@@ -3,24 +3,32 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
3
3
  include Java
4
4
 
5
5
  module Neo4jr
6
- require 'jars/shell-1.0-b10.jar'
7
- require 'jars/neo-1.0-b10.jar'
8
- require 'jars/jta-1.1.jar'
9
- require 'jars/graph-algo-0.2-20090815.182816-1.jar'
6
+
7
+ require 'jars/neo4j-kernel-1.0-rc.jar'
8
+ require 'jars/lucene-core-2.9.1.jar'
9
+ require 'jars/neo4j-index-1.0-b1.jar'
10
+ require 'jars/geronimo-jta_1.1_spec-1.1.1.jar'
11
+ require 'jars/jline-0.9.94.jar'
12
+ require 'jars/neo4j-commons-0.4.jar'
13
+ require 'jars/neo4j-remote-graphdb-0.5.jar'
14
+ require 'jars/neo4j-graph-algo-0.3-20100125.090624-8.jar'
10
15
 
11
16
  java_import java.lang.System
12
- java_import org.neo4j.api.core.EmbeddedNeo
17
+ java_import org.neo4j.kernel.EmbeddedGraphDatabase
18
+ java_import org.neo4j.graphdb.DynamicRelationshipType
19
+ java_import org.neo4j.graphdb.Traverser
20
+ java_import org.neo4j.index.lucene.LuceneIndexService
13
21
  java_import org.neo4j.graphalgo.AllSimplePaths
14
22
  java_import org.neo4j.graphalgo.shortestpath.Dijkstra
15
23
  java_import org.neo4j.graphalgo.shortestpath.CostEvaluator
16
24
  java_import org.neo4j.graphalgo.shortestpath.std.IntegerEvaluator
17
25
  java_import org.neo4j.graphalgo.shortestpath.std.DoubleAdder
18
26
  java_import org.neo4j.graphalgo.shortestpath.std.DoubleComparator
19
- java_import org.neo4j.api.core.DynamicRelationshipType
20
27
  end
21
28
 
22
29
  require 'neo4jr/configuration'
23
30
  require 'neo4jr/db'
31
+ require 'neo4jr/indexer'
24
32
  require 'neo4jr/relationship_type'
25
33
  require 'neo4jr/embedded_neo_extension'
26
34
  require 'neo4jr/node_extension'
@@ -33,4 +41,5 @@ require 'neo4jr/stop_evaluator'
33
41
  require 'neo4jr/simple_cost_evaluator'
34
42
  require 'neo4jr/order'
35
43
  require 'neo4jr/direction'
44
+ require 'neo4jr/path_rater'
36
45
  require 'neo4jr/cli'
data/lib/neo4jr/db.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  module Neo4jr
2
2
  class DB
3
+
3
4
  class << self
4
5
  def instance
5
6
  @neo ||= begin
6
- neo = EmbeddedNeo.new(Configuration.database_path)
7
+ neo = EmbeddedGraphDatabase.new(Configuration.database_path)
7
8
  at_exit do
8
9
  neo.shutdown
9
10
  end
11
+ Neo4jr::Indexer.use neo
10
12
  neo
11
13
  end
12
14
  end
@@ -34,7 +36,7 @@ module Neo4jr
34
36
  end
35
37
 
36
38
  def node_count
37
- instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.api.core.Node.java_class)
39
+ instance.getConfig().getNeoModule().getNodeManager().getNumberOfIdsInUse(org.neo4j.graphdb.Node.java_class)
38
40
  end
39
41
 
40
42
  def stats
@@ -1,8 +1,8 @@
1
1
  module Neo4jr
2
2
  module Direction
3
- OUTGOING = org.neo4j.api.core.Direction::OUTGOING
4
- INCOMING = org.neo4j.api.core.Direction::INCOMING
5
- BOTH = org.neo4j.api.core.Direction::BOTH
3
+ OUTGOING = org.neo4j.graphdb.Direction::OUTGOING
4
+ INCOMING = org.neo4j.graphdb.Direction::INCOMING
5
+ BOTH = org.neo4j.graphdb.Direction::BOTH
6
6
 
7
7
  def self.from_string(value)
8
8
  case value.upcase
@@ -1,4 +1,4 @@
1
- org.neo4j.api.core.EmbeddedNeo.java_class.ruby_class.class_eval do
1
+ org.neo4j.kernel.EmbeddedGraphDatabase.java_class.ruby_class.class_eval do
2
2
 
3
3
  alias :orginalGetNodeById :getNodeById
4
4
  def getNodeById(id)
@@ -12,6 +12,9 @@ org.neo4j.api.core.EmbeddedNeo.java_class.ruby_class.class_eval do
12
12
  node
13
13
  end
14
14
  alias :create_node :createNode
15
-
16
-
15
+
16
+ def find_node_by_identifier(identifier_value)
17
+ Neo4jr::Indexer.find_node_by_identifier(identifier_value)
18
+ end
19
+
17
20
  end
@@ -0,0 +1,37 @@
1
+ module Neo4jr
2
+ class Indexer
3
+ RESERVED_IDENTIFIER_KEY = 'identifier'
4
+
5
+ class << self
6
+ def use(service)
7
+ @indexer = LuceneIndexService.new(service)
8
+ end
9
+
10
+ def enabled?
11
+ !@indexer.nil?
12
+ end
13
+
14
+ def attempt_index(node, property_name, value)
15
+ @indexer.index(node, RESERVED_IDENTIFIER_KEY, value.to_s) if property_name == RESERVED_IDENTIFIER_KEY
16
+ end
17
+
18
+ def find_node_by_identifier(identifier_value)
19
+ hits = @indexer.getNodes(RESERVED_IDENTIFIER_KEY, identifier_value)
20
+ nodes = hits.iterator
21
+ results = []
22
+ results << nodes.next while nodes.hasNext
23
+ if results.size > 1
24
+ results.sort!{|a, b| a.getId <=> b.getId}
25
+ results.each_with_index{|node, index| @indexer.removeIndex(node, RESERVED_IDENTIFIER_KEY, identifier_value) if index < results.size}
26
+ end
27
+ results.last
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ # begin
34
+ #
35
+ # node = nodes.next
36
+ # end while(nodes.hasNext)
37
+ # return node
@@ -1,7 +1,8 @@
1
- org.neo4j.impl.core.IntArrayIterator.java_class.ruby_class.class_eval do
2
-
3
- def hashify_objects
4
- map{|object| object.to_hash }
5
- end
6
-
7
- end
1
+ # org.neo4j.impl.core.IntArrayIterator.java_class.ruby_class.class_eval do
2
+ # org.neo4j.graphdb.IntArrayIterator.java_class.ruby_class.class_eval do
3
+ #
4
+ # def hashify_objects
5
+ # map{|object| object.to_hash }
6
+ # end
7
+ #
8
+ # end
@@ -1,4 +1,4 @@
1
- org.neo4j.api.core.Node.java_class.ruby_class.class_eval do
1
+ org.neo4j.graphdb.Node.java_class.ruby_class.class_eval do
2
2
 
3
3
  def id
4
4
  getId
data/lib/neo4jr/order.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Neo4jr
2
2
  # SEE: http://api.neo4j.org/current/org/neo4j/api/core/Traverser.Order.html
3
3
  class Order
4
- BREADTH_FIRST = org.neo4j.api.core.Traverser::Order::BREADTH_FIRST
5
- DEPTH_FIRST = org.neo4j.api.core.Traverser::Order::DEPTH_FIRST
4
+ BREADTH_FIRST = org.neo4j.graphdb.Traverser::Order::BREADTH_FIRST
5
+ DEPTH_FIRST = org.neo4j.graphdb.Traverser::Order::DEPTH_FIRST
6
6
  end
7
7
  end
@@ -0,0 +1,13 @@
1
+ module Neo4jr
2
+ module PathRater
3
+ def get_cost path, start_cost, cost_evaluator, cost_accumulator
4
+ cost = start_cost
5
+ previous = nil
6
+ path.each do |r|
7
+ cost = cost_accumulator.addCosts(cost, cost_evaluator.getCost(r, r.getEndNode == previous)) if r.kind_of? org.neo4j.api.core.Relationship
8
+ previous = r
9
+ end
10
+ cost
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  # Extends the Node class with a hash style accessor methods to the node's properties
2
- org.neo4j.api.core.PropertyContainer.java_class.ruby_class.class_eval do
2
+ org.neo4j.graphdb.PropertyContainer.java_class.ruby_class.class_eval do
3
3
 
4
4
  # Example:
5
5
  # node[:name] #=> 'Matt'
@@ -12,6 +12,7 @@ org.neo4j.api.core.PropertyContainer.java_class.ruby_class.class_eval do
12
12
  # node[:name] = 'Matt'
13
13
  #
14
14
  def []=(arg, value)
15
+ Neo4jr::Indexer.attempt_index(self, arg.to_s, value)
15
16
  set_property(arg.to_s, value)
16
17
  end
17
18
 
@@ -1,4 +1,4 @@
1
- org.neo4j.api.core.Relationship.java_class.ruby_class.class_eval do
1
+ org.neo4j.graphdb.Relationship.java_class.ruby_class.class_eval do
2
2
 
3
3
  def to_hash
4
4
  properties
@@ -1,6 +1,6 @@
1
1
  module Neo4jr
2
2
  class RelationshipType
3
- include org.neo4j.api.core.RelationshipType
3
+ include org.neo4j.graphdb.RelationshipType
4
4
 
5
5
  @@names = {}
6
6
 
@@ -11,7 +11,7 @@ module Neo4jr
11
11
  end
12
12
 
13
13
  def instances(*names)
14
- names.map{|name| instance(name)}.to_java(org.neo4j.api.core.RelationshipType)
14
+ names.map{|name| instance(name)}.to_java(org.neo4j.graphdb.RelationshipType)
15
15
  end
16
16
 
17
17
  def outgoing(type)
@@ -39,7 +39,7 @@ module Neo4jr
39
39
  end
40
40
 
41
41
  def to_a
42
- [self].to_java(org.neo4j.api.core.RelationshipType)
42
+ [self].to_java(org.neo4j.graphdb.RelationshipType)
43
43
  end
44
44
 
45
45
  def name
@@ -1,8 +1,8 @@
1
1
  module Neo4jr
2
2
  # SEE: http://api.neo4j.org/current/org/neo4j/api/core/ReturnableEvaluator.html
3
3
  class ReturnableEvaluator
4
- ALL = org.neo4j.api.core.ReturnableEvaluator.ALL
5
- ALL_BUT_START_NODE = org.neo4j.api.core.ReturnableEvaluator.ALL_BUT_START_NODE
4
+ ALL = org.neo4j.graphdb.ReturnableEvaluator.ALL
5
+ ALL_BUT_START_NODE = org.neo4j.graphdb.ReturnableEvaluator.ALL_BUT_START_NODE
6
6
 
7
7
  # Creates a new ReturnableEvaluator on the fly that delgates to the passed in block to use with the traverse method.
8
8
  # The block should return either true or false
@@ -1,9 +1,9 @@
1
1
  module Neo4jr
2
2
  # SEE: http://api.neo4j.org/current/org/neo4j/api/core/StopEvaluator.html
3
3
  class StopEvaluator
4
- DEPTH_ONE = org.neo4j.api.core.StopEvaluator::DEPTH_ONE
5
- END_OF_GRAPH = org.neo4j.api.core.StopEvaluator::END_OF_GRAPH
6
- END_OF_NETWORK = org.neo4j.api.core.StopEvaluator::END_OF_NETWORK
4
+ DEPTH_ONE = org.neo4j.graphdb.StopEvaluator::DEPTH_ONE
5
+ END_OF_GRAPH = org.neo4j.graphdb.StopEvaluator::END_OF_GRAPH
6
+ END_OF_NETWORK = org.neo4j.graphdb.StopEvaluator::END_OF_NETWORK
7
7
 
8
8
  # Creates a new StopEvaluator on the fly that delgates to the passed in block to use with the traverse method.
9
9
  # The block should return either true or false
@@ -1,4 +1,4 @@
1
- org.neo4j.api.core.Traverser.java_class.ruby_class.class_eval do
1
+ org.neo4j.graphdb.Traverser.java_class.ruby_class.class_eval do
2
2
  def size
3
3
  self.map.size
4
4
  end
data/spec/db_spec.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe Neo4jr::DB do
4
+
4
5
  it 'should fail the transaction if an error happens and then propgate the original exception' do
5
6
  lambda{
6
7
  Neo4jr::DB.execute do |neo|
@@ -8,4 +9,18 @@ describe Neo4jr::DB do
8
9
  end
9
10
  }.should raise_error(SystemCallError)
10
11
  end
12
+
13
+ it 'should retreive nodes by string' do
14
+ lambda{
15
+ Neo4jr::DB.getNodeById("0")
16
+ }.should_not raise_error
17
+ end
18
+
19
+ it 'accepts a hash when creating a node' do
20
+ node_created = Neo4jr::DB.execute do |embedded_neo|
21
+ embedded_neo.create_node(:a => 'b')
22
+ end
23
+ node_created[:a].should == 'b'
24
+ end
25
+
11
26
  end
@@ -0,0 +1,36 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Neo4jr::Indexer do
4
+
5
+ it 'is always created when we just access a neo4j database' do
6
+ Neo4jr::DB.instance
7
+ Neo4jr::Indexer.should be_enabled
8
+ end
9
+
10
+ it 'indexes and finds nodes using the indentifier' do
11
+ random_identifier = Object.new.object_id
12
+
13
+ node_created = Neo4jr::DB.execute do |neo|
14
+ neo.createNode(:identifier => random_identifier)
15
+ end
16
+
17
+ node_found = Neo4jr::DB.execute do |neo|
18
+ neo.find_node_by_identifier(random_identifier)
19
+ end
20
+
21
+ node_found.id.should == node_created.id
22
+ end
23
+
24
+ it 'only allows one object to be indexed by indentifier' do
25
+ first_node = nil
26
+ last_node = nil
27
+ node_found = Neo4jr::DB.execute do |neo|
28
+ first_node = neo.createNode(:identifier => 'asdf')
29
+ last_node = neo.createNode(:identifier => 'asdf')
30
+ last_node = neo.createNode(:identifier => 'asdf')
31
+ neo.find_node_by_identifier('asdf')
32
+ end
33
+ last_node.id.should == node_found.id
34
+ end
35
+
36
+ end
@@ -15,7 +15,7 @@ describe Neo4jr::RelationshipType do
15
15
 
16
16
  it 'can covert one relationship type to a java array so it can be used with the neo4j API' do
17
17
  relationship_type = Neo4jr::RelationshipType.instance('worked_in')
18
- relationship_type.to_a.class.java_class.to_s.should == '[Lorg.neo4j.api.core.RelationshipType;'
18
+ relationship_type.to_a.class.java_class.to_s.should == '[Lorg.neo4j.graphdb.RelationshipType;'
19
19
  end
20
20
 
21
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4jr-simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
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: neosh
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -44,19 +44,26 @@ extra_rdoc_files:
44
44
  files:
45
45
  - VERSION
46
46
  - bin/neosh
47
- - lib/jars/graph-algo-0.2-20090815.182816-1.jar
48
- - lib/jars/jta-1.1.jar
49
- - lib/jars/neo-1.0-b10.jar
50
- - lib/jars/shell-1.0-b10.jar
47
+ - lib/jars/geronimo-jta_1.1_spec-1.1.1.jar
48
+ - lib/jars/jline-0.9.94.jar
49
+ - lib/jars/lucene-core-2.9.1.jar
50
+ - lib/jars/neo4j-commons-0.4.jar
51
+ - lib/jars/neo4j-graph-algo-0.3-20100125.090624-8.jar
52
+ - lib/jars/neo4j-index-1.0-b1.jar
53
+ - lib/jars/neo4j-kernel-1.0-rc.jar
54
+ - lib/jars/neo4j-remote-graphdb-0.5.jar
55
+ - lib/jars/neo4j-shell-1.0-rc.jar
51
56
  - lib/neo4jr-simple.rb
52
57
  - lib/neo4jr/cli.rb
53
58
  - lib/neo4jr/configuration.rb
54
59
  - lib/neo4jr/db.rb
55
60
  - lib/neo4jr/direction.rb
56
61
  - lib/neo4jr/embedded_neo_extension.rb
62
+ - lib/neo4jr/indexer.rb
57
63
  - lib/neo4jr/int_array_iterator_extension.rb
58
64
  - lib/neo4jr/node_extension.rb
59
65
  - lib/neo4jr/order.rb
66
+ - lib/neo4jr/path_rater.rb
60
67
  - lib/neo4jr/property_container_extension.rb
61
68
  - lib/neo4jr/relationship_extension.rb
62
69
  - lib/neo4jr/relationship_type.rb
@@ -98,8 +105,8 @@ test_files:
98
105
  - VERSION
99
106
  - spec/db_spec.rb
100
107
  - spec/direction_spec.rb
101
- - spec/embedded_neo_extension_spec.rb
102
108
  - spec/functional_example_spec.rb
109
+ - spec/indexer_spec.rb
103
110
  - spec/int_array_iterator_extension_spec.rb
104
111
  - spec/node_extension_spec.rb
105
112
  - spec/property_container_extension_spec.rb
data/lib/jars/jta-1.1.jar DELETED
Binary file
Binary file
Binary file
@@ -1,18 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe Neo4jr::EmbeddedNeo do
4
-
5
- it 'should retreive nodes by string' do
6
- lambda{
7
- Neo4jr::DB.getNodeById("0")
8
- }.should_not raise_error
9
- end
10
-
11
- it 'accepts a hash when creating a node' do
12
- node_created = Neo4jr::DB.execute do |embedded_neo|
13
- embedded_neo.create_node(:a => 'b')
14
- end
15
- node_created[:a].should == 'b'
16
- end
17
-
18
- end