Great! Thanks Marko, this has been very helpful.

I did realise my mistake on the sort: when I tried it the way you suggested
originally, I also had a few other things wrong, and obviously did not
apply a methodical approach to solving it.
One last question: I need to just return the nodes, at the end of all of
this. I figured I needed to do a projection of sorts, and the only thing I
could get working was a transform(), as follows:

m.sort{a,b -> a.value <=> b.value}._().transform(){a -> a.key}

Now, I remember in your first reply, you used things like "keyset" and "as
List", but I couldn't get that to work...

Any thoughts on this? I imagine it's probably safe to say there's a better
method to achieve this :)


 ----- A closed mouth gathers no feet...


On Mon, Nov 7, 2011 at 11:00 PM, Marko Rodriguez-2 [via Neo4j Community
Discussions] <ml-node+s438527n3488223...@n3.nabble.com> wrote:

> Hey,
>
> > I've played around a bit more, and this is the query that currently
> works
> > best for me... would anyone mind "reviewing" it for me please? Feels a
> > little like I'm getting the right answer, but the wrong way....
> > gremlin> m = [:];
> > gremlin> g.v(162).in('R_PartOf').loop(1){m.put(it.object, it.loops);
> true}
> > gremlin> m.sort{a -> a.value}._()
> >
> > And, that sort tripped me up a few times.... :)
>
> Everything looks good except your m.sort{}, which should be something like
> this:
>
>         m.sort{a,b -> a.value <=> b.value}
>
> The provided closure is a comparator. For a java.util.Map, the comparison
> is happening between two Map.Entry objects. Thus, your sort needs two
> inputs (a,b) and then the value of those Entry objects is a.value and
> b.value, respectively.
>
> Hope that is clear.
>
> *** Also, note that if you don't want to see output from your g.v(162)...
> expression, simply do >> -1 as it will while(expr.hasNext()) and thus, fill
> the map without burdensome System.out.println()s. ***
>
> Enjoy,
> Marko.
>
> _______________________________________________
> Neo4j mailing list
> [hidden email] <http://user/SendEmail.jtp?type=node&node=3488223&i=0>
> https://lists.neo4j.org/mailman/listinfo/user
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3488223.html
>  To unsubscribe from Gremlin - how to flatten a tree, and sort, click 
> here<http://neo4j-community-discussions.438527.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3480586&code=a2V2aW4udmVyc2ZlbGRAZ21haWwuY29tfDM0ODA1ODZ8LTE5MTM2MjYxMjE=>.
>
>


--
View this message in context: 
http://neo4j-community-discussions.438527.n3.nabble.com/Gremlin-how-to-flatten-a-tree-and-sort-tp3480586p3489554.html
Sent from the Neo4j Community Discussions mailing list archive at Nabble.com.
_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to