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/01 20:29:20 UTC
[2/3] incubator-tinkerpop git commit: More cleanup...
gremlin-python-3.2.1-SNAPSHOT.py is published to
gremlin-variant/variants/python/ directory for easy access by users.
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/487d992e/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversal.java b/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversal.java
new file mode 100644
index 0000000..0245d5a
--- /dev/null
+++ b/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversal.java
@@ -0,0 +1,968 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.process.variant;
+
+import org.apache.tinkerpop.gremlin.process.computer.VertexProgram;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
+import org.apache.tinkerpop.gremlin.structure.Column;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
+import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
+
+import javax.script.Bindings;
+import javax.script.ScriptEngine;
+import javax.script.SimpleBindings;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiFunction;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class VariantGraphTraversal<S, E> extends DefaultGraphTraversal<S, E> {
+
+
+ public StringBuilder variantString;
+ protected VariantConverter variantConverter;
+
+ public VariantGraphTraversal(final Graph graph, final StringBuilder variantString, final VariantConverter variantConverter) {
+ super(graph);
+ this.variantConverter = variantConverter;
+ this.variantString = variantString;
+ __.EMPTY_GRAPH_TRAVERSAL = () -> {
+ final StringBuilder builder = new StringBuilder("__");
+ return new VariantGraphTraversal<>(EmptyGraph.instance(), builder, this.variantConverter);
+ };
+ }
+
+ public StringBuilder getVariantString() {
+ return this.variantString;
+ }
+
+ public String toString() {
+ return this.steps.isEmpty() ? this.variantString.toString() : super.toString();
+ }
+
+ @Override
+ public void applyStrategies() {
+ if (!(this.getParent() instanceof EmptyStep)) {
+ return;
+ }
+ try {
+ final String jythonString = this.variantConverter.generateGremlinGroovy(this.variantString);
+ __.EMPTY_GRAPH_TRAVERSAL = DefaultGraphTraversal::new;
+ ScriptEngine groovy = ScriptEngineCache.get("gremlin-groovy");
+ final Bindings groovyBindings = new SimpleBindings();
+ groovyBindings.put("g", new GraphTraversalSource(this.getGraph().get(), this.getStrategies()));
+ Traversal.Admin<S, E> traversal = (Traversal.Admin<S, E>) groovy.eval(jythonString, groovyBindings);
+ assert !traversal.isLocked();
+ this.sideEffects = traversal.getSideEffects();
+ this.strategies = traversal.getStrategies();
+ traversal.getSteps().forEach(step -> this.addStep(step));
+ super.applyStrategies();
+ } catch (final Exception e) {
+ throw new IllegalArgumentException(e.getMessage(), e);
+ }
+ }
+
+ private static String getMethodName() {
+ return Thread.currentThread().getStackTrace()[2].getMethodName();
+ }
+
+ //////////////////////////
+
+ public <E2> GraphTraversal<S, E2> map(final Function<Traverser<E>, E2> function) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), function);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> map(final Traversal<?, E2> mapTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), mapTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> flatMap(final Function<Traverser<E>, Iterator<E2>> function) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), function);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> flatMap(final Traversal<?, E2> flatMapTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), flatMapTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Object> id() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, String> label() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> identity() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> constant(final E2 e) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), e);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> V(final Object... vertexIdsOrElements) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), vertexIdsOrElements);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> to(final Direction direction, final String... edgeLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), direction, edgeLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> out(final String... edgeLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), edgeLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> in(final String... edgeLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), edgeLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> both(final String... edgeLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), edgeLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Edge> toE(final Direction direction, final String... edgeLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), direction, edgeLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Edge> outE(final String... edgeLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), edgeLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Edge> inE(final String... edgeLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), edgeLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Edge> bothE(final String... edgeLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), edgeLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> toV(final Direction direction) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), direction);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> inV() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> outV() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> bothV() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> otherV() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> order() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> order(final Scope scope) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, ? extends Property<E2>> properties(final String... propertyKeys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKeys);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> values(final String... propertyKeys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKeys);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, Map<String, E2>> propertyMap(final String... propertyKeys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKeys);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, Map<String, E2>> valueMap(final String... propertyKeys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKeys);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, Map<String, E2>> valueMap(final boolean includeTokens, final String... propertyKeys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), includeTokens, propertyKeys);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, Collection<E2>> select(final Column column) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), column);
+ return (GraphTraversal) this;
+ }
+
+ @Deprecated
+ public <E2> GraphTraversal<S, E2> mapValues() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ @Deprecated
+ public <E2> GraphTraversal<S, E2> mapKeys() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, String> key() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> value() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Path> path() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, Map<String, E2>> match(final Traversal<?, ?>... matchTraversals) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), matchTraversals);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> sack() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Integer> loops() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, Map<String, E2>> project(final String projectKey, final String... otherProjectKeys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), projectKey, otherProjectKeys);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, Map<String, E2>> select(final Pop pop, final String selectKey1, final String selectKey2, String... otherSelectKeys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), pop, selectKey1, selectKey2, otherSelectKeys);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, Map<String, E2>> select(final String selectKey1, final String selectKey2, String... otherSelectKeys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), selectKey1, selectKey2, otherSelectKeys);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> select(final Pop pop, final String selectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), pop, selectKey);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> select(final String selectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), selectKey);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> unfold() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, List<E>> fold() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> fold(final E2 seed, final BiFunction<E2, E, E2> foldFunction) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), seed, foldFunction);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Long> count() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Long> count(final Scope scope) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope);
+ return (GraphTraversal) this;
+ }
+
+ public <E2 extends Number> GraphTraversal<S, E2> sum() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <E2 extends Number> GraphTraversal<S, E2> sum(final Scope scope) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope);
+ return (GraphTraversal) this;
+ }
+
+ public <E2 extends Number> GraphTraversal<S, E2> max() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <E2 extends Number> GraphTraversal<S, E2> max(final Scope scope) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope);
+ return (GraphTraversal) this;
+ }
+
+ public <E2 extends Number> GraphTraversal<S, E2> min() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <E2 extends Number> GraphTraversal<S, E2> min(final Scope scope) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope);
+ return (GraphTraversal) this;
+ }
+
+ public <E2 extends Number> GraphTraversal<S, E2> mean() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <E2 extends Number> GraphTraversal<S, E2> mean(final Scope scope) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope);
+ return (GraphTraversal) this;
+ }
+
+ public <K, V> GraphTraversal<S, Map<K, V>> group() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ @Deprecated
+ public <K, V> GraphTraversal<S, Map<K, V>> groupV3d0() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public <K> GraphTraversal<S, Map<K, Long>> groupCount() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Tree> tree() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> addV(final String vertexLabel) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), vertexLabel);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Vertex> addV() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ @Deprecated
+ public GraphTraversal<S, Vertex> addV(final Object... propertyKeyValues) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKeyValues);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Edge> addE(final String edgeLabel) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), edgeLabel);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> to(final String toStepLabel) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), toStepLabel);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> from(final String fromStepLabel) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), fromStepLabel);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> to(final Traversal<E, Vertex> toVertex) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), toVertex);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> from(final Traversal<E, Vertex> fromVertex) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), fromVertex);
+ return (GraphTraversal) this;
+ }
+
+ @Deprecated
+ public GraphTraversal<S, Edge> addE(final Direction direction, final String firstVertexKeyOrEdgeLabel, final String edgeLabelOrSecondVertexKey, final Object... propertyKeyValues) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), direction, firstVertexKeyOrEdgeLabel, edgeLabelOrSecondVertexKey, propertyKeyValues);
+ return (GraphTraversal) this;
+ }
+
+ @Deprecated
+ public GraphTraversal<S, Edge> addOutE(final String firstVertexKeyOrEdgeLabel, final String edgeLabelOrSecondVertexKey, final Object... propertyKeyValues) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), firstVertexKeyOrEdgeLabel, edgeLabelOrSecondVertexKey, propertyKeyValues);
+ return (GraphTraversal) this;
+ }
+
+ @Deprecated
+ public GraphTraversal<S, Edge> addInE(final String firstVertexKeyOrEdgeLabel, final String edgeLabelOrSecondVertexKey, final Object... propertyKeyValues) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), firstVertexKeyOrEdgeLabel, edgeLabelOrSecondVertexKey, propertyKeyValues);
+ return (GraphTraversal) this;
+ }
+
+ ///////////////////// FILTER STEPS /////////////////////
+
+ public GraphTraversal<S, E> filter(final Predicate<Traverser<E>> predicate) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), predicate);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> filter(final Traversal<?, ?> filterTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), filterTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> or(final Traversal<?, ?>... orTraversals) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), orTraversals);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> and(final Traversal<?, ?>... andTraversals) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), andTraversals);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> inject(final E... injections) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), injections);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> dedup(final Scope scope, final String... dedupLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope, dedupLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> dedup(final String... dedupLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), dedupLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> where(final String startKey, final P<String> predicate) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), startKey, predicate);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> where(final P<String> predicate) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), predicate);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> where(final Traversal<?, ?> whereTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), whereTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> has(final String propertyKey, final P<?> predicate) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKey, predicate);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> has(final T accessor, final P<?> predicate) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), accessor, predicate);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> has(final String propertyKey, final Object value) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKey, value);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> has(final T accessor, final Object value) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), accessor, value);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> has(final String label, final String propertyKey, final P<?> predicate) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), label, propertyKey, predicate);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> has(final String label, final String propertyKey, final Object value) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), label, propertyKey, value);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> has(final T accessor, final Traversal<?, ?> propertyTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), accessor, propertyTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> has(final String propertyKey, final Traversal<?, ?> propertyTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKey, propertyTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> has(final String propertyKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> hasNot(final String propertyKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), propertyKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> hasLabel(final String... labels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), labels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> hasId(final Object... ids) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), ids);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> hasKey(final String... keys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), keys);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> hasValue(final Object... values) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), values);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> is(final P<E> predicate) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), predicate);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> is(final Object value) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), value);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> not(final Traversal<?, ?> notTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), notTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> coin(final double probability) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), probability);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> range(final long low, final long high) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), low, high);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> range(final Scope scope, final long low, final long high) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope, low, high);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> limit(final long limit) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), limit);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> limit(final Scope scope, final long limit) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope, limit);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> tail() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> tail(final long limit) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), limit);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> tail(final Scope scope) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> tail(final Scope scope, final long limit) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope, limit);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> timeLimit(final long timeLimit) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), timeLimit);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> simplePath() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> cyclicPath() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> sample(final int amountToSample) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), amountToSample);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> sample(final Scope scope, final int amountToSample) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), scope, amountToSample);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> drop() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ ///////////////////// SIDE-EFFECT STEPS /////////////////////
+
+ public GraphTraversal<S, E> sideEffect(final Consumer<Traverser<E>> consumer) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), consumer);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> sideEffect(final Traversal<?, ?> sideEffectTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> cap(final String sideEffectKey, final String... sideEffectKeys) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectKey, sideEffectKeys);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, Edge> subgraph(final String sideEffectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> aggregate(final String sideEffectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> group(final String sideEffectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> groupV3d0(final String sideEffectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> groupCount(final String sideEffectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> tree(final String sideEffectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectKey);
+ return (GraphTraversal) this;
+ }
+
+ public <V, U> GraphTraversal<S, E> sack(final BiFunction<V, U, V> sackOperator) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sackOperator);
+ return (GraphTraversal) this;
+ }
+
+
+ @Deprecated
+ public <V, U> GraphTraversal<S, E> sack(final BiFunction<V, U, V> sackOperator, final String elementPropertyKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sackOperator, elementPropertyKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> store(final String sideEffectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> profile(final String sideEffectKey) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), sideEffectKey);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> property(final VertexProperty.Cardinality cardinality, final Object key, final Object value, final Object... keyValues) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), cardinality, key, value, keyValues);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> property(final Object key, final Object value, final Object... keyValues) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), key, value, keyValues);
+ return (GraphTraversal) this;
+ }
+
+ ///////////////////// BRANCH STEPS /////////////////////
+
+ public <M, E2> GraphTraversal<S, E2> branch(final Traversal<?, M> branchTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), branchTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public <M, E2> GraphTraversal<S, E2> branch(final Function<Traverser<E>, M> function) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), function);
+ return (GraphTraversal) this;
+ }
+
+ public <M, E2> GraphTraversal<S, E2> choose(final Traversal<?, M> choiceTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), choiceTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> choose(final Traversal<?, ?> traversalPredicate,
+ final Traversal<?, E2> trueChoice, final Traversal<?, E2> falseChoice) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), traversalPredicate, trueChoice, falseChoice);
+ return (GraphTraversal) this;
+ }
+
+ public <M, E2> GraphTraversal<S, E2> choose(final Function<E, M> choiceFunction) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), choiceFunction);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> choose(final Predicate<E> choosePredicate,
+ final Traversal<?, E2> trueChoice, final Traversal<?, E2> falseChoice) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), choosePredicate, trueChoice, falseChoice);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> optional(final Traversal<?, E2> optionalTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), optionalTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> union(final Traversal<?, E2>... unionTraversals) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), unionTraversals);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> coalesce(final Traversal<?, E2>... coalesceTraversals) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), coalesceTraversals);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> repeat(final Traversal<?, E> repeatTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), repeatTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> emit(final Traversal<?, ?> emitTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), emitTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> emit(final Predicate<Traverser<E>> emitPredicate) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), emitPredicate);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> emit() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> until(final Traversal<?, ?> untilTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), untilTraversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> until(final Predicate<Traverser<E>> untilPredicate) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), untilPredicate);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> times(final int maxLoops) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), maxLoops);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E2> local(final Traversal<?, E2> localTraversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), localTraversal);
+ return (GraphTraversal) this;
+ }
+
+ /////////////////// VERTEX PROGRAM STEPS ////////////////
+
+ public GraphTraversal<S, E> pageRank() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> pageRank(final double alpha) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), alpha);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> peerPressure() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> program(final VertexProgram<?> vertexProgram) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), vertexProgram);
+ return (GraphTraversal) this;
+ }
+
+ ///////////////////// UTILITY STEPS /////////////////////
+
+ public GraphTraversal<S, E> as(final String stepLabel, final String... stepLabels) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), stepLabel, stepLabels);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> barrier() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> barrier(final int maxBarrierSize) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), maxBarrierSize);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> barrier(final Consumer<TraverserSet<Object>> barrierConsumer) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), barrierConsumer);
+ return (GraphTraversal) this;
+ }
+
+
+ //// BY-MODULATORS
+
+ public GraphTraversal<S, E> by() {
+ this.variantConverter.addStep(this.variantString, getMethodName());
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> by(final Traversal<?, ?> traversal) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), traversal);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> by(final T token) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), token);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> by(final String key) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), key);
+ return (GraphTraversal) this;
+ }
+
+ public <V> GraphTraversal<S, E> by(final Function<V, Object> function) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), function);
+ return (GraphTraversal) this;
+ }
+
+ //// COMPARATOR BY-MODULATORS
+
+ public <V> GraphTraversal<S, E> by(final Traversal<?, ?> traversal, final Comparator<V> comparator) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), traversal, comparator);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> by(final Comparator<E> comparator) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), comparator);
+ return (GraphTraversal) this;
+ }
+
+ public GraphTraversal<S, E> by(final Order order) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), order);
+ return (GraphTraversal) this;
+ }
+
+ public <V> GraphTraversal<S, E> by(final String key, final Comparator<V> comparator) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), key, comparator);
+ return (GraphTraversal) this;
+ }
+
+ public <U> GraphTraversal<S, E> by(final Function<U, Object> function, final Comparator comparator) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), function, comparator);
+ return (GraphTraversal) this;
+ }
+
+ ////
+
+ public <M, E2> GraphTraversal<S, E> option(final M pickToken, final Traversal<E, E2> traversalOption) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), pickToken, traversalOption);
+ return (GraphTraversal) this;
+ }
+
+ public <E2> GraphTraversal<S, E> option(final Traversal<E, E2> traversalOption) {
+ this.variantConverter.addStep(this.variantString, getMethodName(), traversalOption);
+ return (GraphTraversal) this;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/487d992e/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversalSource.java
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversalSource.java b/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversalSource.java
new file mode 100644
index 0000000..9e4382f
--- /dev/null
+++ b/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/VariantGraphTraversalSource.java
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.process.variant;
+
+import org.apache.tinkerpop.gremlin.process.computer.Computer;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStartStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Transaction;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+
+import java.util.function.BinaryOperator;
+import java.util.function.Supplier;
+import java.util.function.UnaryOperator;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class VariantGraphTraversalSource extends GraphTraversalSource {
+
+ private VariantConverter variantConverter;
+ private StringBuilder sourceString = new StringBuilder("g");
+
+ public VariantGraphTraversalSource(final VariantConverter variantConverter, final Graph graph, final TraversalStrategies traversalStrategies) {
+ super(graph, traversalStrategies);
+ this.variantConverter = variantConverter;
+ }
+
+ private static String getMethodName() {
+ return Thread.currentThread().getStackTrace()[2].getMethodName();
+ }
+
+ ///
+
+ @Override
+ public GraphTraversal<Edge, Edge> E(final Object... edgeIds) {
+ final StringBuilder temp = new StringBuilder(this.sourceString.toString());
+ this.variantConverter.addStep(temp, getMethodName(), edgeIds);
+ return new VariantGraphTraversal<>(this.getGraph(), temp, this.variantConverter);
+ }
+
+ @Override
+ public GraphTraversal<Vertex, Vertex> V(final Object... vertexIds) {
+ final StringBuilder temp = new StringBuilder(this.sourceString.toString());
+ this.variantConverter.addStep(temp, getMethodName(), vertexIds);
+ return new VariantGraphTraversal<>(this.getGraph(), temp, this.variantConverter);
+ }
+
+ @Deprecated
+ public GraphTraversal<Vertex, Vertex> addV(final Object... keyValues) {
+ final StringBuilder temp = new StringBuilder(this.sourceString.toString());
+ this.variantConverter.addStep(temp, getMethodName(), keyValues);
+ return new VariantGraphTraversal<>(this.getGraph(), temp, this.variantConverter);
+ }
+
+ public GraphTraversal<Vertex, Vertex> addV(final String label) {
+ final StringBuilder temp = new StringBuilder(this.sourceString.toString());
+ this.variantConverter.addStep(temp, getMethodName(), label);
+ return new VariantGraphTraversal<>(this.getGraph(), temp, this.variantConverter);
+ }
+
+ public GraphTraversal<Vertex, Vertex> addV() {
+ final StringBuilder temp = new StringBuilder(this.sourceString.toString());
+ this.variantConverter.addStep(temp, getMethodName());
+ return new VariantGraphTraversal<>(this.getGraph(), temp, this.variantConverter);
+ }
+
+ public <S> GraphTraversal<S, S> inject(S... starts) {
+ final StringBuilder temp = new StringBuilder(this.sourceString.toString());
+ this.variantConverter.addStep(temp, getMethodName(), starts);
+ return new VariantGraphTraversal<>(this.getGraph(), temp, this.variantConverter);
+ }
+
+ ///
+
+ @Override
+ public GraphTraversalSource withComputer(final Computer computer) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), computer);
+ return this;
+ }
+
+ @Override
+ public GraphTraversalSource withComputer(final Class<? extends GraphComputer> graphComputerClass) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), graphComputerClass);
+ return this;
+ }
+
+ @Override
+ public GraphTraversalSource withComputer() {
+ this.variantConverter.addStep(this.sourceString, getMethodName());
+ return this;
+ }
+
+ @Override
+ public GraphTraversalSource withStrategies(final TraversalStrategy... traversalStrategies) {
+ return super.withStrategies(traversalStrategies);
+ //this.variantConverter.addStep(this.sourceString, getMethodName(), traversalStrategies);
+ //return this;
+ }
+
+ @Override
+ @SuppressWarnings({"unchecked", "varargs"})
+ public GraphTraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), traversalStrategyClasses);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSack(final Supplier<A> initialValue, final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), splitOperator, mergeOperator);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSack(final A initialValue, final UnaryOperator<A> splitOperator, final BinaryOperator<A> mergeOperator) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), initialValue, splitOperator, mergeOperator);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSack(final A initialValue) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), initialValue);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSack(final Supplier<A> initialValue) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), initialValue);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSack(final Supplier<A> initialValue, final UnaryOperator<A> splitOperator) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), initialValue, splitOperator);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSack(final A initialValue, final UnaryOperator<A> splitOperator) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), initialValue, splitOperator);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSack(final Supplier<A> initialValue, final BinaryOperator<A> mergeOperator) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), initialValue, mergeOperator);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSack(final A initialValue, final BinaryOperator<A> mergeOperator) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), initialValue, mergeOperator);
+ return this;
+ }
+
+ /////
+
+ @Override
+ public <A> GraphTraversalSource withSideEffect(final String key, final Supplier<A> initialValue, final BinaryOperator<A> reducer) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), key, initialValue, reducer);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSideEffect(final String key, final A initialValue, final BinaryOperator<A> reducer) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), key, initialValue, reducer);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSideEffect(final String key, final A initialValue) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), key, initialValue);
+ return this;
+ }
+
+ @Override
+ public <A> GraphTraversalSource withSideEffect(final String key, final Supplier<A> initialValue) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), key, initialValue);
+ return this;
+ }
+
+ /////
+
+ @Override
+ public GraphTraversalSource withBulk(final boolean useBulk) {
+ this.variantConverter.addStep(this.sourceString, getMethodName(), useBulk);
+ return this;
+ }
+
+ @Override
+ public GraphTraversalSource withPath() {
+ this.variantConverter.addStep(this.sourceString, getMethodName());
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/487d992e/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/python/PythonVariantConverter.java
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/python/PythonVariantConverter.java b/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/python/PythonVariantConverter.java
new file mode 100644
index 0000000..b5810ac
--- /dev/null
+++ b/gremlin-variant/src/test/java/org/apache/tinkerpop/gremlin/process/variant/python/PythonVariantConverter.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tinkerpop.gremlin.process.variant.python;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Operator;
+import org.apache.tinkerpop.gremlin.process.traversal.Order;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.Pop;
+import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
+import org.apache.tinkerpop.gremlin.process.traversal.Scope;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.VerificationException;
+import org.apache.tinkerpop.gremlin.process.traversal.util.EmptyTraversal;
+import org.apache.tinkerpop.gremlin.process.variant.VariantConverter;
+import org.apache.tinkerpop.gremlin.process.variant.VariantGraphTraversal;
+import org.apache.tinkerpop.gremlin.structure.Column;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.VertexProperty;
+import org.apache.tinkerpop.gremlin.util.Gremlin;
+import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
+import org.apache.tinkerpop.gremlin.util.iterator.ArrayIterator;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
+import javax.script.Bindings;
+import javax.script.ScriptContext;
+import javax.script.ScriptEngine;
+import javax.script.ScriptException;
+import javax.script.SimpleBindings;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Stream;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class PythonVariantConverter implements VariantConverter {
+
+ private static ScriptEngine JYTHON_ENGINE = ScriptEngineCache.get("jython");
+
+ static {
+ try {
+ final String fileName = (new File("variants/python").exists() ? "variants/python/" : "gremlin-variants/variants/python/") + "gremlin-python-" + Gremlin.version() + ".py";
+ GremlinPythonGenerator.create(fileName);
+ JYTHON_ENGINE.eval("execfile(\"" + fileName + "\")");
+ } catch (final ScriptException e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ }
+
+ private static final Set<String> PREFIX_NAMES = new HashSet<>(Arrays.asList("as", "in", "and", "or", "is", "not", "from"));
+
+ @Override
+ public String generateGremlinGroovy(final StringBuilder currentTraversal) throws ScriptException {
+ if (currentTraversal.toString().contains("$") || currentTraversal.toString().contains("@"))
+ throw new VerificationException("Lambdas are currently not supported: " + currentTraversal.toString(), EmptyTraversal.instance());
+
+ final Bindings jythonBindings = new SimpleBindings();
+ jythonBindings.put("g", JYTHON_ENGINE.eval("PythonGraphTraversalSource(\"g\")"));
+ JYTHON_ENGINE.getContext().setBindings(jythonBindings, ScriptContext.GLOBAL_SCOPE);
+ return JYTHON_ENGINE.eval(currentTraversal.toString()).toString();
+ }
+
+ @Override
+ public void addStep(final StringBuilder currentTraversal, final String stepName, final Object... arguments) {
+ // flatten the arguments into a single array
+ final Object[] objects = Stream.of(arguments)
+ .flatMap(arg ->
+ IteratorUtils.stream(arg instanceof Object[] ?
+ new ArrayIterator<>((Object[]) arg) :
+ IteratorUtils.of(arg)))
+ .toArray();
+ if (objects.length == 0)
+ currentTraversal.append(".").append(convertStepName(stepName)).append("()");
+ else if (stepName.equals("range") && 2 == objects.length)
+ currentTraversal.append("[").append(objects[0]).append(":").append(objects[1]).append("]");
+ else if (stepName.equals("limit") && 1 == objects.length)
+ currentTraversal.append("[0:").append(objects[0]).append("]");
+ else if (stepName.equals("values") && 1 == objects.length && !currentTraversal.toString().equals("__"))
+ currentTraversal.append(".").append(objects[0]);
+ else {
+ String temp = "." + convertStepName(stepName) + "(";
+ for (final Object object : objects) {
+ temp = temp + convertToString(object) + ",";
+ }
+ currentTraversal.append(temp.substring(0, temp.length() - 1) + ")");
+ }
+ }
+
+ private static String convertToString(final Object object) {
+ if (object instanceof String)
+ return "\"" + object + "\"";
+ else if (object instanceof List) {
+ final List list = new ArrayList<>(((List) object).size());
+ for (final Object item : (List) object) {
+ list.add(item instanceof String ? "'" + item + "'" : convertToString(item)); // hack
+ }
+ return list.toString();
+ } else if (object instanceof Long)
+ return object + "L";
+ else if (object instanceof Class)
+ return ((Class) object).getCanonicalName();
+ else if (object instanceof SackFunctions.Barrier)
+ return "Barrier." + object.toString();
+ else if (object instanceof VertexProperty.Cardinality)
+ return "Cardinality." + object.toString();
+ else if (object instanceof Direction)
+ return "Direction." + object.toString();
+ else if (object instanceof Operator)
+ return ((object == Operator.and || object == Operator.or) ? "Operator._" : "Operator.") + object.toString();
+ else if (object instanceof Pop)
+ return "Pop." + object.toString();
+ else if (object instanceof Column)
+ return "Column." + object.toString();
+ else if (object instanceof P)
+ return "P." + ((P) object).getBiPredicate() + "(" + (((P) object).getValue() instanceof String ? "'" + ((P) object).getValue() + "'" : convertToString(((P) object).getValue())) + ")";
+ else if (object instanceof T)
+ return "T." + object.toString();
+ else if (object instanceof Order)
+ return "Order." + object.toString();
+ else if (object instanceof Scope)
+ return "Scope._" + object.toString();
+ else if (object instanceof Element)
+ return convertToString(((Element) object).id()); // hack
+ else if (object instanceof VariantGraphTraversal)
+ return ((VariantGraphTraversal) object).getVariantString().toString();
+ else if (object instanceof Boolean)
+ return object.equals(Boolean.TRUE) ? "True" : "False";
+ else
+ return null == object ? "" : object.toString();
+ }
+
+ private static String convertStepName(final String stepName) {
+ if (PREFIX_NAMES.contains(stepName))
+ return "_" + stepName;
+ else
+ return stepName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/487d992e/gremlin-variant/src/test/resources/log4j-test.properties
----------------------------------------------------------------------
diff --git a/gremlin-variant/src/test/resources/log4j-test.properties b/gremlin-variant/src/test/resources/log4j-test.properties
index f9035ba..79038b1 100644
--- a/gremlin-variant/src/test/resources/log4j-test.properties
+++ b/gremlin-variant/src/test/resources/log4j-test.properties
@@ -17,7 +17,7 @@
# under the License.
#
-log4j.rootLogger=INFO, stdout
+log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n
\ No newline at end of file