Hi,
>> 9, i'm not sure if it's trival: find out users who are only 2
>> relationships a way (use twitter example: my followees' followers),
>> live in same city, group by age and gender. also retrieve all their
>> followees. i want to do the traversal in java, where can i find an
>> examples?
If you use Gremlin, then you can do your query as follows:
age = [:]
gender = [:]
people = g.v(1).out('livesIn').sideEffect{city =
it}.back(2).out.out.filter{it.out('livesIn').next().equals(city)}.groupCount(age){it.age}.groupCount(gender){it.gender}
>> []
NOTE: This is a Gremlin 1.2+ query (so use Neo4j 1.5M01).
The query says this:
1. create an empty hash map called age
2. create an empty hash map called gender
3. main traversal
- start from vertex 1
- determine what city vertex 1 lives in
- save that city vertex to the variable city
- go back to vertex 1 (back(2) means go back 2 steps ago)
- go down 2 relationships -- (could be both.both if you are
doing undirected)
- filter out those vertices that do not live in the same city
as vertex 1
- index those vertices ages into the age hash map with the
values being the distribution of ages.
- index those vertices genders into the gender hash map with
the values being the distribution of genders.
- insert those vertices into an empty list and save the
reference to people.
Thus, your results are:
people : the people that meat the traversal description
age : their ages as a distribution (count)
gender: their genders as a distribution (count)
As Peter says, you can do this in native Java (instead of Groovy) if you want
using FluentPipeline, but that is still in SNAPSHOT over at TinkerPop and will
not be released for about a month.
Good luck with your project,
Marko.
http://markorodriguez.com
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user