You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/08/16 23:48:47 UTC

tinkerpop git commit: more work on the document processor. it can now to traversal and non-traversal code lines in python.

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 640d4ccc7 -> a5ac35157


more work on the document processor. it can now to traversal and non-traversal code lines in python.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/a5ac3515
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/a5ac3515
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/a5ac3515

Branch: refs/heads/TINKERPOP-1278
Commit: a5ac35157d6c180dbdb7e54e83cc1d0e6acab887
Parents: 640d4cc
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Aug 16 17:48:44 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Aug 16 17:48:44 2016 -0600

----------------------------------------------------------------------
 docs/preprocessor/awk/init-code-blocks.awk   | 14 ++++++--
 docs/src/reference/gremlin-variants.asciidoc | 41 +++++++++++------------
 2 files changed, 30 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a5ac3515/docs/preprocessor/awk/init-code-blocks.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/init-code-blocks.awk b/docs/preprocessor/awk/init-code-blocks.awk
index 67f116c..4759a65 100644
--- a/docs/preprocessor/awk/init-code-blocks.awk
+++ b/docs/preprocessor/awk/init-code-blocks.awk
@@ -51,6 +51,7 @@ BEGIN {
   print ":set max-iteration 100"
   if (lang == "python") {
     print "import static javax.script.ScriptContext.*"
+    print "import org.apache.tinkerpop.gremlin.python.jsr223.PythonTranslator"
     print "jython = new org.apache.tinkerpop.gremlin.python.jsr223.GremlinJythonScriptEngine()"
     print "jython.eval('import os')"
     print "jython.eval('os.chdir(\"" TP_HOME "\")')"
@@ -69,6 +70,7 @@ BEGIN {
     print "jython.eval('statics.load_statics(globals())')"
     print "jythonBindings = jython.createBindings()"
     print "jythonBindings.put('g', jython.eval('RemoteGraph(None).traversal()'))"
+    print "jythonBindings.put('h', g)"
     print "jython.getContext().setBindings(jythonBindings, javax.script.ScriptContext.GLOBAL_SCOPE)"
     print "groovy = new org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine()"
     print "groovyBindings = groovy.createBindings()"
@@ -76,9 +78,15 @@ BEGIN {
     print "groovyBindings.put('TinkerGraphComputer', TinkerGraphComputer)"
     print "groovy.getContext().setBindings(groovyBindings, javax.script.ScriptContext.GLOBAL_SCOPE)"
     print "def processTraversal(t, jython, groovy) {"
-    print "  jython.getContext().getBindings(GLOBAL_SCOPE).put('j', jython.eval(t))"
-    print "  groovy.getContext().getBindings(GLOBAL_SCOPE).put('j', jython.eval('GraphSONWriter.writeObject(j)').toString())"
-    print "  return groovy.eval(groovy.eval('GroovyTranslator.of(\"g\").translate(GraphSONReader.build().create().mapper.readValue(j,Bytecode.class))').toString())"
+    print "  jython.getContext().getBindings(GLOBAL_SCOPE).put('j', jython.eval(t.replace('.toList()','')))"
+    print "  if(jython.eval('isinstance(j, Traversal)')) {"
+    print "    bytecode = GraphSONReader.build().create().mapper.readValue(jython.eval('GraphSONWriter.writeObject(j)').toString(), Bytecode.class)"
+    print "    language = BytecodeHelper.getLambdaLanguage(bytecode).orElse('gremlin-groovy')"
+    print "    return language.equals('gremlin-groovy') ? groovy.eval(GroovyTranslator.of(\"g\").translate(bytecode) + '.toList()').toString() : jython.eval(PythonTranslator.of(\"h\").translate(bytecode) + '.toList()').toString()"
+    print "  } else {"
+    print "    j = jython.getContext().getBindings(GLOBAL_SCOPE).get('j')"
+    print "    return null == j ? 'null' : j.toString()"
+    print "  }"
     print "}"
   }
   print "'-IGNORE'"

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a5ac3515/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 5c49d7b..1257c24 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -30,7 +30,7 @@ structure as best as possible given the constructs of the host language. A stron
 that the general Gremlin reference documentation is applicable to all variants and that users moving between development
 languages can easily adopt the Gremlin language variant for that language.
 
-image::gremlin-variant-architecture.png[width=600,float=left]
+image::gremlin-variant-architecture.png[width=650,float=left]
 
 NOTE: The information herein describes how to use the Gremlin language variants distributed
 with Apache TinkerPop. For information on how to build a Gremlin language variant,
@@ -59,6 +59,7 @@ pip install gremlin_python
 There are three primary classes distributed with Gremlin-Python: `GraphTraversalSource`, `GraphTraversal`, and `__`.
 
 [source,python]
+from gremlin_python import statics
 from gremlin_python.structure.remote_graph import RemoteGraph
 from gremlin_python.process.graph_traversal import GraphTraversalSource
 from gremlin_python.process.graph_traversal import GraphTraversal
@@ -114,9 +115,9 @@ makes traversals a bit more concise.
 
 [gremlin-python,modern]
 ----
-g.V().both()[1:3]
-g.V().both()[1]
-g.V().both().name
+g.V().both()[1:3].toList()
+g.V().both()[1].toList()
+g.V().both().name.toList()
 ----
 
 Static Enums and Methods
@@ -140,19 +141,19 @@ These can be used analogously to how they are used in Gremlin-Java.
 
 [gremlin-python,modern]
 ----
-g.V().hasLabel('person').has('age',P.gt(30)).order().by('age',Order.decr)
+g.V().hasLabel('person').has('age',P.gt(30)).order().by('age',Order.decr).toList()
 ----
 
 Moreover, by importing the `statics` of Gremlin-Python, the class prefixes can be removed.
 
 [source,python]
-gremlin_python.statics.load_statics(globals())
+statics.load_statics(globals())
 
 With statics loaded its possible to represent the above traversal as below.
 
 [gremlin-python,modern]
 ----
-g.V().hasLabel('person').has('age',gt(30)).order().by('age',decr)
+g.V().hasLabel('person').has('age',gt(30)).order().by('age',decr).toList()
 ----
 
 Finally, statics includes all the `__`-methods and thus, anonymous traversals like `__.out()` can be expressed as below.
@@ -160,7 +161,7 @@ That is, without the `__.`-prefix.
 
 [gremlin-python,modern]
 ----
-g.V().repeat(out()).times(2).name.fold()
+g.V().repeat(out()).times(2).name.fold().toList()
 ----
 
 RemoteConnection Bindings
@@ -175,8 +176,8 @@ In Gremlin-Python, bindings are 2-tuples and used as follows.
 
 [gremlin-python,modern]
 ----
-g.V(('id',1)).out('created').name
-g.V(('id',4)).out('created').name
+g.V(('id',1)).out('created').name.toList()
+g.V(('id',4)).out('created').name.toList()
 ----
 
 The Lambda Solution
@@ -187,20 +188,16 @@ As a simple solution, it is up to the Gremlin variant to decide lambdas (in any
 encoded in the standard `Bytecode` format. In Gremlin-Python, a link:https://docs.python.org/2/reference/expressions.html#lambda[Python lambda]
 should be a zero-arg callable that returns a string representation of a lambda. The default lambda language is `gremlin-jython`
 and can be changed via `statics.default_lambda_language.` When the lambda is represented in `Bytecode` its language is encoded
-such that the remote connection host can infer which translator to use.
+such that the remote connection host can infer which translator to use. A zero-arg lambda yields a string representation of a lambda in Gremlin-Jython.
+For example, `g.V().out().map(lambda: "lambda x: x.get().value('name').length()").sum().toList()`.
 
 [gremlin-python,modern]
 ----
-g.V().out().map(lambda: ("it.get().value('name').length()", "gremlin-groovy")).sum()
+g.V().out().map(lambda: ("it.get().value('name').length()", "gremlin-groovy")).sum().toList()
+statics.default_lambda_language = 'gremlin-groovy'
+g.V().out().map(lambda: "it.get().value('name').length()").sum().toList()
 ----
 
-A zero-arg lambda can yield a 2-tuple with the first element being the lambda script and second element being the lambda language.
-If the zero-arg lambda yields a string representation of a lambda (not a 2-tuple), then the language is assumed to be Gremlin-Jython.
-
-To change the default lambda language, update `gremlin_python.statics.default_lambda_language`.
-
-[source,python]
-g.V().out().map(lambda: "lambda x: x.get().value('name').length()").sum()
-gremlin_python.statics.default_lambda_language = "gremlin-groovy"
-g.V().out().map(lambda: "it.get().value('name').length()").sum()
-
+1. A zero-arg lambda yields 2-tuple where the second element is the lambda language.
+2. The default lambda language can be statically changed.
+3. A zero-arg lambda yields a string representation of a closure in Gremlin-Groovy.