Hi,
I did you example over TinkerGraph as vertex IDs are Strings and thus, easy to
build your graph with.
~$ gremlin
\,,,/
(o o)
-----oOOo-(_)-oOOo-----
gremlin> g = new TinkerGraph()
==>tinkergraph[vertices:0 edges:0]
gremlin> g.addVertex('A'); g.addVertex('B'); g.addVertex('C');
g.addVertex('D'); g.addVertex('E');
==>v[E]
gremlin> g.addEdge(g.v('C'),g.v('A'),'foo');
g.addEdge(g.v('D'),g.v('A'),'foo'); g.addEdge(g.v('E'),g.v('A'),'bar')
==>e[2][E-bar->A]
gremlin> g.V
==>v[D]
==>v[E]
==>v[A]
==>v[B]
==>v[C]
gremlin> g.E
==>e[2][E-bar->A]
==>e[1][D-foo->A]
==>e[0][C-foo->A]
So, you have your 5 vertices and 3 edges. Next, here is your mutating traversal:
gremlin> g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo');
g.removeEdge(it)}
==>e[1][D-foo->A]
==>e[0][C-foo->A]
And now your edges are as you wanted them.
gremlin> g.E
==>e[3][D-foo->B]
==>e[2][E-bar->A]
==>e[4][C-foo->B]
So again, your traversal is:
g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,g.v('B'),'foo');
g.removeEdge(it)}
Here is what the traversal says step-by-step:
g.V : iterate through all vertices
outE('foo') : iterate through their the outgoing 'foo' labeled edges
sideEffect{} : yield a sideEffect (mutate state)
g.addEdge(it.outVertex,g.v('B'),'foo'): add a new edge from the
vertex (e.g. C,D,E -- it.outVertex) to vertex B with label 'foo'.
g.removeEdge(it) : remove the current edge (it)
Note that its more optimal to do:
v = g.v('B');
g.V.outE('foo').sideEffect{g.addEdge(it.outVertex,v,'foo'); g.removeEdge(it)}
Also, vertex IDs are not Strings in Neo4j, but longs. Hopefully you can do what
you need from here.
Good luck,
Marko.
http://markorodriguez.com
On Aug 31, 2011, at 6:17 PM, Nuo Yan wrote:
> I want to update the ending node for all relationships that are type :foo
> coming into node A to node B.
>
> For example, for all relationships that are type :foo coming into node A
> (node A as the end node), no matter where their starting node is, I want
> them to set the end node to node B.
>
> Node C --:foo--> Node A
> Node D --:foo--> Node A
> Node E --:bar--> Node A
>
> would become:
>
> Node C --:foo--> Node B
> Node D --:foo -> Node B
> Node E --:bar--> Node A
>
> On Wed, Aug 31, 2011 at 5:00 PM, Marko Rodriguez <[email protected]>wrote:
>
>> Hi,
>>
>> If you tell me in English what you want to do, I can give you the Gremlin
>> query. With Gremlin, you can traverse and update in a single query so
>> perhaps it will meet your needs.
>>
>> Marko.
>>
>> http://markorodriguez.com
>>
>> On Aug 31, 2011, at 5:13 PM, Nuo Yan wrote:
>>
>>> I looked through the REST APIs and didn't see an endpoint to move
>>> relationships. Is such operation possible? For example, given a set of
>>> relationships all end in one node, I want to send a bulk request to
>> update
>>> their end nodes to another node.
>>>
>>> If there is no REST API for updating/moving relationship, what is the
>> best
>>> way to do this? Can gremlin do it easily? Or do I have to delete all of
>> the
>>> relationships and create new ones to the new end node?
>>>
>>> Thanks,
>>> Nuo
>>> _______________________________________________
>>> Neo4j mailing list
>>> [email protected]
>>> https://lists.neo4j.org/mailman/listinfo/user
>>
>> _______________________________________________
>> Neo4j mailing list
>> [email protected]
>> https://lists.neo4j.org/mailman/listinfo/user
>>
> _______________________________________________
> Neo4j mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user