Navigation Menu

Skip to content

Commit

Permalink
Fixed RDocs.
Browse files Browse the repository at this point in the history
Neo4j::NodeMixin#props now returns a _neo_id for the node id.
Fixed broken Rest Specs.
Upgraded to GraphAlgo jar file
[#105 state:resolved]
  • Loading branch information
andreas committed Feb 5, 2010
1 parent 7950d54 commit a66330f
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 83 deletions.
8 changes: 4 additions & 4 deletions README.rdoc
Expand Up @@ -51,7 +51,7 @@ This page contains the following information:
* Three Minute Tutorial
* Ten Minute Tutorial
* Neo4j API Documentation
* Extensions: REST (see Neo4j::RestMixin) and find_path
* Extensions: REST (see Neo4j::RestMixin) and find_path (Neo4j::GraphAlgo::AllSimplePaths)
* Performance issues
* Ruby on Rails with Neo4j.rb
* Lucene API Documentation
Expand Down Expand Up @@ -245,9 +245,9 @@ Example:
=== Finding Nodes and Queries

There are three ways of finding/querying nodes in Neo4j:
1. by traversing the graph
2. by using Lucene queries
3. using the unique neo4j id (Neo4j::NodeMixin#neo_id).
1. by traversing the graph
2. by using Lucene queries
3. using the unique neo4j id (Neo4j::NodeMixin#neo_id).

When doing a traversal one starts from a node and traverses one or more relationships (one or more levels deep).
This start node can be either the reference node which is always found (Neo4j#ref_node) or by finding a start
Expand Down
7 changes: 5 additions & 2 deletions Rakefile
Expand Up @@ -57,8 +57,11 @@ Rake::RDocTask.new do |rdoc|
rdoc.options << '--title' << "Neo4j v#{Neo4j::VERSION}" << '--line-numbers' << '--inline-source' << '--main' << 'README.rdoc'
rdoc.options << '--webcvs=http://github.com/andreasronge/neo4j/tree/master/'

rdoc.rdoc_files.include('README.rdoc', 'CHANGELOG', 'lib/**/*.rb')
rdoc.rdoc_files.exclude('lib/neo4j/extensions')
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('CHANGELOG')
rdoc.rdoc_files.include('lib/**/*.rb')
rdoc.rdoc_files.exclude('lib/neo4j/extensions/*.rb')
rdoc.rdoc_files.exclude('lib/neo4j/extensions/aggregate/**/*.rb')
end

desc 'Upload documentation to RubyForge.'
Expand Down
18 changes: 15 additions & 3 deletions lib/neo4j/extensions/graph_algo/all_simple_paths.rb
@@ -1,8 +1,8 @@
module Neo4j::GraphAlgo
require 'neo4j/extensions/graph_algo/graph-algo-0.2-20090815.182816-1.jar'
require 'neo4j/extensions/graph_algo/neo4j-graph-algo-0.3-20100202.170643-12.jar'


class ListOfAlternatingNodesAndRelationships #:nodoc:
class ListOfAlternatingNodesAndRelationships #:nodoc:
include Enumerable

def initialize(list)
Expand Down Expand Up @@ -44,6 +44,18 @@ def each
end
end

# A Wrapper for some of the neo4j graphdb algorithms
#
# Currently only the AllSimplePaths is wrapped in Ruby.
#
# === Usage
#
# found_nodes = GraphAlgo.all_simple_paths.from(node1).both(:knows).to(node7).depth(4).as_nodes
#
# === See also
# * JavaDoc: http://components.neo4j.org/graph-algo/apidocs/org/neo4j/graphalgo/AllSimplePaths.html
# * A complete example: http://github.com/andreasronge/neo4j/tree/master/examples/you_might_know/
#
class AllSimplePaths
include Enumerable

Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/neo4j/extensions/rest/rest.rb
Expand Up @@ -29,7 +29,7 @@ def self.base_uri
end

def self.load_class(clazz)
clazz = clazz.split("::").inject(Kernel) do |container, name|
clazz.split("::").inject(Kernel) do |container, name|
container.const_get(name.to_s)
end
rescue NameError
Expand Down
66 changes: 33 additions & 33 deletions lib/neo4j/extensions/rest/rest_mixin.rb
@@ -1,38 +1,38 @@
module Neo4j

# Creates a number of resources for the class using this mixin.
#
# The following resources are created:
#
# <b>add new class</b>:: <code>POST /neo</code> post ruby code of a neo4j node class
# <b>node classes</b>:: <code>GET /neo</code> - returns hyperlinks to /nodes/classname
# <b>search nodes</b>:: <code>GET /nodes/classname?name=p</code>
# <b>view all nodes</b>:: <code>GET /nodes/classname</code>
# <b>update property</b>:: <code>PUT nodes/classname/id/property_name</code>
# <b>view property</b>:: <code>GET nodes/classname/id/property_name</code>
# <b>delete node</b>:: <code>DELETE nodes/classname/node_id</code>
# <b>update properties</b>:: <code>PUT nodes/classname/node_id</code>
# <b>view node</b>:: <code>GET /nodes/classname/id</code>
# <b>create node</b>:: <code>POST /nodes/classname</code>
# <b>view relationship</b>:: <code>GET /rels/id</code>
# <b>list rels</b>:: <code>GET /nodes/classname/id/relationship-type</code>
# <b>add relationship</b>:: <code>POST /nodes/classname/id/relationship-type</code>
# <b>traversal</b>:: <code>GET nodes/classname/id/traverse?relationship=relationship-type&depth=depth</code>
#
# Also provides lucene queries
# <b>Lucene query string</b>:: <code>/nodes/classname?search=name:hello~</code>
# <b>Exact match on property</b>:: <code>/nodes/classname?name=hello</code>
# <b>Specify sorting order</b>:: <code>/nodes/classname?sort=name,desc</code>
# <b>Pagination (offset,num)</b>:: <code>/nodes/classname?limit=100,20</code>#
#
# When create a new node by posting to <code>/nodes/classname</code> a 201 will be return with the 'Location' header set to the
# URI of the newly created node.
#
# The JSON representation of a node looks like this
#
# {"rels" : {"type1":"http://0.0.0.0:4567/rels/0","type2":"http://0.0.0.0:4567/rels/1"},
# "properties" : {"id":1,"classname":"MyNode"}}
#
# Creates a number of resources for the class using this mixin.
#
# The following resources are created:
#
# <b>add new class</b>:: <code>POST /neo</code> post ruby code of a neo4j node class
# <b>node classes</b>:: <code>GET /neo</code> - returns hyperlinks to /nodes/classname
# <b>search nodes</b>:: <code>GET /nodes/classname?name=p</code>
# <b>view all nodes</b>:: <code>GET /nodes/classname</code>
# <b>update property</b>:: <code>PUT nodes/classname/id/property_name</code>
# <b>view property</b>:: <code>GET nodes/classname/id/property_name</code>
# <b>delete node</b>:: <code>DELETE nodes/classname/node_id</code>
# <b>update properties</b>:: <code>PUT nodes/classname/node_id</code>
# <b>view node</b>:: <code>GET /nodes/classname/id</code>
# <b>create node</b>:: <code>POST /nodes/classname</code>
# <b>view relationship</b>:: <code>GET /rels/id</code>
# <b>list rels</b>:: <code>GET /nodes/classname/id/relationship-type</code>
# <b>add relationship</b>:: <code>POST /nodes/classname/id/relationship-type</code>
# <b>traversal</b>:: <code>GET nodes/classname/id/traverse?relationship=relationship-type&depth=depth</code>
#
# Also provides lucene queries
# <b>Lucene query string</b>:: <code>/nodes/classname?search=name:hello~</code>
# <b>Exact match on property</b>:: <code>/nodes/classname?name=hello</code>
# <b>Specify sorting order</b>:: <code>/nodes/classname?sort=name,desc</code>
# <b>Pagination (offset,num)</b>:: <code>/nodes/classname?limit=100,20</code>#
#
# When create a new node by posting to <code>/nodes/classname</code> a 201 will be return with the 'Location' header set to the
# URI of the newly created node.
#
# The JSON representation of a node looks like this
#
# {"rels" : {"type1":"http://0.0.0.0:4567/rels/0","type2":"http://0.0.0.0:4567/rels/1"},
# "properties" : {"_neo_id":1,"_classname":"MyNode"}}
#
module RestMixin

def _uri
Expand Down
2 changes: 1 addition & 1 deletion lib/neo4j/extensions/rest/server.rb
Expand Up @@ -3,7 +3,7 @@ module Neo4j
module Rest
# todo move inside namepace Rest

class RestServer
class RestServer #:nodoc:
class << self
attr_accessor :thread

Expand Down
9 changes: 7 additions & 2 deletions lib/neo4j/extensions/rest/stubs.rb
@@ -1,5 +1,9 @@
module Neo4j
module Rest
# A stub class that talk to a neo4j rest server.
# It behaves like a Neo4j::Node, but instead of actually performing operation
# it talks to the server over HTTP/JSON
#
module RestStubMixin
attr_accessor :json

Expand Down Expand Up @@ -29,7 +33,7 @@ def props
end
end

module RestHttpMethods
module RestHttpMethods # :nodoc:
class << self
def get_request(resource, args = {})
body = _get_request(resource, args)
Expand Down Expand Up @@ -67,7 +71,7 @@ def _request(resource, method = :get, args = {})
end


class RelationshipStub
class RelationshipStub # :nodoc:
include RestStubMixin

def start_node
Expand Down Expand Up @@ -128,6 +132,7 @@ def each
end
end

# A class that simply includes the RestStubMixin
class NodeStub
include RestStubMixin
end
Expand Down
15 changes: 7 additions & 8 deletions lib/neo4j/mixins/java_property_mixin.rb
Expand Up @@ -81,7 +81,7 @@ def delete_property (name)

# Returns a hash of all properties.
#
# ==== Returns
# === Returns
# Hash:: property key and property value with the '_neo_id' as the neo_id
#
def props
Expand All @@ -98,19 +98,18 @@ def props
# If the option <code>{:strict => true}</code> is given, any properties present on
# the node but not present in the hash will be removed from the node.
#
# ==== Parameters
# struct_or_hash<#each_pair>:: the key and value to be set
# options<Hash>:: further options defining the context of the update
# === Parameters
# struct_or_hash<#each_pair>:: the key and value to be set, should respond to 'each_pair'
# options:: further options defining the context of the update, should be a Hash
#
# ==== Returns
# === Returns
# self
#
# :api: public
def update(struct_or_hash, options={})
strict = options[:strict]
keys_to_delete = props.keys - %w(_neo_id) if strict # TODO can probably simply all this code a lot
keys_to_delete = props.keys - %w(_neo_id _classname) if strict
struct_or_hash.each_pair do |key, value|
next if %w(_neo_id).include? key.to_s # do not allow special properties to be mass assigned
next if %w(_neo_id _classname).include? key.to_s # do not allow special properties to be mass assigned
keys_to_delete.delete(key) if strict
self[key] = value
end
Expand Down
38 changes: 13 additions & 25 deletions test/extensions/graph_algo_spec.rb
Expand Up @@ -2,7 +2,7 @@
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/..")

require 'neo4j'
#require 'neo4j/extensions/graph_algo'
require 'neo4j/extensions/graph_algo'
require 'spec_helper'

include Neo4j
Expand Down Expand Up @@ -37,18 +37,14 @@


it "should contain Enumerable of Enumerable" do
pending "GraphAlgo Java Jar not compatible with Neo4j 1.0 rc yet"

paths = GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n5).depth(2)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n5).depth(2)
paths.size.should == 2
[*paths][0].should be_kind_of Enumerable
[*paths][1].should be_kind_of Enumerable
end

it "should contain Enumerable of Enumerable of alternating Relationship and Nodes" do
pending "GraphAlgo Java Jar not compatible with Neo4j 1.0 rc yet"

paths = GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n5).depth(2)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n5).depth(2)
node = true
node_and_rel_ids = []

Expand All @@ -70,9 +66,7 @@
end

it "should contain Enumerable of Enumerable of only Nodes if as_nodes is given" do
pending "GraphAlgo Java Jar not compatible with Neo4j 1.0 rc yet"

paths = GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n5).depth(2).as_nodes
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n5).depth(2).as_nodes
node_ids = []
[*paths][0].each do | node|
node.should be_kind_of org.neo4j.graphdb.Node
Expand All @@ -82,41 +76,35 @@
end

it "should take a depth parameter" do
pending "GraphAlgo Java Jar not compatible with Neo4j 1.0 rc yet"

paths = GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n6).depth(1)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n6).depth(1)
paths.size.should == 0

paths = GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n6).depth(3)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n6).depth(3)
paths.size.should == 2

paths = GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n6).depth(2)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n6).depth(2)
paths.size.should == 0
end

it "should take a incoming and outgoing parameter" do
pending "GraphAlgo Java Jar not compatible with Neo4j 1.0 rc yet"

paths = GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n6).depth(3)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n1).outgoing(:knows).to(@n6).depth(3)
paths.size.should == 2

paths = GraphAlgo.all_simple_paths.from(@n1).incoming(:knows).to(@n6).depth(3)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n1).incoming(:knows).to(@n6).depth(3)
paths.size.should == 0

paths = GraphAlgo.all_simple_paths.from(@n6).outgoing(:knows).to(@n1).depth(3)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n6).outgoing(:knows).to(@n1).depth(3)
paths.size.should == 0

paths = GraphAlgo.all_simple_paths.from(@n6).incoming(:knows).to(@n1).depth(3)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n6).incoming(:knows).to(@n1).depth(3)
paths.size.should == 2
end

it "should take a both parameter" do
pending "GraphAlgo Java Jar not compatible with Neo4j 1.0 rc yet"

paths = GraphAlgo.all_simple_paths.from(@n1).both(:knows).to(@n6).depth(3)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n1).both(:knows).to(@n6).depth(3)
paths.size.should == 3

paths = GraphAlgo.all_simple_paths.from(@n6).both(:knows).to(@n1).depth(3)
paths = Neo4j::GraphAlgo.all_simple_paths.from(@n6).both(:knows).to(@n1).depth(3)
paths.size.should == 3
end

Expand Down
8 changes: 4 additions & 4 deletions test/rest/rest_spec.rb
Expand Up @@ -217,7 +217,7 @@ class FooRest
last_response.status.should == 200
body = JSON.parse(last_response.body)
body.size.should == 1
body[0]['id'].should == bertil.neo_id
body[0]['_neo_id'].should == bertil.neo_id
end

it "should return a single related node on GET /nodes/<classname>/<node_id>/<has_one_rel>" do
Expand All @@ -233,7 +233,7 @@ class FooRest
# then
last_response.status.should == 200
body = JSON.parse(last_response.body)
body['id'].should == bertil.neo_id
body['_neo_id'].should == bertil.neo_id
end

it "should be possible to load a rels on GET /rels/<id>" do
Expand Down Expand Up @@ -445,7 +445,7 @@ class FooRest
last_response.status.should == 200
data = JSON.parse(last_response.body)
data.size.should == 1
data[0]['id'].should == p1_id
data[0]['_neo_id'].should == p1_id
data[0]['name'].should == "p"
end

Expand Down Expand Up @@ -527,7 +527,7 @@ class FooRest
last_response.status.should == 200
data = JSON.parse(last_response.body)
data.size.should == 1
data[0]['id'].should == id
data[0]['_neo_id'].should == id
end
end

Expand Down

0 comments on commit a66330f

Please sign in to comment.