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/06/17 18:14:51 UTC

tinkerpop git commit: simplified the awk script by using GroovyScriptEngine instead of GroovyShell. Added more documentaiton on RawExpression.

Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1278 605c67cb8 -> e5937a06c


simplified the awk script by using GroovyScriptEngine instead of GroovyShell. Added more documentaiton on RawExpression.


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

Branch: refs/heads/TINKERPOP-1278
Commit: e5937a06ceed394c6f00920acf32307431b06b13
Parents: 605c67c
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Jun 17 12:14:46 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Jun 17 12:14:46 2016 -0600

----------------------------------------------------------------------
 docs/preprocessor/awk/init-code-blocks.awk       | 19 ++++++-------------
 docs/preprocessor/awk/language-variants.awk      |  2 +-
 docs/src/reference/gremlin-variants.asciidoc     | 13 +++++++++++--
 .../jython/gremlin_python/groovy_translator.py   |  3 +--
 4 files changed, 19 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e5937a06/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 a413de9..d5a1de8 100644
--- a/docs/preprocessor/awk/init-code-blocks.awk
+++ b/docs/preprocessor/awk/init-code-blocks.awk
@@ -88,18 +88,11 @@ BEGIN {
     print "jythonBindings = new SimpleBindings()"
     print "jythonBindings.put('g', jython.eval('PythonGraphTraversalSource(GroovyTranslator(\"g\"))'))"
     print "jython.getContext().setBindings(jythonBindings, javax.script.ScriptContext.GLOBAL_SCOPE)"
-    print "sharedData = new Binding()"
-    print "sharedData.setProperty('g', g)"
-    print "sharedData.setProperty('__', __)"
-    print "sharedData.setProperty('T', T)"
-    print "sharedData.setProperty('Order', Order)"
-    print "sharedData.setProperty('Column', Column)"
-    print "sharedData.setProperty('Direction', Direction)"
-    print "sharedData.setProperty('Operator', Operator)"
-    print "sharedData.setProperty('P', P)"
-    print "sharedData.setProperty('Pop', Pop)"
-    print "sharedData.setProperty('Scope', Scope)"
-    print "shell = new GroovyShell(sharedData)"
+    print "groovyBindings = new SimpleBindings()"
+    print "groovyBindings.put('g', g)"
+    print "groovyBindings.put('TinkerGraphComputer', TinkerGraphComputer)"
+    print "groovy = new org.apache.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine()"
+    print "groovy.getContext().setBindings(groovyBindings, javax.script.ScriptContext.GLOBAL_SCOPE)"
   }
   print "'-IGNORE'"
 }
@@ -108,7 +101,7 @@ BEGIN {
   if (delimiter == 2 && !($0 ~ /^pb\([0-9]*\); '----'/)) {
     switch (lang) {
       case "python":
-        print "shell.evaluate jython.eval(\"\"\"" $0 "\"\"\").toString()"
+        print "groovy.eval jython.eval(\"\"\"" $0 "\"\"\").toString()"
         break
       default:
         print

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e5937a06/docs/preprocessor/awk/language-variants.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/language-variants.awk b/docs/preprocessor/awk/language-variants.awk
index e89d057..1d69c48 100644
--- a/docs/preprocessor/awk/language-variants.awk
+++ b/docs/preprocessor/awk/language-variants.awk
@@ -39,7 +39,7 @@ BEGIN {
       case "python":
         gsub(/^gremlin>/, ">>>")
         gsub(/^==>/, "")
-        print gensub(/shell.evaluate jython.eval\("""(.*)"""\).toString\(\)/, "\\1", 1)
+        print gensub(/groovy.eval jython.eval\("""(.*)"""\).toString\(\)/, "\\1", 1)
         break
       default:
         print

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e5937a06/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index c2166eb..8c6fd97 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -204,7 +204,7 @@ ultimately concatenated together by the `Translator`. Like lambdas, `RawExpressi
 translator and now the host language and thus, a `RawExpression` used for Gremlin-Groovy execution may not work
 for Gremlin-Jython.
 
-The following example uses `RawExpression` to call the `Geoshape.point` static constructor method on the `Geoshape`
+The following example uses `RawExpression` to call the `Geoshape.point()` static constructor method on the `Geoshape`
 class provided by Aurelius' link:http://titan.thinkaurelius.com/[Titan] graph database.
 
 [source,python]
@@ -215,7 +215,7 @@ g.V().has('location', RawExpression('Geoshape.point(', ('x', 45), ', ', ('y', -4
 Note that both `x` and `y` are `RemoteConnection` bindings with values 45 and -45 respectively.
 
 To help readability, especially if an expression will be used more than once, it is recommended that a helper class be
-created. Again, note that this helper class is tied to GroovyTranslator as its `point()` `RawExpression` return is
+created. Again, note that this helper class is tied to `GroovyTranslator` as its `point()` `RawExpression` return is
 tied to the the underlying execution language.
 
 [source,python]
@@ -240,3 +240,12 @@ Or, without using bindings:
 g.V().has('location', Geoshape.point(45,-45))
 ----
 
+Finally, `RawExpressions` are useful when adding or removing a `TraversalStrategy` from the `GraphTraversalSource` as
+they typically have Java-based APIs. Again, respective Python classes that yield `RawExpressions` can be used to make
+their use more readable.
+
+[gremlin-python,modern]
+----
+g.withComputer(RawExpression('compute(TinkerGraphComputer)')).V().pageRank().by('rank').valueMap('name','rank')
+----
+

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e5937a06/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py b/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py
index 2e30841..e3908a3 100644
--- a/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py
+++ b/gremlin-variant/src/main/jython/gremlin_python/groovy_translator.py
@@ -80,8 +80,7 @@ class GroovyTranslator(Translator):
     @staticmethod
     def stringOrObject(arg):
         if (isinstance(arg, str) and
-                not (arg.startswith("Computer.")) and
-                not (arg.startswith("ReadOnlyStrategy."))):
+                not (arg.startswith("Computer."))):
             return "\"" + arg + "\""
         elif isinstance(arg, bool):
             return str(arg).lower()