neo4j-core 0.0.15-java → 2.0.0.alpha.1-java
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/Gemfile +2 -2
- data/README.rdoc +12 -192
- data/lib/neo4j-core.rb +3 -19
- data/lib/neo4j-core/database.rb +5 -4
- data/lib/neo4j-core/event_handler.rb +1 -1
- data/lib/neo4j-core/index/class_methods.rb +41 -27
- data/lib/neo4j-core/index/index.rb +4 -3
- data/lib/neo4j-core/index/index_config.rb +23 -30
- data/lib/neo4j-core/index/indexer.rb +53 -65
- data/lib/neo4j-core/index/indexer_registry.rb +2 -2
- data/lib/neo4j-core/index/lucene_query.rb +42 -53
- data/lib/neo4j-core/node/class_methods.rb +4 -4
- data/lib/neo4j-core/node/node.rb +8 -1
- data/lib/neo4j-core/property/property.rb +3 -1
- data/lib/neo4j-core/relationship/relationship.rb +10 -8
- data/lib/neo4j-core/rels/rels.rb +4 -9
- data/lib/neo4j-core/rels/traverser.rb +27 -13
- data/lib/neo4j-core/traversal/prune_evaluator.rb +2 -2
- data/lib/neo4j-core/traversal/traverser.rb +27 -122
- data/lib/neo4j-core/type_converters/type_converters.rb +287 -0
- data/lib/neo4j-core/version.rb +1 -1
- data/lib/neo4j-core/version.rb~ +3 -0
- data/lib/neo4j/config.rb +6 -3
- data/lib/neo4j/neo4j.rb +22 -51
- data/lib/neo4j/node.rb +0 -27
- data/lib/neo4j/relationship.rb +0 -25
- data/lib/test.rb +27 -0
- data/neo4j-core.gemspec +2 -2
- metadata +11 -17
- data/lib/neo4j-core/cypher/cypher.rb +0 -969
- data/lib/neo4j-core/cypher/result_wrapper.rb +0 -48
- data/lib/neo4j-core/hash_with_indifferent_access.rb +0 -165
- data/lib/neo4j-core/index/unique_factory.rb +0 -54
- data/lib/neo4j-core/property/java.rb +0 -59
- data/lib/neo4j-core/wrapper/class_methods.rb +0 -22
- data/lib/neo4j-core/wrapper/wrapper.rb +0 -20
- data/lib/neo4j/algo.rb +0 -300
- data/lib/neo4j/cypher.rb +0 -180
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
|