Repository: tinkerpop Updated Branches: refs/heads/master c59526185 -> 523fb6dcf
Formatting fixes to recipes CTR Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/523fb6dc Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/523fb6dc Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/523fb6dc Branch: refs/heads/master Commit: 523fb6dcf28a4bb2f59e2536ebf490893ef2ffe6 Parents: c595261 Author: Stephen Mallette <sp...@genoprime.com> Authored: Fri Oct 14 14:33:05 2016 -0400 Committer: Stephen Mallette <sp...@genoprime.com> Committed: Fri Oct 14 14:33:05 2016 -0400 ---------------------------------------------------------------------- docs/src/recipes/between-vertices.asciidoc | 2 +- docs/src/recipes/centrality.asciidoc | 24 +++++----- docs/src/recipes/cycle-detection.asciidoc | 30 ++++++------- docs/src/recipes/pagination.asciidoc | 20 +++++---- docs/src/recipes/recommendation.asciidoc | 59 +++++++++++++++++-------- docs/src/recipes/shortest-path.asciidoc | 42 +++++++++--------- docs/src/recipes/tree.asciidoc | 12 +++-- 7 files changed, 108 insertions(+), 81 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523fb6dc/docs/src/recipes/between-vertices.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/recipes/between-vertices.asciidoc b/docs/src/recipes/between-vertices.asciidoc index 021e85b..f8814eb 100644 --- a/docs/src/recipes/between-vertices.asciidoc +++ b/docs/src/recipes/between-vertices.asciidoc @@ -19,7 +19,7 @@ Between Vertices ---------------- It is quite common to have a situation where there are two particular vertices of a graph and a need to execute some -traversal on the paths found between them. Consider the following examples: +traversal on the paths found between them. Consider the following examples using the modern toy graph: [gremlin-groovy,modern] ---- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523fb6dc/docs/src/recipes/centrality.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/recipes/centrality.asciidoc b/docs/src/recipes/centrality.asciidoc index eeee79d..cbce418 100644 --- a/docs/src/recipes/centrality.asciidoc +++ b/docs/src/recipes/centrality.asciidoc @@ -27,7 +27,7 @@ Degree Centrality ~~~~~~~~~~~~~~~~~ link:https://en.wikipedia.org/wiki/Centrality#Degree_centrality[Degree centrality] is a measure of the number of -edges associated to each vertex. +edges associated to each vertex. The following examples use the modern toy graph: [gremlin-groovy,modern] ---- @@ -67,15 +67,15 @@ image:betweeness-example.png[width=600] [gremlin-groovy ] ---- -a = graph.addVertex('name','a') -b = graph.addVertex('name','b') -c = graph.addVertex('name','c') -d = graph.addVertex('name','d') -e = graph.addVertex('name','e') -a.addEdge('next',b) -b.addEdge('next',c) -c.addEdge('next',d) -d.addEdge('next',e) +g.addV('name','a').as('a'). + addV('name','b').as('b'). + addV('name','c').as('c'). + addV('name','d').as('d'). + addV('name','e').as('e'). + addE('next').from('a').to('b'). + addE('next').from('b').to('c'). + addE('next').from('c').to('d'). + addE('next').from('d').to('e').iterate() g.withSack(0).V().store("x").repeat(both().simplePath()).emit().path(). <1> group().by(project("a","b").by(limit(local, 1)). <2> by(tail(local, 1))). @@ -84,7 +84,7 @@ g.withSack(0).V().store("x").repeat(both().simplePath()).emit().path(). <1> select("x").unfold().as("v"). <5> select("shortestPaths"). <6> map(unfold().filter(unfold().where(eq("v"))).count()). <7> - sack(sum).sack().as("betweeness"). <8> + sack(sum).sack().as("betweeness"). <8> select("v","betweeness") ---- @@ -110,7 +110,7 @@ Closeness Centrality ~~~~~~~~~~~~~~~~~~~~ link:https://en.wikipedia.org/wiki/Centrality[Closeness centrality] is a measure of the distance of one vertex to all -other reachable vertices in the graph. +other reachable vertices in the graph. The following examples use the modern toy graph: [gremlin-groovy,modern] ---- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523fb6dc/docs/src/recipes/cycle-detection.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/recipes/cycle-detection.asciidoc b/docs/src/recipes/cycle-detection.asciidoc index 864b760..1a8650b 100644 --- a/docs/src/recipes/cycle-detection.asciidoc +++ b/docs/src/recipes/cycle-detection.asciidoc @@ -25,19 +25,19 @@ image:graph-cycle.png[width=250] [gremlin-groovy] ---- -vA = graph.addVertex(id, 'a') -vB = graph.addVertex(id, 'b') -vC = graph.addVertex(id, 'c') -vD = graph.addVertex(id, 'd') -vA.addEdge("knows", vB) -vB.addEdge("knows", vC) -vC.addEdge("knows", vA) -vA.addEdge("knows", vD) -vC.addEdge("knows", vD) -g.V().as("a").repeat(out().simplePath()).times(2). - where(out().as("a")).path() <1> -g.V().as("a").repeat(out().simplePath()).times(2). - where(out().as("a")).path(). +g.addV(id,'a').as('a'). + addV(id,'b').as('b'). + addV(id,'c').as('c'). + addV(id,'d').as('d'). + addE('knows').from('a').to('b'). + addE('knows').from('b').to('c'). + addE('knows').from('c').to('a'). + addE('knows').from('a').to('d'). + addE('knows').from('c').to('d').iterate() +g.V().as('a').repeat(out().simplePath()).times(2). + where(out().as('a')).path() <1> +g.V().as('a').repeat(out().simplePath()).times(2). + where(out().as('a')).path(). dedup().by(unfold().order().by(id).dedup().fold()) <2> ---- @@ -55,7 +55,7 @@ arbitrary length over both incoming and outgoing edges in the modern graph? [gremlin-groovy,modern] ---- -g.V().as("a").repeat(both().simplePath()).emit(loops().is(gt(1))). - both().where(eq("a")).path(). +g.V().as('a').repeat(both().simplePath()).emit(loops().is(gt(1))). + both().where(eq('a')).path(). dedup().by(unfold().order().by(id).dedup().fold()) ---- \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523fb6dc/docs/src/recipes/pagination.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/recipes/pagination.asciidoc b/docs/src/recipes/pagination.asciidoc index 85f55c8..510a586 100644 --- a/docs/src/recipes/pagination.asciidoc +++ b/docs/src/recipes/pagination.asciidoc @@ -29,15 +29,17 @@ In Gremlin, a basic approach to paging would look something like the following: [gremlin-groovy,modern] ---- -g.V().hasLabel('person').fold() <1> -g.V().hasLabel('person').fold().as('persons','count'). - select('persons','count'). - by(range(local, 0, 2)). - by(count(local)) <2> -g.V().hasLabel('person').fold().as('persons','count'). - select('persons','count'). - by(range(local, 2, 4)). - by(count(local)) <3> +g.V().hasLabel('person').fold() <1> +g.V().hasLabel('person'). + fold().as('persons','count'). + select('persons','count'). + by(range(local, 0, 2)). + by(count(local)) <2> +g.V().hasLabel('person'). + fold().as('persons','count'). + select('persons','count'). + by(range(local, 2, 4)). + by(count(local)) <3> ---- <1> Gets all the "person" vertices. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523fb6dc/docs/src/recipes/recommendation.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/recipes/recommendation.asciidoc b/docs/src/recipes/recommendation.asciidoc index 81b2c96..8d5f1ec 100644 --- a/docs/src/recipes/recommendation.asciidoc +++ b/docs/src/recipes/recommendation.asciidoc @@ -133,7 +133,9 @@ g.V().has('person','name','alice').as('her'). <1> out('bought').aggregate('self'). <2> in('bought').where(neq('her')). <3> out('bought').where(without('self')). <4> - groupCount().order(local).by(values, decr) <5> + groupCount(). + order(local). + by(values, decr) <5> ---- <1> Find "alice" who is the person for whom the product recommendation is being made. @@ -164,7 +166,9 @@ Next, do some grouping to find count how many products they have in common: g.V().has("person","name","alice").as("alice"). out("bought").aggregate("self"). in("bought").where(neq("alice")).dedup(). - group().by().by(out("bought").where(within("self")).count()) + group(). + by().by(out("bought"). + where(within("self")).count()) ---- The above output shows that the best that can be expected is three common products. The traversal needs to be aware of @@ -175,9 +179,12 @@ that maximum: g.V().has("person","name","alice").as("alice"). out("bought").aggregate("self"). in("bought").where(neq("alice")).dedup(). - group().by().by(out("bought"). - where(within("self")).count()). - select(values).order(local).by(decr).limit(local, 1) + group(). + by().by(out("bought"). + where(within("self")).count()). + select(values). + order(local). + by(decr).limit(local, 1) ---- With the maximum value available, it can be used to chose those "person" vertices that have the three products in @@ -188,10 +195,14 @@ common: g.V().has("person","name","alice").as("alice"). out("bought").aggregate("self"). in("bought").where(neq("alice")).dedup(). - group().by().by(out("bought"). - where(within("self")).count()).as("g"). - select(values).order(local).by(decr).limit(local, 1).as("m"). - select("g").unfold().where(select(values).as("m")).select(keys) + group(). + by().by(out("bought"). + where(within("self")).count()).as("g"). + select(values). + order(local). + by(decr).limit(local, 1).as("m"). + select("g").unfold(). + where(select(values).as("m")).select(keys) ---- Now that there is a list of "person" vertices to base the recommendation on, traverse to the products that they @@ -202,10 +213,14 @@ purchased: g.V().has("person","name","alice").as("alice"). out("bought").aggregate("self"). in("bought").where(neq("alice")).dedup(). - group().by().by(out("bought"). - where(within("self")).count()).as("g"). - select(values).order(local).by(decr).limit(local, 1).as("m"). - select("g").unfold().where(select(values).as("m")).select(keys). + group(). + by().by(out("bought"). + where(within("self")).count()).as("g"). + select(values). + order(local). + by(decr).limit(local, 1).as("m"). + select("g").unfold(). + where(select(values).as("m")).select(keys). out("bought").where(without("self")) ---- @@ -216,10 +231,18 @@ The above output shows that one product is held in common making it the top reco g.V().has("person","name","alice").as("alice"). out("bought").aggregate("self"). in("bought").where(neq("alice")).dedup(). - group().by().by(out("bought"). - where(within("self")).count()).as("g"). - select(values).order(local).by(decr).limit(local, 1).as("m"). - select("g").unfold().where(select(values).as("m")).select(keys). + group(). + by().by(out("bought"). + where(within("self")).count()).as("g"). + select(values). + order(local). + by(decr).limit(local, 1).as("m"). + select("g").unfold(). + where(select(values).as("m")).select(keys). out("bought").where(without("self")). - groupCount().order(local).by(values, decr).by(select(keys).values("name")).unfold().select(keys).values("name") + groupCount(). + order(local). + by(values, decr). + by(select(keys).values("name")). + unfold().select(keys).values("name") ---- \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523fb6dc/docs/src/recipes/shortest-path.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/recipes/shortest-path.asciidoc b/docs/src/recipes/shortest-path.asciidoc index 933eebf..004bf1e 100644 --- a/docs/src/recipes/shortest-path.asciidoc +++ b/docs/src/recipes/shortest-path.asciidoc @@ -26,17 +26,16 @@ is a simple example that identifies the shortest path between vertex "1" and ver [gremlin-groovy] ---- -v1 = graph.addVertex(T.id, 1) -v2 = graph.addVertex(T.id, 2) -v3 = graph.addVertex(T.id, 3) -v4 = graph.addVertex(T.id, 4) -v5 = graph.addVertex(T.id, 5) -v1.addEdge("knows", v2) -v2.addEdge("knows", v4) -v4.addEdge("knows", v5) -v2.addEdge("knows", v3) -v3.addEdge("knows", v4) -g = graph.traversal() +g.addV(id, 1).as('1'). + addV(id, 2).as('2'). + addV(id, 3).as('3'). + addV(id, 4).as('4'). + addV(id, 5).as('5'). + addE('knows').from('1').to('2'). + addE('knows').from('2').to('4'). + addE('knows').from('4').to('5'). + addE('knows').from('2').to('3'). + addE('knows').from('3').to('4').iterate() g.V(1).repeat(out().simplePath()).until(hasId(5)).path().limit(1) <1> g.V(1).repeat(out().simplePath()).until(hasId(5)).path().count(local) <2> g.V(1).repeat(out().simplePath()).until(hasId(5)).path(). @@ -57,17 +56,16 @@ but includes a "weight" on the edges, that will be used to help determine the "c [gremlin-groovy] ---- -v1 = graph.addVertex(T.id, 1) -v2 = graph.addVertex(T.id, 2) -v3 = graph.addVertex(T.id, 3) -v4 = graph.addVertex(T.id, 4) -v5 = graph.addVertex(T.id, 5) -v1.addEdge("knows", v2, "weight", 1.25) -v2.addEdge("knows", v4, "weight", 1.5) -v4.addEdge("knows", v5, "weight", 0.25) -v2.addEdge("knows", v3, "weight", 0.25) -v3.addEdge("knows", v4, "weight", 0.25) -g = graph.traversal() +g.addV(id, 1).as('1'). + addV(id, 2).as('2'). + addV(id, 3).as('3'). + addV(id, 4).as('4'). + addV(id, 5).as('5'). + addE('knows').from('1').to('2').property('weight', 1.25). + addE('knows').from('2').to('4').property('weight', 1.5). + addE('knows').from('4').to('5').property('weight', 0.25). + addE('knows').from('2').to('3').property('weight', 0.25). + addE('knows').from('3').to('4').property('weight', 0.25).iterate() g.V(1).repeat(out().simplePath()).until(hasId(5)).path(). group().by(count(local)).next() <1> g.V(1).repeat(outE().inV().simplePath()).until(hasId(5)). http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/523fb6dc/docs/src/recipes/tree.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/recipes/tree.asciidoc b/docs/src/recipes/tree.asciidoc index 2297ccd..7069277 100644 --- a/docs/src/recipes/tree.asciidoc +++ b/docs/src/recipes/tree.asciidoc @@ -172,11 +172,15 @@ The Gremlin script below creates the graph depicted in the graph above: [gremlin-groovy] ---- g.addV(label, 'year', 'name', '2016').as('y2016'). - addV(label, 'month', 'name', 'may').as('m05').addV(label, 'month', 'name', 'june').as('m06'). - addV(label, 'day', 'name', '30').as('d30').addV(label, 'day', 'name', '31').as('d31'). + addV(label, 'month', 'name', 'may').as('m05'). + addV(label, 'month', 'name', 'june').as('m06'). + addV(label, 'day', 'name', '30').as('d30'). + addV(label, 'day', 'name', '31').as('d31'). addV(label, 'day', 'name', '01').as('d01'). - addV(label, 'event', 'name', 'A').as('eA').addV(label, 'event', 'name', 'B').as('eB'). - addV(label, 'event', 'name', 'C').as('eC').addV(label, 'event', 'name', 'D').as('eD'). + addV(label, 'event', 'name', 'A').as('eA'). + addV(label, 'event', 'name', 'B').as('eB'). + addV(label, 'event', 'name', 'C').as('eC'). + addV(label, 'event', 'name', 'D').as('eD'). addV(label, 'event', 'name', 'E').as('eE'). addE('may').from('y2016').to('m05'). addE('june').from('y2016').to('m06').