Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 121 lines (88 sloc) 6.555 kB
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
1 == Welcome to Neography
2
90cb6ed @maxdemarzi adding traverser
maxdemarzi authored
3 Neography is a thin Ruby wrapper to the Neo4j Rest API, for more information:
e01369f @maxdemarzi cleaning up
maxdemarzi authored
4 * {Getting Started with Neo4j Server}[http://wiki.neo4j.org/content/Getting_Started_with_Neo4j_Server]
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
5 * {Neo4j Rest API Reference}[http://components.neo4j.org/neo4j-rest/]
6
ab93266 @maxdemarzi doc updates
maxdemarzi authored
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
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
8
9 === Installation
10
3a1cef5 @maxdemarzi make readme prettier
maxdemarzi authored
11 gem install 'neography'
12 require 'neography'
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
13
e42beda @maxdemarzi more cleanup
maxdemarzi authored
14 === Dependencies
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
15
e42beda @maxdemarzi more cleanup
maxdemarzi authored
16 for use:
17 json
18 httparty
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
19
e42beda @maxdemarzi more cleanup
maxdemarzi authored
20 for development:
21 rspec
22 net-http-spy
23 fakeweb
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
24
25 ==== Rails
26
27 Just add gem 'neography' to your Gemfile and run bundle install
28
29 === Documentation
30
ef9f673 @maxdemarzi Spliting off basic Rest wrapper
maxdemarzi authored
31 A thin ruby wrapper Neography::Rest which tries to mirror the Neo4j Rest API and returns JSON or Nil:
32
e42beda @maxdemarzi more cleanup
maxdemarzi authored
33 # protocol, server, port, log_file, log_enabled
34 @neo = Neography::Rest.new ('http://', '192.168.10.1', 7479, 'log/neography.log', true)
35
36 Default Parameters are:
37
38 @neo = Neography::Rest.new ('http://', 'localhost', 7474, '/neography.log', false)
39
40 To Use:
41
42 @neo = Neography::Rest.new
43
44 @neo.get_root # Get the root node
45 @neo.create_node # Create an empty node
46 @neo.create_node("age" => 31, "name" => "Max") # Create a node with some properties
47 @neo.get_node(id) # Get a node and its properties
48 @neo.delete_node(id) # Delete an unrelated node
49 @neo.delete_node!(id) # Delete a node and all its relationships
50
51 @neo.reset_node_properties(id, {"age" => 31}) # Reset a node's properties
52 @neo.set_node_properties(id, {"weight" => 200}) # Set a node's properties
53 @neo.get_node_properties(id) # Get just the node properties
54 @neo.get_node_properties(id, ["weight","age"]) # Get some of the node properties
55 @neo.remove_node_properties(id) # Remove all properties of a node
56 @neo.remove_node_properties(id, "weight") # Remove one property of a node
57 @neo.remove_node_properties(id, ["weight","age"]) # Remove multiple properties of a node
58
59 @neo.create_relationship("friends", node1, node2) # Create a relationship between node1 and node2
60 @neo.get_node_relationships(id) # Get all relationships
61 @neo.get_node_relationships(id, "in") # Get only incoming relationships
62 @neo.get_node_relationships(id, "all", "enemies") # Get all relationships of type enemies
63 @neo.get_node_relationships(id, "in", "enemies") # Get only incoming relationships of type enemies
64 @neo.delete_relationship(id) # Delete a relationship
65
66 @neo.reset_relationship_properties(id, {"age" => 31}) # Reset a relationship's properties
67 @neo.set_relationship_properties(id, {"weight" => 200}) # Set a relationship's properties
68 @neo.get_relationship_properties(id) # Get just the relationship properties
69 @neo.get_relationship_properties(id, ["since","met"]) # Get some of the relationship properties
70 @neo.remove_relationship_properties(id) # Remove all properties of a relationship
71 @neo.remove_relationship_properties(id, "since") # Remove one property of a relationship
72 @neo.remove_relationship_properties(id, ["since","met"]) # Remove multiple properties of a relationship
73
74 @neo.list_indexes # doesn't really seam to do what the api says it does
75 @neo.add_to_index(key, value, id) # adds a node to an index with the given key/value pair
76 @neo.remove_from_index(key, value, id) # removes a node to an index with the given key/value pair
77 @neo.get_index(key, value) # gets an index with the given key/value pair
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
78
4e1cf8f @maxdemarzi documentation changes, use shortest path as default for path
maxdemarzi authored
79 @neo.get_path(from, to, relationships, depth=4, algorithm="shortestPath") # finds the shortest path between two nodes
80 @neo.get_paths(from, to, relationships, depth=3, algorithm="allPaths") # finds all paths between two nodes
81
90cb6ed @maxdemarzi adding traverser
maxdemarzi authored
82 nodes = @neo.traverse(id, # the id of the node where the traversal starts
ab93266 @maxdemarzi doc updates
maxdemarzi authored
83 "nodes", # return_type (can be "nodes", "relationships" or "paths"
90cb6ed @maxdemarzi adding traverser
maxdemarzi authored
84 {"order" => "breadth first", # "breadth first" or "depth first" traversal order
85 "uniqueness" => "node global", # See Uniqueness in API documentation for options.
86 "relationships" => [{"type"=> "roommates", # A hash containg a description of the traversal
87 "direction" => "all"}, # two relationships.
88 {"type"=> "friends", #
89 "direction" => "out"}], #
90 "prune evaluator" => {"language" => "javascript", # A prune evaluator (when to stop traversing)
80cc0f0 @peterneubauer typos
peterneubauer authored
91 "body" => "position.endNode().getProperty('age') < 21;"},
90cb6ed @maxdemarzi adding traverser
maxdemarzi authored
92 "return filter" => {"language" => "builtin", # "all" or "all but start node"
93 "name" => "all"},
94 "depth" => 4})
95
96 # "depth" is a short-hand way of specifying a prune evaluator which prunes after a certain depth.
97 # 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.
98
ab93266 @maxdemarzi doc updates
maxdemarzi authored
99 Please see the specs for more examples.
100
101 See Neo4j API for:
102 * {Order}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/graphdb/Traverser.Order.html]
103 * {Uniqueness}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/kernel/Uniqueness.html]
104 * {Prune Evaluator}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/graphdb/StopEvaluator.html]
105 * {Return Filter}[http://components.neo4j.org/neo4j-examples/1.2.M04/apidocs/org/neo4j/graphdb/ReturnableEvaluator.html]
90cb6ed @maxdemarzi adding traverser
maxdemarzi authored
106
4e1cf8f @maxdemarzi documentation changes, use shortest path as default for path
maxdemarzi authored
107 === To Do
108
90cb6ed @maxdemarzi adding traverser
maxdemarzi authored
109 * More tests
77b9011 @maxdemarzi adding path tests
maxdemarzi authored
110 * examples
111 * batch import with typhoeus ?
90cb6ed @maxdemarzi adding traverser
maxdemarzi authored
112 * create proper objects for Node and Relationship
4e1cf8f @maxdemarzi documentation changes, use shortest path as default for path
maxdemarzi authored
113
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
114 === License
2bedc62 @maxdemarzi adding indexes
maxdemarzi authored
115
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
116 * Neography - MIT, see the LICENSE file http://github.com/maxdemarzi/neography/tree/master/LICENSE.
117 * Lucene - Apache, see http://lucene.apache.org/java/docs/features.html
90cb6ed @maxdemarzi adding traverser
maxdemarzi authored
118 * Neo4j - Dual free software/commercial license, see http://neo4j.org
0b5b547 @maxdemarzi starting on relationships
maxdemarzi authored
119
120
Something went wrong with that request. Please try again.