Added more content to traversal induced value recipe
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e1d5b686 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e1d5b686 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e1d5b686 Branch: refs/heads/TINKERPOP-1600 Commit: e1d5b686172aa4caed3429adf04802fb3ef62a07 Parents: 6dba5ec Author: Stephen Mallette <sp...@genoprime.com> Authored: Fri Jan 6 11:48:40 2017 -0500 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Fri Jan 6 11:48:40 2017 -0500 ---------------------------------------------------------------------- .../recipes/traversal-induced-values.asciidoc | 49 +++++++++++++++++++ docs/static/images/eulerian-circuit.png | Bin 0 -> 25270 bytes .../images/traversal-induced-values-1.png | Bin 0 -> 12607 bytes .../images/traversal-induced-values-2.png | Bin 0 -> 40440 bytes .../images/traversal-induced-values-3.png | Bin 0 -> 49652 bytes 5 files changed, 49 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e1d5b686/docs/src/recipes/traversal-induced-values.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/recipes/traversal-induced-values.asciidoc b/docs/src/recipes/traversal-induced-values.asciidoc index e292e16..03affbe 100644 --- a/docs/src/recipes/traversal-induced-values.asciidoc +++ b/docs/src/recipes/traversal-induced-values.asciidoc @@ -56,6 +56,55 @@ g.V().has('name','marko').as('marko'). <1> <3> Continue to traverser only if Marko's current friend is older than him. <4> Get the name of Marko's older friend. +As another example of how traversal induced values can be used, consider a scenario where there was a graph that +contained people, their friendship relationships, and the movies that they liked. + +image:traversal-induced-values-3.png[width=600] + +[gremlin-groovy] +---- +g.addV("name", "alice", label, "user").as("u1"). + addV("name", "jen", label, "user").as("u2"). + addV("name", "dave", label, "user").as("u3"). + addV("name", "the wild bunch", label, "movie").as("m1"). + addV("name", "young guns", label, "movie").as("m2"). + addV("name", "unforgiven", label, "movie").as("m3"). + addE("friend").from("u1").to("u2"). + addE("friend").from("u1").to("u3"). + addE("like").from("u2").to("m1"). + addE("like").from("u2").to("m2"). + addE("like").from("u3").to("m2"). + addE("like").from("u3").to("m3").iterate() +---- + +Getting a list of all the movies that Alice's friends like could be done like this: + +[gremlin-groovy,existing] +---- +g.V().has('name','alice').out("friend").out("like").values("name") +---- + +but what if there was a need to get a list of movies that *all* her Alice's friends liked. In this case, that would +mean filtering out "the wild bunch" and "unforgiven". + +[gremlin-groovy,existing] +---- +g.V().has("name","alice"). + out("friend").aggregate("friends"). <1> + out("like").dedup(). <2> + filter(__.in("like").where(within("friends")).count().as("a"). <3> + select("friends").count(local).where(eq("a"))). <4> + values("name") +---- + +<1> Gather Alice's list of friends to a list called "friends". +<2> Traverse to the unique list of movies that Alice's friends like. +<3> Remove movies that weren't liked by all friends. This starts by taking each movie and traversing back in on the +"like" edges to friends who liked the movie (note the use of `where(within("friends"))` to limit those likes to only +Alice's friends as aggregated in step one) and count them up into "a". +<4> Count the aggregated friends and see if the number matches what was stored in "a" which would mean that all friends +like the movie. + Traversal induced values are not just for filtering. They can also be used when writing the values of the properties of one `Vertex` to another: http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e1d5b686/docs/static/images/eulerian-circuit.png ---------------------------------------------------------------------- diff --git a/docs/static/images/eulerian-circuit.png b/docs/static/images/eulerian-circuit.png new file mode 100755 index 0000000..d75674f Binary files /dev/null and b/docs/static/images/eulerian-circuit.png differ http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e1d5b686/docs/static/images/traversal-induced-values-1.png ---------------------------------------------------------------------- diff --git a/docs/static/images/traversal-induced-values-1.png b/docs/static/images/traversal-induced-values-1.png new file mode 100755 index 0000000..3dc1eea Binary files /dev/null and b/docs/static/images/traversal-induced-values-1.png differ http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e1d5b686/docs/static/images/traversal-induced-values-2.png ---------------------------------------------------------------------- diff --git a/docs/static/images/traversal-induced-values-2.png b/docs/static/images/traversal-induced-values-2.png new file mode 100755 index 0000000..cd17c55 Binary files /dev/null and b/docs/static/images/traversal-induced-values-2.png differ http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e1d5b686/docs/static/images/traversal-induced-values-3.png ---------------------------------------------------------------------- diff --git a/docs/static/images/traversal-induced-values-3.png b/docs/static/images/traversal-induced-values-3.png new file mode 100755 index 0000000..8e8c4b5 Binary files /dev/null and b/docs/static/images/traversal-induced-values-3.png differ