tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject incubator-tinkerpop git commit: Added PeerPressureVertexProgramStep and GraphTraversal.peerPressure(). Added GraphTraversal.pageRank(alpha). Ensured that VertexComputing steps are NOT used in StandardTraversal.
Date Wed, 17 Feb 2016 18:04:36 GMT
Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1154 2d5cd1c0d -> 622f84b9d


Added PeerPressureVertexProgramStep and GraphTraversal.peerPressure(). Added GraphTraversal.pageRank(alpha).
Ensured that VertexComputing steps are NOT used in StandardTraversal.


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

Branch: refs/heads/TINKERPOP-1154
Commit: 622f84b9dc94ae5ef1b6c174fcf360cef2366d37
Parents: 2d5cd1c
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Wed Feb 17 11:04:27 2016 -0700
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Wed Feb 17 11:04:27 2016 -0700

----------------------------------------------------------------------
 .../peerpressure/PeerPressureVertexProgram.java |  40 +++++--
 .../step/map/PageRankVertexProgramStep.java     |   5 +-
 .../step/map/PeerPressureVertexProgramStep.java | 118 +++++++++++++++++++
 .../traversal/dsl/graph/GraphTraversal.java     |  11 +-
 .../decoration/VertexProgramStrategy.java       |   2 +-
 .../StandardVerificationStrategy.java           |   7 ++
 .../step/map/GroovyPeerPressureTest.groovy      |  39 ++++++
 .../process/GroovyProcessComputerSuite.java     |   2 +
 .../gremlin/process/ProcessComputerSuite.java   |   2 +
 .../traversal/step/map/PeerPressureTest.java    |  63 ++++++++++
 .../structure/TinkerGraphPlayTest.java          |  17 +--
 11 files changed, 280 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
index daf49df..d1eebc3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
@@ -60,6 +60,7 @@ public class PeerPressureVertexProgram extends StaticVertexProgram<Pair<Serializ
     public static final String CLUSTER = "gremlin.peerPressureVertexProgram.cluster";
     public static final String VOTE_STRENGTH = "gremlin.peerPressureVertexProgram.voteStrength";
 
+    public static final String PROPERTY = "gremlin.peerPressureVertexProgram.property";
     private static final String MAX_ITERATIONS = "gremlin.peerPressureVertexProgram.maxIterations";
     private static final String DISTRIBUTE_VOTE = "gremlin.peerPressureVertexProgram.distributeVote";
     private static final String EDGE_TRAVERSAL = "gremlin.peerPressureVertexProgram.edgeTraversal";
@@ -68,8 +69,8 @@ public class PeerPressureVertexProgram extends StaticVertexProgram<Pair<Serializ
     private PureTraversal<Vertex, Edge> edgeTraversal = null;
     private int maxIterations = 30;
     private boolean distributeVote = false;
+    private String property = CLUSTER;
 
-    private static final Set<String> ELEMENT_COMPUTE_KEYS = new HashSet<>(Arrays.asList(CLUSTER,
VOTE_STRENGTH));
     private static final Set<String> MEMORY_COMPUTE_KEYS = new HashSet<>(Collections.singletonList(VOTE_TO_HALT));
 
     private PeerPressureVertexProgram() {
@@ -83,6 +84,7 @@ public class PeerPressureVertexProgram extends StaticVertexProgram<Pair<Serializ
             this.voteScope = MessageScope.Local.of(() -> this.edgeTraversal.get().clone());
             this.countScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.voteScope));
         }
+        this.property = configuration.getString(PROPERTY, CLUSTER);
         this.maxIterations = configuration.getInt(MAX_ITERATIONS, 30);
         this.distributeVote = configuration.getBoolean(DISTRIBUTE_VOTE, false);
     }
@@ -98,7 +100,7 @@ public class PeerPressureVertexProgram extends StaticVertexProgram<Pair<Serializ
 
     @Override
     public Set<String> getElementComputeKeys() {
-        return ELEMENT_COMPUTE_KEYS;
+        return new HashSet<>(Arrays.asList(this.property, VOTE_STRENGTH));
     }
 
     @Override
@@ -133,25 +135,25 @@ public class PeerPressureVertexProgram extends StaticVertexProgram<Pair<Serializ
                 messenger.sendMessage(this.countScope, Pair.with('c', 1.0d));
             } else {
                 double voteStrength = 1.0d;
-                vertex.property(VertexProperty.Cardinality.single, CLUSTER, vertex.id());
+                vertex.property(VertexProperty.Cardinality.single, this.property, vertex.id());
                 vertex.property(VertexProperty.Cardinality.single, VOTE_STRENGTH, voteStrength);
                 messenger.sendMessage(this.voteScope, new Pair<>((Serializable) vertex.id(),
voteStrength));
                 memory.and(VOTE_TO_HALT, false);
             }
         } else if (1 == memory.getIteration() && this.distributeVote) {
             double voteStrength = 1.0d / IteratorUtils.reduce(IteratorUtils.map(messenger.receiveMessages(),
Pair::getValue1), 0.0d, (a, b) -> a + b);
-            vertex.property(VertexProperty.Cardinality.single, CLUSTER, vertex.id());
+            vertex.property(VertexProperty.Cardinality.single, this.property, vertex.id());
             vertex.property(VertexProperty.Cardinality.single, VOTE_STRENGTH, voteStrength);
             messenger.sendMessage(this.voteScope, new Pair<>((Serializable) vertex.id(),
voteStrength));
             memory.and(VOTE_TO_HALT, false);
         } else {
             final Map<Serializable, Double> votes = new HashMap<>();
-            votes.put(vertex.value(CLUSTER), vertex.<Double>value(VOTE_STRENGTH));
+            votes.put(vertex.value(this.property), vertex.<Double>value(VOTE_STRENGTH));
             messenger.receiveMessages().forEachRemaining(message -> MapHelper.incr(votes,
message.getValue0(), message.getValue1()));
             Serializable cluster = PeerPressureVertexProgram.largestCount(votes);
             if (null == cluster) cluster = (Serializable) vertex.id();
-            memory.and(VOTE_TO_HALT, vertex.value(CLUSTER).equals(cluster));
-            vertex.property(VertexProperty.Cardinality.single, CLUSTER, cluster);
+            memory.and(VOTE_TO_HALT, vertex.value(this.property).equals(cluster));
+            vertex.property(VertexProperty.Cardinality.single, this.property, cluster);
             messenger.sendMessage(this.voteScope, new Pair<>(cluster, vertex.<Double>value(VOTE_STRENGTH)));
         }
     }
@@ -202,6 +204,11 @@ public class PeerPressureVertexProgram extends StaticVertexProgram<Pair<Serializ
             super(PeerPressureVertexProgram.class);
         }
 
+        public Builder property(final String key) {
+            this.configuration.setProperty(PROPERTY, key);
+            return this;
+        }
+
         public Builder maxIterations(final int iterations) {
             this.configuration.setProperty(MAX_ITERATIONS, iterations);
             return this;
@@ -212,14 +219,27 @@ public class PeerPressureVertexProgram extends StaticVertexProgram<Pair<Serializ
             return this;
         }
 
+        public Builder edges(final Traversal.Admin<Vertex, Edge> edgeTraversal) {
+            PureTraversal.storeState(this.configuration, EDGE_TRAVERSAL, edgeTraversal);
+            return this;
+        }
+
+        /**
+         * @deprecated As of release 3.2.0, replaced by {@link PeerPressureVertexProgram.Builder#edges(Traversal.Admin)}
+         */
+        @Deprecated
         public Builder traversal(final TraversalSource traversalSource, final String scriptEngine,
final String traversalScript, final Object... bindings) {
-            return this.traversal(new ScriptTraversal<>(traversalSource, scriptEngine,
traversalScript, bindings));
+            return this.edges(new ScriptTraversal<>(traversalSource, scriptEngine,
traversalScript, bindings));
         }
 
+        /**
+         * @deprecated As of release 3.2.0, replaced by {@link PeerPressureVertexProgram.Builder#edges(Traversal.Admin)}
+         */
+        @Deprecated
         public Builder traversal(final Traversal.Admin<Vertex, Edge> edgeTraversal)
{
-            PureTraversal.storeState(this.configuration, EDGE_TRAVERSAL, edgeTraversal);
-            return this;
+            return this.edges(edgeTraversal);
         }
+
     }
 
     ////////////////////////////

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
index 68db42a..739a0f5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
@@ -49,9 +49,11 @@ public final class PageRankVertexProgramStep extends VertexProgramStep
implement
     private PureTraversal<Vertex, Edge> edgeTraversal;
     private String pageRankProperty = PageRankVertexProgram.PAGE_RANK;
     private int times = 30;
+    private final double alpha;
 
-    public PageRankVertexProgramStep(final Traversal.Admin traversal) {
+    public PageRankVertexProgramStep(final Traversal.Admin traversal, final double alpha)
{
         super(traversal);
+        this.alpha = alpha;
         this.modulateBy(__.<Vertex>outE().asAdmin());
     }
 
@@ -94,6 +96,7 @@ public final class PageRankVertexProgramStep extends VertexProgramStep implement
         return PageRankVertexProgram.build()
                 .property(this.pageRankProperty)
                 .iterations(this.times)
+                .alpha(this.alpha)
                 .edges(compiledTraversal)
                 .create(graph);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PeerPressureVertexProgramStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PeerPressureVertexProgramStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PeerPressureVertexProgramStep.java
new file mode 100644
index 0000000..6f35808
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PeerPressureVertexProgramStep.java
@@ -0,0 +1,118 @@
+/*
+ * 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.computer.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.PeerPressureVertexProgram;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.ByModulating;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TimesModulating;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.process.traversal.util.PureTraversal;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.function.Function;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class PeerPressureVertexProgramStep extends VertexProgramStep implements TraversalParent,
ByModulating, TimesModulating {
+
+    private transient Function<Graph, GraphComputer> graphComputerFunction = Graph::compute;
+
+    private PureTraversal<Vertex, Edge> edgeTraversal;
+    private String clusterProperty = PeerPressureVertexProgram.CLUSTER;
+    private int times = 30;
+
+    public PeerPressureVertexProgramStep(final Traversal.Admin traversal) {
+        super(traversal);
+        this.modulateBy(__.<Vertex>outE().asAdmin());
+    }
+
+    @Override
+    public void modulateBy(final Traversal.Admin<?, ?> edgeTraversal) {
+        this.edgeTraversal = new PureTraversal<>((Traversal.Admin<Vertex, Edge>)
edgeTraversal);
+        this.integrateChild(this.edgeTraversal.get());
+    }
+
+    @Override
+    public void modulateBy(final String clusterProperty) {
+        this.clusterProperty = clusterProperty;
+    }
+
+    @Override
+    public void modulateTimes(int times) {
+        this.times = times;
+    }
+
+    @Override
+    public List<Traversal.Admin<Vertex, Edge>> getLocalChildren() {
+        return Collections.singletonList(this.edgeTraversal.get());
+    }
+
+    @Override
+    public String toString() {
+        return StringFactory.stepString(this, this.edgeTraversal.get(), this.clusterProperty,
this.times);
+    }
+
+    @Override
+    public void setGraphComputerFunction(final Function<Graph, GraphComputer> graphComputerFunction)
{
+        this.graphComputerFunction = graphComputerFunction;
+    }
+
+    @Override
+    public PeerPressureVertexProgram generateProgram(final Graph graph) {
+        this.edgeTraversal.reset();
+        final Traversal.Admin<Vertex, Edge> compiledTraversal = this.edgeTraversal.get();
+        compiledTraversal.setStrategies(TraversalStrategies.GlobalCache.getStrategies(graph.getClass()));
+        return PeerPressureVertexProgram.build()
+                .property(this.clusterProperty)
+                .maxIterations(this.times)
+                .edges(compiledTraversal)
+                .create(graph);
+    }
+
+    @Override
+    public Set<TraverserRequirement> getRequirements() {
+        return TraversalParent.super.getSelfAndChildRequirements();
+    }
+
+    @Override
+    public GraphComputer generateComputer(final Graph graph) {
+        return this.graphComputerFunction.apply(graph).persist(GraphComputer.Persist.EDGES).result(GraphComputer.ResultGraph.NEW);
+    }
+
+    @Override
+    public PeerPressureVertexProgramStep clone() {
+        final PeerPressureVertexProgramStep clone = (PeerPressureVertexProgramStep) super.clone();
+        clone.edgeTraversal = this.edgeTraversal.clone();
+        this.integrateChild(this.edgeTraversal.get());
+        return clone;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 62d6c4a..69c84ad 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -19,6 +19,7 @@
 package org.apache.tinkerpop.gremlin.process.traversal.dsl.graph;
 
 import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PageRankVertexProgramStep;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.PeerPressureVertexProgramStep;
 import org.apache.tinkerpop.gremlin.process.traversal.Order;
 import org.apache.tinkerpop.gremlin.process.traversal.P;
 import org.apache.tinkerpop.gremlin.process.traversal.Path;
@@ -1150,7 +1151,15 @@ public interface GraphTraversal<S, E> extends Traversal<S,
E> {
     /////////////////// VERTEX PROGRAM STEPS ////////////////
 
     public default GraphTraversal<S, E> pageRank() {
-        return this.asAdmin().addStep((Step<?, E>) new PageRankVertexProgramStep(this.asAdmin()));
+        return this.pageRank(0.85d);
+    }
+
+    public default GraphTraversal<S, E> pageRank(final double alpha) {
+        return this.asAdmin().addStep((Step<E, E>) new PageRankVertexProgramStep(this.asAdmin(),
alpha));
+    }
+
+    public default GraphTraversal<S, E> peerPressure() {
+        return this.asAdmin().addStep((Step<E, E>) new PeerPressureVertexProgramStep(this.asAdmin()));
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
index 775a225..7e9833b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
@@ -130,7 +130,7 @@ public final class VertexProgramStrategy extends AbstractTraversalStrategy<Trave
     }
 
     private static Step<?, ?> getLastLegalOLAPStep(Step<?, ?> currentStep) {
-        if (currentStep instanceof VertexComputing)
+        while (currentStep instanceof VertexComputing)
             currentStep = currentStep.getNextStep();
         while (!(currentStep instanceof EmptyStep)) {
             if (ComputerVerificationStrategy.isStepInstanceOfEndStep(currentStep))

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
index 48cd7fd..62f2654 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
@@ -18,11 +18,13 @@
  */
 package org.apache.tinkerpop.gremlin.process.traversal.strategy.verification;
 
+import org.apache.tinkerpop.gremlin.process.computer.traversal.step.VertexComputing;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -36,6 +38,11 @@ public final class StandardVerificationStrategy extends AbstractTraversalStrateg
 
     @Override
     public void apply(final Traversal.Admin<?, ?> traversal) {
+        if (!traversal.getStrategies().toList().contains(ComputerVerificationStrategy.instance()))
{
+            if (!TraversalHelper.getStepsOfAssignableClass(VertexComputing.class, traversal).isEmpty())
+                throw new VerificationException("VertexComputing steps must be executing
with a GraphComputer: " + TraversalHelper.getStepsOfAssignableClass(VertexComputing.class,
traversal), traversal);
+        }
+
         traversal.getSteps().forEach(step -> {
             if (step instanceof ReducingBarrierStep && step.getTraversal().getParent()
instanceof RepeatStep && step.getTraversal().getParent().getGlobalChildren().get(0).getSteps().contains(step))
                 throw new VerificationException("The direct parent of a ReducingBarrierStep
can not be a RepeatStep: " + step, traversal);

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyPeerPressureTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyPeerPressureTest.groovy
b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyPeerPressureTest.groovy
new file mode 100644
index 0000000..136ae50
--- /dev/null
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyPeerPressureTest.groovy
@@ -0,0 +1,39 @@
+/*
+ * 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.traversal.step.map
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal
+import org.apache.tinkerpop.gremlin.process.traversal.util.ScriptTraversal
+import org.apache.tinkerpop.gremlin.structure.Vertex
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public abstract class GroovyPeerPressureTest {
+
+    public static class Traversals extends PeerPressureTest {
+
+        @Override
+        public Traversal<Vertex, Vertex> get_g_V_peerPressure() {
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V.peerPressure")
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
index f74e1dd..8e7fc30 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
@@ -59,6 +59,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyMinTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyOrderTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyPageRankTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyPathTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyPeerPressureTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovyPropertiesTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovySelectTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.GroovySumTest;
@@ -143,6 +144,7 @@ public class GroovyProcessComputerSuite extends ProcessComputerSuite {
             GroovyOrderTest.Traversals.class,
             GroovyPageRankTest.Traversals.class,
             GroovyPathTest.Traversals.class,
+            GroovyPeerPressureTest.Traversals.class,
             GroovyPropertiesTest.Traversals.class,
             GroovySelectTest.Traversals.class,
             GroovySumTest.Traversals.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
index 5295f77..d680421 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
@@ -62,6 +62,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.MinTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.PageRankTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.PathTest;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.PeerPressureTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.SelectTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.SumTest;
@@ -152,6 +153,7 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
             OrderTest.Traversals.class,
             PageRankTest.Traversals.class,
             PathTest.Traversals.class,
+            PeerPressureTest.Traversals.class,
             PropertiesTest.Traversals.class,
             SelectTest.Traversals.class,
             UnfoldTest.Traversals.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PeerPressureTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PeerPressureTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PeerPressureTest.java
new file mode 100644
index 0000000..0b161df
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PeerPressureTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.traversal.step.map;
+
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.PeerPressureVertexProgram;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Test;
+
+import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public abstract class PeerPressureTest extends AbstractGremlinProcessTest {
+
+    public abstract Traversal<Vertex, Vertex> get_g_V_peerPressure();
+
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_peerPressure() {
+        final Traversal<Vertex, Vertex> traversal = get_g_V_peerPressure();
+        printTraversalForm(traversal);
+        int counter = 0;
+        while (traversal.hasNext()) {
+            final Vertex vertex = traversal.next();
+            counter++;
+            assertTrue(vertex.property(PeerPressureVertexProgram.CLUSTER).isPresent());
+        }
+        assertEquals(6, counter);
+    }
+
+
+    public static class Traversals extends PeerPressureTest {
+
+        @Override
+        public Traversal<Vertex, Vertex> get_g_V_peerPressure() {
+            return g.V().peerPressure();
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/622f84b9/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index 921c4d5..7fdf724 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -19,16 +19,13 @@
 package org.apache.tinkerpop.gremlin.tinkergraph.structure;
 
 import org.apache.tinkerpop.gremlin.process.computer.bulkloading.BulkLoaderVertexProgram;
-import org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVertexProgram;
 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.Scope;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 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.structure.Column;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -42,9 +39,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.function.Supplier;
 
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.as;
@@ -52,13 +47,10 @@ import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.choose;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.count;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.fold;
-import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.groupCount;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has;
-import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.identity;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.outE;
-import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.properties;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.union;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.valueMap;
@@ -74,14 +66,13 @@ public class TinkerGraphPlayTest {
     @Ignore
     public void testPlay8() throws Exception {
         Graph graph = TinkerFactory.createModern();
-        GraphTraversalSource g = graph.traversal(); //GraphTraversalSource.computer());
+        GraphTraversalSource g = graph.traversal();//.withComputer(); //GraphTraversalSource.computer());
         //System.out.println(g.V().outE("knows").identity().inV().count().is(P.eq(5)).explain());
         //System.out.println(g.V().hasLabel("person").fold().order(Scope.local).by("age").toList());
-        System.out.println(g.V().out("knows").V().values("name").toString());
-        System.out.println(g.V().out("knows").V().values("name").iterate().toString());
-        System.out.println(g.V().out("knows").V().values("name").toList());
+        System.out.println(g.V().peerPressure().toString());
+        System.out.println(g.V().peerPressure().iterate().toString());
+        System.out.println(g.V().peerPressure().toList());
         //System.out.println(g.V().pageRank().order().by(PageRankVertexProgram.PAGE_RANK).valueMap().toList());
-
     }
 
     @Test


Mime
View raw message