Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 61A57200B0F for ; Fri, 17 Jun 2016 20:14:53 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 602EB160A61; Fri, 17 Jun 2016 18:14:53 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 821FB160A4C for ; Fri, 17 Jun 2016 20:14:52 +0200 (CEST) Received: (qmail 86762 invoked by uid 500); 17 Jun 2016 18:14:51 -0000 Mailing-List: contact commits-help@tinkerpop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.apache.org Delivered-To: mailing list commits@tinkerpop.apache.org Received: (qmail 86753 invoked by uid 99); 17 Jun 2016 18:14:51 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jun 2016 18:14:51 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9689CE049D; Fri, 17 Jun 2016 18:14:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: okram@apache.org To: commits@tinkerpop.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: tinkerpop git commit: simplified the awk script by using GroovyScriptEngine instead of GroovyShell. Added more documentaiton on RawExpression. Date: Fri, 17 Jun 2016 18:14:51 +0000 (UTC) archived-at: Fri, 17 Jun 2016 18:14:53 -0000 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 Authored: Fri Jun 17 12:14:46 2016 -0600 Committer: Marko A. Rodriguez 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()