-
Notifications
You must be signed in to change notification settings - Fork 1
/
gremlindocs-methods.expected
410 lines (410 loc) · 10.4 KB
/
gremlindocs-methods.expected
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
node > // gremlindocs-methods
node > // See http://gremlindocs.com/#methods
node >
node > // ### http://gremlindocs.com/#methods/element-keys
node > // Get the property keys of an element.
node > // TODO: Not implemented.
node >
node > // http://gremlindocs.com/#methods/element-remove
node > g.E().property('weight');
[
0.2,
0.4,
0.4,
0.5,
1,
1
]
node > var deferred = Q.defer();
node > g.E().has('weight',T.lt,g.java.newFloat(0.5)).remove(deferred.makeNodeResolver()) // No removeSync
node > deferred.promise
node > g.E().property('weight') // now show that the edges with weights<0.5 were removed.
[
0.5,
1,
1
]
node > var g = makeDemoTinker() // restore the demo graph
node > g.E().property('weight') // now show that all edges restored.
[
0.2,
0.4,
0.4,
0.5,
1,
1
]
node >
node > // ### http://gremlindocs.com/#methods/element-values
node > // Gets the property values of an element.
node > // TODO: Not implemented.
node >
node > // http://gremlindocs.com/#methods/graph-addedge
node > // Adds an edge to the graph. Note that most graph implementations ignore the identifier supplied to addEdge.
node > var t = makeEmptyTinker()
node > var d1 = Q.defer()
node > var d2 = Q.defer()
node > t.addVertex(null, d1.makeNodeResolver())
node > t.addVertex(null, d2.makeNodeResolver())
node > var v1 = d1.promise
node > var v2 = d2.promise
node > var d3 = Q.defer()
node > t.addEdge(null, v1, v2, 'friend', d3.makeNodeResolver())
node > var edge = d3.promise
node > v1
[
{
_id: '0',
_type: 'vertex'
}
]
node > v2
[
{
_id: '1',
_type: 'vertex'
}
]
node > edge
[
{
_id: '2',
_inV: '1',
_label: 'friend',
_outV: '0',
_type: 'edge'
}
]
node >
node > // http://gremlindocs.com/#methods/graph-addvertex
node > t = makeEmptyTinker()
[
'tinkergraph[vertices:0 edges:0]'
]
node > t.addVertex()
[
{
_id: '0',
_type: 'vertex'
}
]
node > t.addVertex()
[
{
_id: '1',
_type: 'vertex'
}
]
node > t.addVertex(100)
[
{
_id: '100',
_type: 'vertex'
}
]
node > // But our addVertex currently ignores passed in properties
node > t.addVertex(null, {name: 'stephen'})
[
{
_id: '2',
_type: 'vertex'
}
]
node >
node > // http://gremlindocs.com/#methods/graph-e
node > g = makeDemoTinker()
[
'tinkergraph[vertices:6 edges:6]'
]
node > g.e('10')
[
{
_id: '10',
_inV: '5',
_label: 'created',
_outV: '4',
_type: 'edge',
weight: 1
}
]
node > g.e('10', '11', '12')
[
{
_id: '10',
_inV: '5',
_label: 'created',
_outV: '4',
_type: 'edge',
weight: 1
},
{
_id: '11',
_inV: '3',
_label: 'created',
_outV: '4',
_type: 'edge',
weight: 0.4
},
{
_id: '12',
_inV: '3',
_label: 'created',
_outV: '6',
_type: 'edge',
weight: 0.2
}
]
node > g.e(['10', '11', '12'])
[
{
_id: '10',
_inV: '5',
_label: 'created',
_outV: '4',
_type: 'edge',
weight: 1
},
{
_id: '11',
_inV: '3',
_label: 'created',
_outV: '4',
_type: 'edge',
weight: 0.4
},
{
_id: '12',
_inV: '3',
_label: 'created',
_outV: '6',
_type: 'edge',
weight: 0.2
}
]
node > var pipe = g.e(['10', '11', '12'])
node > pipe.id()
[
'10',
'11',
'12'
]
node >
node > // http://gremlindocs.com/#methods/graph-load
node > // Load a file from one of several standard formats such as GraphML, GML, or GraphSON.
node > // Note: gremlin-node currently limited to GraphML.
node > toy = makeEmptyTinker()
[
'tinkergraph[vertices:0 edges:0]'
]
node > toy.loadGraphMLSync('toy-example.xml')
node > toy
[
'tinkergraph[vertices:6 edges:6]'
]
node > dead = makeEmptyTinker()
[
'tinkergraph[vertices:0 edges:0]'
]
node > dead.loadGraphMLSync('grateful-dead.xml')
node > dead
[
'tinkergraph[vertices:809 edges:8049]'
]
node >
node > // http://gremlindocs.com/#methods/graph-save
node > // Save a graph to file given one of several standard formats such as GraphML, GML, or GraphSON.
node > // Note: gremlin-node currently limited to GraphML.
node > dead.saveGraphMLSync('/tmp/copy-dead.xml')
node > dead.saveGraphSONSync('/tmp/copy-dead.json')
node >
node > // Now read back these files
node > xmldead = makeEmptyTinker()
[
'tinkergraph[vertices:0 edges:0]'
]
node > xmldead.loadGraphMLSync('/tmp/copy-dead.xml')
node > xmldead
[
'tinkergraph[vertices:809 edges:8049]'
]
node >
node > jsondead = makeEmptyTinker()
[
'tinkergraph[vertices:0 edges:0]'
]
node > jsondead.loadGraphSONSync('/tmp/copy-dead.json')
node > jsondead
[
'tinkergraph[vertices:809 edges:8049]'
]
node >
node > // http://gremlindocs.com/#methods/graph-v
node > // Get a vertex or set of vertices by providing one or more vertex identifiers. The identifiers
node > // must be the identifiers assigned by the underlying graph implementation.
node > // Note that with the gremlin-node implementation, the v() operator can take a callback or not.
node > // If a callback is not provided, the return result is a **Promise** for a PipelineWrapper.
node > // Note that the groovy console returns a vertex with only one id is passed in, and a pipeline
node > // when more than one vertex is passed in. In gremlin-node we always return promise for a pipeline.
node > // Because the result is a promise, it it not possible to chain more pipeline steps,
node > // as in g.v('2').out().id().
node > // Also, in the console, if a var assignment is not used, the promise is resolved immediately,
node > // exhausting the pipeline without running other steps.
node > // However, if a variable is assigned the promise, then the variable can be used to start a pipeline.
node > // See example at end using 'var pipe = ...'.
node > g = makeDemoTinker()
[
'tinkergraph[vertices:6 edges:6]'
]
node > g.v('2')
[
{
_id: '2',
_type: 'vertex',
age: 27,
name: 'vadas'
}
]
node > g.v('1', '2','4')
[
{
_id: '1',
_type: 'vertex',
age: 29,
name: 'marko'
},
{
_id: '2',
_type: 'vertex',
age: 27,
name: 'vadas'
},
{
_id: '4',
_type: 'vertex',
age: 32,
name: 'josh'
}
]
node > g.v(['1', '2','4'])
[
{
_id: '1',
_type: 'vertex',
age: 29,
name: 'marko'
},
{
_id: '2',
_type: 'vertex',
age: 27,
name: 'vadas'
},
{
_id: '4',
_type: 'vertex',
age: 32,
name: 'josh'
}
]
node > var pipe = g.v('1')
node > pipe.out().id()
[
'2',
'3',
'4'
]
node >
node > // http://gremlindocs.com/#methods/index-map-entry
node > // Look up a value in an index.
node > // TODO: Not yet implemented in gremlin-node.
node >
node > // http://gremlindocs.com/#methods/pipe-enablepath
node > // If the path information is required internal to a closure, Gremlin doesn’t know that as it can
node > // not interpret what is in a closure. As such, be sure to use GremlinPipeline.enablePath() if path
node > // information will be required by the expression.
node > // TODO: Not easy to replicate this snippet at this time
node >
node > // http://gremlindocs.com/#methods/pipe-fill
node > // Takes all the results in the pipeline and puts them into the provided collection.
node > // fill() can be called using either a callback API or a promise API:
node > // We use a promise here to make a callback with d.makeNodeResolver(),
node > // but as far as fill() is concerned, it is being called with a regular node callback function.
node > var m = new ArrayList()
node > var d = Q.defer()
node > g.V('id', '1').out().order('{it -> it.a.id <=> it.b.id}').fill(m, d.makeNodeResolver())
node > d.promise
'[v[2], v[3], v[4]]'
node > m
'[v[2], v[3], v[4]]'
node > // Here we truly use the promise API
node > var n = new ArrayList()
node > g.V('id', '1').out().order('{it -> it.a.id <=> it.b.id}').fill(n)
'[v[2], v[3], v[4]]'
node > n
'[v[2], v[3], v[4]]'
node >
node > // http://gremlindocs.com/#methods/pipe-iterate
node > // Calls Pipe.next for all objects in the pipe. This is an important notion
node > // to follow when considering the behavior of the Gremlin Console. The
node > // Gremlin Console iterates through the pipeline automatically and outputs
node > // the results. Outside of the Gremlin Console or if more than one
node > // statement is present on a single line of the Gremlin Console, iterating
node > // the pipe must be done manually. Read more about this topic in the
node > // Gremlin Wiki Troubleshooting Page.
node > //
node > // There are some important things to note in the example below. Had the
node > // the first line of Gremlin been executed separately, as opposed to being
node > // placed on the same line separated by a semi-colon, the names of all the
node > // vertices would have changed because the Gremlin Console would have
node > // automatically iterated the pipe and processed the side-effects.
node > //
node > // TODO: implement this test
node >
node > // http://gremlindocs.com/#methods/pipe-next
node > // Gets the next object in the pipe or the next n objects. This is an
node > // important notion to follow when considering the behavior of the Gremlin
node > // Console. The Gremlin Console iterates through the pipeline automatically
node > // and outputs the results. Outside of the Gremlin Console or if more than
node > // one statement is present on a single line of the Gremlin Console,
node > // iterating the pipe must be done manually. Read more about this topic in
node > // the Gremlin Wiki Troubleshooting Page.
node > //
node > // There are some important things to note in the example below. Had the
node > // the first line of Gremlin been executed separately, as opposed to being
node > // placed on the same line separated by a semi-colon, the name of the
node > // vertex would have changed because the Gremlin Console would have
node > // automatically iterated the pipe and processed the side-effect.
node > //
node > // TODO: Our next() does not take the optional integer n.
node > // TODO: Our node console doesn't implement the weird semantics of the
node > // Groovy Gremlin console for when there is more than one statement present
node > // on a single line. Should we try to mimic that behavior? Seems unnecessary.
node >
node > g = makeDemoTinker()
[
'tinkergraph[vertices:6 edges:6]'
]
node > var d = Q.defer()
node > g.V().order('{it -> it.a.id <=> it.b.id}').sideEffect('{it -> it.name="same-again"}').next(d.makeNodeResolver())
node > d.promise
[
{
_id: '1',
_type: 'vertex',
age: 29,
name: 'same-again'
}
]
node > g.V().property('name')
[
'josh',
'lop',
'peter',
'ripple',
'same-again',
'vadas'
]
node >
node > 'goodbye'
'goodbye'
node >