neo4j-core 0.0.2-java → 0.0.3-java
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +183 -8
- data/lib/neo4j-core.rb +3 -0
- data/lib/neo4j-core/node/node.rb +1 -8
- data/lib/neo4j-core/relationship/relationship.rb +0 -6
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-core/wrapper/class_methods.rb +22 -0
- data/lib/neo4j-core/wrapper/wrapper.rb +13 -0
- data/lib/neo4j/node.rb +3 -0
- data/lib/neo4j/relationship.rb +4 -0
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -4,17 +4,13 @@ This gem only contains the JRuby mapping of the Neo4j graph database.
|
|
4
4
|
The neo4j.rb gem will be split up into two gems, neo4j-core and neo4j.
|
5
5
|
This gem will be included by neo4j 2.0.0 gem.
|
6
6
|
|
7
|
-
Changes from the neo4j.rb
|
8
|
-
* Use of YARD instead of RDoc
|
9
|
-
* Some tidy up of the API and code (e.g. Neo4j::Node#rels methods)
|
10
|
-
* Change of Ruby module structure.
|
11
|
-
* More RSpecs and more use of mocking combined with real testing of the Java layer
|
12
|
-
* Make sure that we retrieve relationships and nodes lazy if possible.
|
13
|
-
* Cypher Query DSL
|
14
|
-
|
15
7
|
This gem contains two modules: Neo4j and Neo4j::Core
|
16
8
|
The Neo4j module is public and the Neo4j::Core(::*) are private modules.
|
17
9
|
|
10
|
+
== Documentation
|
11
|
+
|
12
|
+
* {YARD}[http://rdoc.info/github/andreasronge/neo4j-core/file/README.rdoc]
|
13
|
+
|
18
14
|
== The public API
|
19
15
|
|
20
16
|
{Neo4j::Node} The Java Neo4j Node
|
@@ -25,3 +21,182 @@ The Neo4j module is public and the Neo4j::Core(::*) are private modules.
|
|
25
21
|
|
26
22
|
{Neo4j::Cypher} Cypher Query Generator, see RSpec spec/neo4j/cypher_spec
|
27
23
|
|
24
|
+
== Custom Index
|
25
|
+
|
26
|
+
You can create your own indexer
|
27
|
+
|
28
|
+
class MyIndex
|
29
|
+
extend Neo4j::Core::Index::ClassMethods
|
30
|
+
include Neo4j::Core::Index
|
31
|
+
|
32
|
+
node_indexer do
|
33
|
+
index_names :exact => 'myindex_exact', :fulltext => 'myindex_fulltext'
|
34
|
+
trigger_on :myindex => true, :things => ['a', 'b']
|
35
|
+
end
|
36
|
+
|
37
|
+
index :name
|
38
|
+
end
|
39
|
+
|
40
|
+
All nodes with the property <tt>myindex == true</tt> or property <tt>things</tt> <tt>'a'</tt> or <tt>'b'</tt>
|
41
|
+
will be indexed using this index.
|
42
|
+
|
43
|
+
Exampel:
|
44
|
+
n = Neo4j::Node.new(:myindex = true, :name => 'foo')
|
45
|
+
MyIndex.find('name: foo').first #=> n
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
== Cypher
|
50
|
+
|
51
|
+
Example:
|
52
|
+
Neo4j.query { node(3) }
|
53
|
+
|
54
|
+
Example with parameters:
|
55
|
+
Neo4j.query(Neo4j.ref_node} do |ref|
|
56
|
+
ref <=> :x
|
57
|
+
:x
|
58
|
+
end
|
59
|
+
|
60
|
+
Notice
|
61
|
+
* The last statement in the expression will be the return value.
|
62
|
+
* You can skip the start, match, where and ret (they are just empty methods).
|
63
|
+
|
64
|
+
=== Cypher Examples
|
65
|
+
|
66
|
+
"START n0=node(3) RETURN n0"
|
67
|
+
Neo4j.query do
|
68
|
+
start n = node(3)
|
69
|
+
ret n
|
70
|
+
end
|
71
|
+
# the above is same as:
|
72
|
+
Neo4j.query { node(3) }
|
73
|
+
|
74
|
+
"START n0=node(42) RETURN n0"
|
75
|
+
node(Neo4j::Node.new)
|
76
|
+
|
77
|
+
"START r0=relationship(3,4) RETURN r0"
|
78
|
+
rel(3,4)
|
79
|
+
|
80
|
+
"START n0=node(3) MATCH (n0)--(x) RETURN x"
|
81
|
+
start n = node(3)
|
82
|
+
match n <=> :x
|
83
|
+
ret :x
|
84
|
+
|
85
|
+
"START n0=node(3) MATCH (n0)--(v0) RETURN v0"
|
86
|
+
x = node
|
87
|
+
n = node(3)
|
88
|
+
match n <=> x
|
89
|
+
ret x
|
90
|
+
|
91
|
+
"START n0=node(3) MATCH (n0)--(v0) RETURN v0.name"
|
92
|
+
x = node
|
93
|
+
n = node(3)
|
94
|
+
match n <=> x
|
95
|
+
ret x[:name]
|
96
|
+
|
97
|
+
"START n0=node(1) RETURN n0.name AS SomethingTotallyDifferent"
|
98
|
+
x = node(1)
|
99
|
+
x[:name].as('SomethingTotallyDifferent')
|
100
|
+
|
101
|
+
"START n0=node:fooindex_exact(name:A) RETURN n0"
|
102
|
+
query(FooIndex, "name:A")
|
103
|
+
|
104
|
+
"START n0=node:fooindex_fulltext(desc="A") RETURN n0"
|
105
|
+
lookup(FooIndex, "desc", "A")
|
106
|
+
|
107
|
+
"START n0=node(1),n1=node(2) RETURN n0,n1"
|
108
|
+
[node(1), node(2)]
|
109
|
+
|
110
|
+
"START n0=node(3) MATCH (n0)-->(c)-->(d) RETURN c"
|
111
|
+
node(3) >> node(:c) >> :d
|
112
|
+
:c
|
113
|
+
|
114
|
+
"START n0=node(3) MATCH (n0)-[r]->(x) RETURN r"
|
115
|
+
node(3) > :r > :x
|
116
|
+
:r
|
117
|
+
|
118
|
+
"START n0=node(3) MATCH (n0)-[r:friends]->(x) RETURN r"
|
119
|
+
r = rel('r:friends').as(:r)
|
120
|
+
node(3) > r > :x
|
121
|
+
r
|
122
|
+
|
123
|
+
"START n0=node(3,1) WHERE n0.age < 30 RETURN n0"
|
124
|
+
n=node(3, 1)
|
125
|
+
where n[:age] < 30
|
126
|
+
ret n
|
127
|
+
|
128
|
+
"START n0=node(3,4) WHERE n0.desc = "hej" RETURN n0"
|
129
|
+
n=node(3, 4)
|
130
|
+
n[:desc] == "hej"
|
131
|
+
n
|
132
|
+
|
133
|
+
"START n0=node(3) MATCH (n0)<-[:knows]-(c) RETURN c"
|
134
|
+
a=node(3)
|
135
|
+
a < ':knows' < :c
|
136
|
+
:c
|
137
|
+
|
138
|
+
"START n0=node(3) MATCH (n0)-[r]->(v1) WHERE type(r) =~ /K.*/ RETURN r"
|
139
|
+
n=node(3)
|
140
|
+
n > (r=rel('r')) > node
|
141
|
+
r.rel_type =~ /K.*/
|
142
|
+
r
|
143
|
+
|
144
|
+
"START n0=node(3) MATCH m2 = (n0)-->(b) RETURN b,length(m2)"
|
145
|
+
p = node(3) >> :b; [:b, p.length]
|
146
|
+
|
147
|
+
"START n0=node(1) MATCH (n0)-->(b) RETURN distinct n0"
|
148
|
+
n=node(1); n>>:b; n.distinct
|
149
|
+
|
150
|
+
"START n0=node(2) MATCH (n0)-->(x) RETURN n0,count(*)"
|
151
|
+
n = node(2))>>:x
|
152
|
+
[n, count]
|
153
|
+
|
154
|
+
"START n0=node(2,3,4) RETURN sum(n0.property)"
|
155
|
+
n=node(2, 3, 4)
|
156
|
+
n[:property].sum
|
157
|
+
|
158
|
+
"START n0=node(2) MATCH (n0)-->(b) RETURN count(distinct n0.eyes)"
|
159
|
+
n=node(2); n>>:b
|
160
|
+
n[:eyes].distinct.count
|
161
|
+
|
162
|
+
"START n0=node(3,4,5) RETURN ID(n0)"
|
163
|
+
node(3, 4, 5).neo_id
|
164
|
+
|
165
|
+
"START n0=node(2) WHERE any(x in n0.array WHERE x = "one") RETURN n0"
|
166
|
+
a = node(2)
|
167
|
+
a[:array].any? { |x| x == 'one' }
|
168
|
+
a
|
169
|
+
|
170
|
+
"START n0=node(3),n1=node(4),n2=node(1) MATCH m4 = (n0)-->(n1)-->(n2) RETURN extract(x in nodes(m4) : x.age)"
|
171
|
+
a=node(3)
|
172
|
+
b=node(4)
|
173
|
+
c=node(1)
|
174
|
+
p=a>>b>>c
|
175
|
+
p.nodes.extract { |x| x[:age] }
|
176
|
+
|
177
|
+
"START n0=node(3) WHERE abs(n0.x) = 3 RETURN n0"
|
178
|
+
a=node(3); a[:x].abs==3
|
179
|
+
a
|
180
|
+
|
181
|
+
"START n0=node(3,4,5,1,2) RETURN n0 ORDER BY n0.name SKIP 1 LIMIT 2"
|
182
|
+
a=node(3,4,5,1,2); ret(a).asc(a[:name]).skip(1).limit(2)
|
183
|
+
# o same as
|
184
|
+
a=node(3,4,5,1,2); ret a, :asc => a[:name], :skip => 1, :limit => 2
|
185
|
+
|
186
|
+
For more examples, see the RSpecs
|
187
|
+
|
188
|
+
== Creates Your Own Wrapper
|
189
|
+
|
190
|
+
Todo, see {Neo4j::Core::Wrapper}
|
191
|
+
|
192
|
+
|
193
|
+
== Changes
|
194
|
+
|
195
|
+
Changes from the neo4j.rb
|
196
|
+
* Use of YARD instead of RDoc
|
197
|
+
* Some tidy up of the API and code (e.g. Neo4j::Node#rels methods)
|
198
|
+
* Change of Ruby module structure.
|
199
|
+
* More RSpecs and more use of mocking combined with real testing of the Java layer
|
200
|
+
* Make sure that we retrieve relationships and nodes lazy if possible.
|
201
|
+
* Cypher Query DSL
|
202
|
+
|
data/lib/neo4j-core.rb
CHANGED
@@ -39,6 +39,9 @@ require 'neo4j-core/index/lucene_query'
|
|
39
39
|
|
40
40
|
require 'neo4j-core/equal/equal'
|
41
41
|
|
42
|
+
require 'neo4j-core/wrapper/class_methods'
|
43
|
+
require 'neo4j-core/wrapper/wrapper'
|
44
|
+
|
42
45
|
require 'neo4j-core/relationship/relationship'
|
43
46
|
require 'neo4j-core/relationship/class_methods'
|
44
47
|
|
data/lib/neo4j-core/node/node.rb
CHANGED
@@ -31,14 +31,7 @@ module Neo4j
|
|
31
31
|
Neo4j::Node.exist?(self)
|
32
32
|
end
|
33
33
|
|
34
|
-
#
|
35
|
-
# This allows you to create a custom Ruby wrapper class around the Neo4j::Node.
|
36
|
-
# This is for example done in the <tt>neo4j<//t> ruby gem <tt>Neo4j::NodeMixin</tt>
|
37
|
-
# @return a wrapper object or self
|
38
|
-
def wrapper
|
39
|
-
self.class.respond_to?(:wrapper) ? self.class.wrapper(node) : self
|
40
|
-
end
|
41
|
-
|
34
|
+
# Overrides the class so that the java object feels like a Ruby object.
|
42
35
|
def class
|
43
36
|
Neo4j::Node
|
44
37
|
end
|
@@ -70,12 +70,6 @@ module Neo4j
|
|
70
70
|
Neo4j::Relationship.exist?(self)
|
71
71
|
end
|
72
72
|
|
73
|
-
# Loads the wrapper using the #wrapper class method if it exists, otherwise return self.
|
74
|
-
def wrapper
|
75
|
-
self.class.respond_to?(:wrapper) ? self.class.wrapper(node) : self
|
76
|
-
end
|
77
|
-
|
78
|
-
|
79
73
|
# Returns the relationship name
|
80
74
|
#
|
81
75
|
# @example
|
data/lib/neo4j-core/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Core
|
3
|
+
module Wrapper
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
# Tries to load a wrapper for this node if possible
|
7
|
+
# @see #wrapper_proc=
|
8
|
+
def wrapper(entity)
|
9
|
+
@_wrapper_proc ? @_wrapper_proc.call(entity) : entity
|
10
|
+
end
|
11
|
+
|
12
|
+
# Sets the procs to be used to load wrappers
|
13
|
+
# @see #wrapper
|
14
|
+
def wrapper_proc=(proc)
|
15
|
+
@_wrapper_proc = proc
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Neo4j
|
2
|
+
module Core
|
3
|
+
# Can be used to define your own wrapper class around nodes and relationships
|
4
|
+
module Wrapper
|
5
|
+
|
6
|
+
# @return [self, Object] return self or a wrapper Ruby object
|
7
|
+
# @see Neo4j::Node::ClassMethods#wrapper
|
8
|
+
def wrapper
|
9
|
+
self.class.wrapper(self)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/neo4j/node.rb
CHANGED
@@ -11,12 +11,14 @@ module Neo4j
|
|
11
11
|
#
|
12
12
|
class Node
|
13
13
|
extend Neo4j::Core::Node::ClassMethods
|
14
|
+
extend Neo4j::Core::Wrapper::ClassMethods
|
14
15
|
|
15
16
|
include Neo4j::Core::Property
|
16
17
|
include Neo4j::Core::Rels
|
17
18
|
include Neo4j::Core::Traversal
|
18
19
|
include Neo4j::Core::Equal
|
19
20
|
include Neo4j::Core::Node
|
21
|
+
include Neo4j::Core::Wrapper
|
20
22
|
|
21
23
|
class << self
|
22
24
|
|
@@ -29,6 +31,7 @@ module Neo4j
|
|
29
31
|
include Neo4j::Core::Traversal
|
30
32
|
include Neo4j::Core::Equal
|
31
33
|
include Neo4j::Core::Node
|
34
|
+
include Neo4j::Core::Wrapper
|
32
35
|
end
|
33
36
|
end
|
34
37
|
end
|
data/lib/neo4j/relationship.rb
CHANGED
@@ -33,9 +33,12 @@ module Neo4j
|
|
33
33
|
#
|
34
34
|
class Relationship
|
35
35
|
extend Neo4j::Core::Relationship::ClassMethods
|
36
|
+
extend Neo4j::Core::Wrapper::ClassMethods
|
37
|
+
|
36
38
|
include Neo4j::Core::Property
|
37
39
|
include Neo4j::Core::Equal
|
38
40
|
include Neo4j::Core::Relationship
|
41
|
+
include Neo4j::Core::Wrapper
|
39
42
|
|
40
43
|
# (see Neo4j::Core::Relationship::ClassMethods#new)
|
41
44
|
def initialize(rel_type, start_node, end_node, props={})
|
@@ -48,6 +51,7 @@ module Neo4j
|
|
48
51
|
include Neo4j::Core::Property
|
49
52
|
include Neo4j::Core::Equal
|
50
53
|
include Neo4j::Core::Relationship
|
54
|
+
include Neo4j::Core::Wrapper
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: neo4j-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Andreas Ronge
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-22 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: neo4j-community
|
@@ -64,6 +64,8 @@ files:
|
|
64
64
|
- lib/neo4j-core/traversal/evaluator.rb
|
65
65
|
- lib/neo4j-core/rels/traverser.rb
|
66
66
|
- lib/neo4j-core/rels/rels.rb
|
67
|
+
- lib/neo4j-core/wrapper/wrapper.rb
|
68
|
+
- lib/neo4j-core/wrapper/class_methods.rb
|
67
69
|
- lib/neo4j-core/index/index_config.rb
|
68
70
|
- lib/neo4j-core/index/indexer.rb
|
69
71
|
- lib/neo4j-core/index/lucene_query.rb
|