neo4j-core 2.1.0-java → 2.2.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -10
- data/README.rdoc +2 -130
- data/config/neo4j/config.yml~ +102 -0
- data/lib/db/active_tx_log +1 -0
- data/lib/db/index/lucene-store.db +0 -0
- data/lib/db/index/lucene.log.active +0 -0
- data/lib/db/index/lucene.log.v0 +0 -0
- data/lib/db/messages.log +285 -0
- data/lib/db/neostore +0 -0
- data/lib/db/neostore.id +0 -0
- data/lib/db/neostore.nodestore.db +1 -0
- data/lib/db/neostore.nodestore.db.id +0 -0
- data/lib/db/neostore.propertystore.db +1 -0
- data/lib/db/neostore.propertystore.db.arrays +0 -0
- data/lib/db/neostore.propertystore.db.arrays.id +0 -0
- data/lib/db/neostore.propertystore.db.id +0 -0
- data/lib/db/neostore.propertystore.db.index +1 -0
- data/lib/db/neostore.propertystore.db.index.id +0 -0
- data/lib/db/neostore.propertystore.db.index.keys +0 -0
- data/lib/db/neostore.propertystore.db.index.keys.id +0 -0
- data/lib/db/neostore.propertystore.db.strings +0 -0
- data/lib/db/neostore.propertystore.db.strings.id +0 -0
- data/lib/db/neostore.relationshipstore.db +1 -0
- data/lib/db/neostore.relationshipstore.db.id +0 -0
- data/lib/db/neostore.relationshiptypestore.db +1 -0
- data/lib/db/neostore.relationshiptypestore.db.id +0 -0
- data/lib/db/neostore.relationshiptypestore.db.names +0 -0
- data/lib/db/neostore.relationshiptypestore.db.names.id +0 -0
- data/lib/db/nioneo_logical.log.active +0 -0
- data/lib/db/nioneo_logical.log.v0 +0 -0
- data/lib/db/tm_tx_log.1 +0 -0
- data/lib/neo4j-core.rb +4 -4
- data/lib/neo4j-core/database.rb +1 -0
- data/lib/neo4j-core/index/index_config.rb +1 -1
- data/lib/neo4j-core/property/property.rb +11 -0
- data/lib/neo4j-core/relationship/class_methods.rb +1 -3
- data/lib/neo4j-core/traversal/traverser.rb +19 -29
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-core/version.rb~ +5 -0
- data/lib/neo4j/config.rb +2 -2
- data/lib/neo4j/config.rb~ +136 -0
- data/lib/neo4j/neo4j.rb +3 -3
- data/neo4j-core.gemspec +1 -0
- metadata +81 -6
- data/lib/neo4j-core/cypher/cypher.rb +0 -1033
- data/lib/neo4j-core/cypher/result_wrapper.rb +0 -48
- data/lib/neo4j/cypher.rb +0 -180
@@ -1,48 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
module Core
|
3
|
-
module Cypher
|
4
|
-
# Wraps the Cypher query result.
|
5
|
-
# Loads the node and relationships wrapper if possible and use symbol as column keys.
|
6
|
-
# @notice The result is a once forward read only Enumerable, work if you need to read the result twice - use #to_a
|
7
|
-
#
|
8
|
-
# @example
|
9
|
-
# result = Neo4j.query(@a, @b){|a,b| node(a,b).as(:n)}
|
10
|
-
# r = @query_result.to_a # can only loop once
|
11
|
-
# r.size.should == 2
|
12
|
-
# r.first.should include(:n)
|
13
|
-
# r[0][:n].neo_id.should == @a.neo_id
|
14
|
-
# r[1][:n].neo_id.should == @b.neo_id
|
15
|
-
class ResultWrapper
|
16
|
-
include Enumerable
|
17
|
-
|
18
|
-
# @return the original result from the Neo4j Cypher Engine, once forward read only !
|
19
|
-
attr_reader :source
|
20
|
-
|
21
|
-
def initialize(source)
|
22
|
-
@source = source
|
23
|
-
end
|
24
|
-
|
25
|
-
# @return [Array<Symbol>] the columns in the query result
|
26
|
-
def columns
|
27
|
-
@source.columns.map{|x| x.to_sym}
|
28
|
-
end
|
29
|
-
|
30
|
-
# for the Enumerable contract
|
31
|
-
def each
|
32
|
-
@source.each { |row| yield map(row) }
|
33
|
-
end
|
34
|
-
|
35
|
-
# Maps each row so that we can use symbols for column names.
|
36
|
-
# @private
|
37
|
-
def map(row)
|
38
|
-
out = {} # move to a real hash!
|
39
|
-
row.each do |key, value|
|
40
|
-
out[key.to_sym] = value.respond_to?(:wrapper) ? value.wrapper : value
|
41
|
-
end
|
42
|
-
out
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/lib/neo4j/cypher.rb
DELETED
@@ -1,180 +0,0 @@
|
|
1
|
-
module Neo4j
|
2
|
-
|
3
|
-
# Generates a Cypher string from a Ruby DSL.
|
4
|
-
# This class is used by the {Ņeo4j#query} method.
|
5
|
-
# Methods on in this class returns object from the {Neo4j::Core::Cypher} module (e.g. {Neo4j::Cypher#node} can return a #{Neo4j::Core::Cypher::StartNode}).
|
6
|
-
#
|
7
|
-
# @example usage
|
8
|
-
# Neo4j::Cypher.new { node }
|
9
|
-
#
|
10
|
-
class Cypher
|
11
|
-
# @private
|
12
|
-
attr_reader :expressions
|
13
|
-
|
14
|
-
include Neo4j::Core::Cypher
|
15
|
-
include Neo4j::Core::Cypher::MathFunctions
|
16
|
-
|
17
|
-
# Creates a Cypher DSL query.
|
18
|
-
# To create a new cypher query you must initialize it either an String or a Block.
|
19
|
-
#
|
20
|
-
# @example <tt>START n0=node(3) MATCH (n0)--(x) RETURN x</tt> same as
|
21
|
-
# Cypher.new { start n = node(3); match n <=> :x; ret :x }.to_s
|
22
|
-
#
|
23
|
-
# @example <tt>START n0=node(3) MATCH (n0)-[r]->(x) RETURN r</tt> same as
|
24
|
-
# node(3) > :r > :x; :r
|
25
|
-
#
|
26
|
-
# @example <tt>START n0=node(3) MATCH (n0)-->(x) RETURN x</tt> same as
|
27
|
-
# node(3) >> :x; :x
|
28
|
-
#
|
29
|
-
# @param args the argument for the dsl_block
|
30
|
-
# @yield the block which will be evaluated in the context of this object in order to create an Cypher Query string
|
31
|
-
# @yieldreturn [Return, Object] If the return is not an instance of Return it will be converted it to a Return object (if possible).
|
32
|
-
# @see Neo4j::Core::Cypher
|
33
|
-
def initialize(*args, &dsl_block)
|
34
|
-
@expressions = []
|
35
|
-
@variables = []
|
36
|
-
to_dsl_args = args.map do |a|
|
37
|
-
case
|
38
|
-
when a.is_a?(Array) && a.first.respond_to?(:_java_node)
|
39
|
-
StartNode.new(a, @expressions)
|
40
|
-
when a.is_a?(Array) && a.first.respond_to?(:_java_rel)
|
41
|
-
StartRel.new(a, @expressions)
|
42
|
-
when a.respond_to?(:_java_node)
|
43
|
-
StartNode.new([a], @expressions)
|
44
|
-
when a.respond_to?(:_java_rel)
|
45
|
-
StartRel.new([a], @expressions)
|
46
|
-
else
|
47
|
-
a
|
48
|
-
end
|
49
|
-
end
|
50
|
-
res = self.instance_exec(*to_dsl_args, &dsl_block)
|
51
|
-
unless res.kind_of?(Return)
|
52
|
-
res.respond_to?(:to_a) ? ret(*res) : ret(res)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
# Does nothing, just for making the DSL easier to read (maybe).
|
57
|
-
# @return self
|
58
|
-
def match(*)
|
59
|
-
self
|
60
|
-
end
|
61
|
-
|
62
|
-
# Does nothing, just for making the DSL easier to read (maybe)
|
63
|
-
# @return self
|
64
|
-
def start(*)
|
65
|
-
self
|
66
|
-
end
|
67
|
-
|
68
|
-
def where(w=nil)
|
69
|
-
Where.new(@expressions, w) if w.is_a?(String)
|
70
|
-
self
|
71
|
-
end
|
72
|
-
|
73
|
-
# Specifies a start node by performing a lucene query.
|
74
|
-
# @param [Class] index_class a class responsible for an index
|
75
|
-
# @param [String] q the lucene query
|
76
|
-
# @param [Symbol] index_type the type of index
|
77
|
-
# @return [NodeQuery]
|
78
|
-
def query(index_class, q, index_type = :exact)
|
79
|
-
NodeQuery.new(index_class, q, index_type, @expressions)
|
80
|
-
end
|
81
|
-
|
82
|
-
# Specifies a start node by performing a lucene query.
|
83
|
-
# @param [Class] index_class a class responsible for an index
|
84
|
-
# @param [String, Symbol] key the key we ask for
|
85
|
-
# @param [String, Symbol] value the value of the key we ask for
|
86
|
-
# @return [NodeLookup]
|
87
|
-
def lookup(index_class, key, value)
|
88
|
-
NodeLookup.new(index_class, key, value, @expressions)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Creates a node variable.
|
92
|
-
# It will create different variables depending on the type of the first element in the nodes argument.
|
93
|
-
# * Fixnum - it will be be used as neo_id for start node(s) (StartNode)
|
94
|
-
# * Symbol - it will create an unbound node variable with the same name as the symbol (NodeVar#as)
|
95
|
-
# * empty array - it will create an unbound node variable (NodeVar)
|
96
|
-
#
|
97
|
-
# @param [Fixnum,Symbol,String] nodes the id of the nodes we want to start from
|
98
|
-
# @return [StartNode, NodeVar]
|
99
|
-
def node(*nodes)
|
100
|
-
if nodes.first.is_a?(Symbol)
|
101
|
-
NodeVar.new(@expressions, @variables).as(nodes.first)
|
102
|
-
elsif !nodes.empty?
|
103
|
-
StartNode.new(nodes, @expressions)
|
104
|
-
else
|
105
|
-
NodeVar.new(@expressions, @variables)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
# Similar to #node
|
110
|
-
# @return [StartRel, RelVar]
|
111
|
-
def rel(*rels)
|
112
|
-
if rels.first.is_a?(Fixnum) || rels.first.respond_to?(:neo_id)
|
113
|
-
StartRel.new(rels, @expressions)
|
114
|
-
elsif rels.first.is_a?(Symbol)
|
115
|
-
RelVar.new(@expressions, @variables, ":`#{rels.first}`").as(rels.first)
|
116
|
-
elsif rels.first.is_a?(String)
|
117
|
-
RelVar.new(@expressions, @variables, rels.first)
|
118
|
-
else
|
119
|
-
raise "Unknown arg #{rels.inspect}"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
# Specifies a return statement.
|
124
|
-
# Notice that this is not needed, since the last value of the DSL block will be converted into one or more
|
125
|
-
# return statements.
|
126
|
-
# @param [Symbol, #var_name] returns a list of variables we want to return
|
127
|
-
# @return [Return]
|
128
|
-
def ret(*returns)
|
129
|
-
options = returns.last.is_a?(Hash) ? returns.pop : {}
|
130
|
-
@expressions -= @expressions.find_all { |r| r.clause == :return && returns.include?(r) }
|
131
|
-
returns.each { |ret| Return.new(ret, @expressions, options) unless ret.respond_to?(:clause) && [:order_by, :skip, :limit].include?(ret.clause)}
|
132
|
-
@expressions.last
|
133
|
-
end
|
134
|
-
|
135
|
-
def shortest_path(&block)
|
136
|
-
match = instance_eval(&block)
|
137
|
-
match.algorithm = 'shortestPath'
|
138
|
-
match.find_match_start
|
139
|
-
end
|
140
|
-
|
141
|
-
def shortest_paths(&block)
|
142
|
-
match = instance_eval(&block)
|
143
|
-
match.algorithm = 'allShortestPaths'
|
144
|
-
match.find_match_start
|
145
|
-
end
|
146
|
-
|
147
|
-
# @param [Symbol,nil] variable the entity we want to count or wildcard (*)
|
148
|
-
# @return [Return] a counter return clause
|
149
|
-
def count(variable='*')
|
150
|
-
Return.new("count(#{variable.to_s})", @expressions)
|
151
|
-
end
|
152
|
-
|
153
|
-
def coalesce(*args)
|
154
|
-
s = args.map { |x| x.var_name }.join(", ")
|
155
|
-
Return.new("coalesce(#{s})", @expressions)
|
156
|
-
end
|
157
|
-
|
158
|
-
def nodes(*args)
|
159
|
-
s = args.map { |x| x.referenced!; x.var_name }.join(", ")
|
160
|
-
Return.new("nodes(#{s})", @expressions)
|
161
|
-
end
|
162
|
-
|
163
|
-
def rels(*args)
|
164
|
-
s = args.map { |x| x.referenced!; x.var_name }.join(", ")
|
165
|
-
Return.new("relationships(#{s})", @expressions)
|
166
|
-
end
|
167
|
-
|
168
|
-
# Converts the DSL query to a cypher String which can be executed by cypher query engine.
|
169
|
-
def to_s
|
170
|
-
clause = nil
|
171
|
-
@expressions.map do |expr|
|
172
|
-
next unless expr.valid?
|
173
|
-
expr_to_s = expr.clause != clause ? "#{expr.prefix} #{expr.to_s}" : "#{expr.separator}#{expr.to_s}"
|
174
|
-
clause = expr.clause
|
175
|
-
expr_to_s
|
176
|
-
end.join
|
177
|
-
end
|
178
|
-
|
179
|
-
end
|
180
|
-
end
|