Nuo,
In principle this looks ok except you will have to take care that you are
not deleting nodes that are in the current traversal and would recursively
change your traversal result.

Dunno the Groovy expression for this, but if you can do it in Java, you can
do it in Groovy, for instance
http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html#rest-api-send-an-arbitrary-groovy-script---lucene-sorting


HTH

/peter

On Friday, October 21, 2011, Nuo Yan <[email protected]> wrote:
> Hi Marko and Gremlin gurus:
>
> Currently I'm doing the following in my own code with multiple requests to
> the standalone neo4j server. I wonder if it's possible to achieve in one
> gremlin query/script so that I can post the gremlin query to the server as
1
> request and done. What I'm trying to achieve is:
>
> Start from one given node (e.g. v1), get all of the nodes connected
through
> a given type of relationship (e.g. relationship "foo"), within all of
these
> nodes, see if their "name" property has the same value, and if so, delete
> the node (and the "foo" relationship connected to it) with smaller
outgoing
> degree (on a specific type of relationship, say, "bar"). If there are more
> than two nodes with the same "name" property, only keep the one with
biggest
> outgoing degree (on type "bar").
>
>
> For example, for the following graph:
>
> v1 --foo--> v2("name" => "abc") --"bar"--> (15 nodes)
> v1 --foo--> v3("name" => "abc") --"bar"--> (5 nodes)
> v1 --foo--> v4("name" => "abc") --"bar"--> (8 nodes)
> v1 --foo--> v5("name" => "xyz")--"bar"-->(16 nodes)
> v1 --foo--> v6("name" => "abc")--"not_bar"--> (20 nodes)
>
> Ideally, after running the gremlin script, it should be:
>
> v1 --foo--> v2("name" => "abc") --"bar"--> (15 nodes)
> v1 --foo--> v5("name" => "xyz")--"bar"-->(16 nodes)
> v1 --foo--> v6("name" => "abc")--"not_bar"--> (20 nodes)
>
> with v3 and v4 (and the "foo" relationships connecting them to v1) deleted
> because they have the same "name" attributes with v2 but a smaller degree
> with outgoing "bar" relationship.
>
> It this possible to achieve relatively easily with Gremlin?
> _______________________________________________
> Neo4j mailing list
> [email protected]
> https://lists.neo4j.org/mailman/listinfo/user
>

-- 
Sent from Gmail Mobile
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to