org.apache.tinkerpop.gremlin.process.computer.VertexComputeKey Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.process.computer.VertexComputeKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TinkerGraphComputerView.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
public TinkerGraphComputerView(final TinkerGraph graph, final GraphFilter graphFilter, final Set<VertexComputeKey> computeKeys) {
    this.graph = graph;
    this.computeKeys = new HashMap<>();
    computeKeys.forEach(key -> this.computeKeys.put(key.getKey(), key));
    this.computeProperties = new ConcurrentHashMap<>();
    this.graphFilter = graphFilter;
    if (this.graphFilter.hasFilter()) {
        graph.vertices().forEachRemaining(vertex -> {
            boolean legalVertex = false;
            if (this.graphFilter.hasVertexFilter() && this.graphFilter.legalVertex(vertex)) {
                this.legalVertices.add(vertex.id());
                legalVertex = true;
            }
            if ((legalVertex || !this.graphFilter.hasVertexFilter()) && this.graphFilter.hasEdgeFilter()) {
                final Set<Object> edges = new HashSet<>();
                this.legalEdges.put(vertex.id(), edges);
                this.graphFilter.legalEdges(vertex).forEachRemaining(edge -> edges.add(edge.id()));
            }
        });
    }
}
 
Example #2
Source File: SparkExecutor.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public static <M> JavaPairRDD<Object, VertexWritable> prepareFinalGraphRDD(
        final JavaPairRDD<Object, VertexWritable> graphRDD,
        final JavaPairRDD<Object, ViewIncomingPayload<M>> viewIncomingRDD,
        final Set<VertexComputeKey> vertexComputeKeys) {
    // the graphRDD and the viewRDD must have the same partitioner
    if (graphRDD.partitioner().isPresent())
        assert (graphRDD.partitioner().get().equals(viewIncomingRDD.partitioner().get()));
    final String[] vertexComputeKeysArray = VertexProgramHelper.vertexComputeKeysAsArray(vertexComputeKeys); // the compute keys as an array
    return graphRDD.leftOuterJoin(viewIncomingRDD)
            .mapValues(tuple -> {
                final StarGraph.StarVertex vertex = tuple._1().get();
                vertex.dropVertexProperties(vertexComputeKeysArray); // drop all existing compute keys
                // attach the final computed view to the cached graph
                final List<DetachedVertexProperty<Object>> view = tuple._2().isPresent() ? tuple._2().get().getView() : Collections.emptyList();
                for (final DetachedVertexProperty<Object> property : view) {
                    if (!VertexProgramHelper.isTransientVertexComputeKey(property.key(), vertexComputeKeys))
                        property.attach(Attachable.Method.create(vertex));
                }
                return tuple._1();
            });
}
 
Example #3
Source File: TinkerGraphComputerView.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public TinkerGraphComputerView(final TinkerGraph graph, final GraphFilter graphFilter, final Set<VertexComputeKey> computeKeys) {
    this.graph = graph;
    this.computeKeys = new HashMap<>();
    computeKeys.forEach(key -> this.computeKeys.put(key.getKey(), key));
    this.computeProperties = new ConcurrentHashMap<>();
    this.graphFilter = graphFilter;
    if (this.graphFilter.hasFilter()) {
        graph.vertices().forEachRemaining(vertex -> {
            boolean legalVertex = false;
            if (this.graphFilter.hasVertexFilter() && this.graphFilter.legalVertex(vertex)) {
                this.legalVertices.add(vertex.id());
                legalVertex = true;
            }
            if ((legalVertex || !this.graphFilter.hasVertexFilter()) && this.graphFilter.hasEdgeFilter()) {
                final Set<Object> edges = new HashSet<>();
                this.legalEdges.put(vertex.id(), edges);
                this.graphFilter.legalEdges(vertex).forEachRemaining(edge -> edges.add(edge.id()));
            }
        });
    }
}
 
Example #4
Source File: PageRankVertexProgram.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void loadState(final Graph graph, final Configuration configuration) {
    if (configuration.containsKey(INITIAL_RANK_TRAVERSAL))
        this.initialRankTraversal = PureTraversal.loadState(configuration, INITIAL_RANK_TRAVERSAL, graph);
    if (configuration.containsKey(EDGE_TRAVERSAL)) {
        this.edgeTraversal = PureTraversal.loadState(configuration, EDGE_TRAVERSAL, graph);
        this.incidentMessageScope = MessageScope.Local.of(() -> this.edgeTraversal.get().clone());
        this.countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
    }
    this.alpha = configuration.getDouble(ALPHA, this.alpha);
    this.epsilon = configuration.getDouble(EPSILON, this.epsilon);
    this.maxIterations = configuration.getInt(MAX_ITERATIONS, 20);
    this.property = configuration.getString(PROPERTY, PAGE_RANK);
    this.vertexComputeKeys = new HashSet<>(Arrays.asList(
            VertexComputeKey.of(this.property, false),
            VertexComputeKey.of(EDGE_COUNT, true)));
    this.memoryComputeKeys = new HashSet<>(Arrays.asList(
            MemoryComputeKey.of(TELEPORTATION_ENERGY, Operator.sum, true, true),
            MemoryComputeKey.of(VERTEX_COUNT, Operator.sum, true, true),
            MemoryComputeKey.of(CONVERGENCE_ERROR, Operator.sum, false, true)));
}
 
Example #5
Source File: GraknSparkExecutor.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
public static <M> JavaPairRDD<Object, VertexWritable> prepareFinalGraphRDD(
        final JavaPairRDD<Object, VertexWritable> graphRDD,
        final JavaPairRDD<Object, ViewIncomingPayload<M>> viewIncomingRDD,
        final Set<VertexComputeKey> vertexComputeKeys) {
    // the graphRDD and the viewRDD must have the same partitioner
    Preconditions.checkState(!graphRDD.partitioner().isPresent() || (graphRDD.partitioner().get().equals(viewIncomingRDD.partitioner().get())));
    final String[] vertexComputeKeysArray = VertexProgramHelper.vertexComputeKeysAsArray(vertexComputeKeys); // the compute keys as an array
    return graphRDD.leftOuterJoin(viewIncomingRDD)
            .mapValues(tuple -> {
                final StarGraph.StarVertex vertex = tuple._1().get();
                vertex.dropVertexProperties(vertexComputeKeysArray); // drop all existing compute keys
                // attach the final computed view to the cached graph
                final List<DetachedVertexProperty<Object>> view = tuple._2().isPresent() ? tuple._2().get().getView() : Collections.emptyList();
                for (final DetachedVertexProperty<Object> property : view) {
                    if (!VertexProgramHelper.isTransientVertexComputeKey(property.key(), vertexComputeKeys)){
                        property.attach(Attachable.Method.create(vertex));}
                }
                return tuple._1();
            });
}
 
Example #6
Source File: TinkerGraphComputerView.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
protected void complete() {
    // remove all transient properties from the vertices
    for (final VertexComputeKey computeKey : this.computeKeys.values()) {
        if (computeKey.isTransient()) {
            for (final Map<String, List<VertexProperty<?>>> properties : this.computeProperties.values()) {
                properties.remove(computeKey.getKey());
            }
        }
    }
}
 
Example #7
Source File: TinkerGraphComputerView.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
protected void complete() {
    // remove all transient properties from the vertices
    for (final VertexComputeKey computeKey : this.computeKeys.values()) {
        if (computeKey.isTransient()) {
            for (final Map<String, List<VertexProperty<?>>> properties : this.computeProperties.values()) {
                properties.remove(computeKey.getKey());
            }
        }
    }
}
 
Example #8
Source File: ShortestPathVertexProgram.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return new HashSet<>(Arrays.asList(
            VertexComputeKey.of(shortestPathRecordedAndBroadcasted, true),
            VertexComputeKey.of(pathFoundButIsNotTheShortest, true),
            VertexComputeKey.of(srcMsgFromPrevIterations, true),
            VertexComputeKey.of(destMsgFromPrevIterations, true)
    ));
}
 
Example #9
Source File: VertexProgramHelper.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public static boolean isTransientVertexComputeKey(final String key, final Set<VertexComputeKey> vertexComputeKeySet) {
    for (final VertexComputeKey vertexComputeKey : vertexComputeKeySet) {
        if (vertexComputeKey.getKey().equals(key))
            return vertexComputeKey.isTransient();
    }
    throw new IllegalArgumentException("Could not find key in vertex compute key set: " + key);
}
 
Example #10
Source File: VertexProgramHelper.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public static Set<String> vertexComputeKeysAsSet(final Set<VertexComputeKey> vertexComputeKeySet) {
    final Set<String> set = new HashSet<>(vertexComputeKeySet.size());
    for (final VertexComputeKey key : vertexComputeKeySet) {
        set.add(key.getKey());
    }
    return set;
}
 
Example #11
Source File: ShortestPathVertexProgram.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return VERTEX_COMPUTE_KEYS;
}
 
Example #12
Source File: TinkerHelper.java    From tinkergraph-gremlin with Apache License 2.0 4 votes vote down vote up
public static TinkerGraphComputerView createGraphComputerView(final TinkerGraph graph, final GraphFilter graphFilter, final Set<VertexComputeKey> computeKeys) {
    return graph.graphComputerView = new TinkerGraphComputerView(graph, graphFilter, computeKeys);
}
 
Example #13
Source File: TinkerHelper.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public static TinkerGraphComputerView createGraphComputerView(final TinkerGraph graph, final GraphFilter graphFilter, final Set<VertexComputeKey> computeKeys) {
    return graph.graphComputerView = new TinkerGraphComputerView(graph, graphFilter, computeKeys);
}
 
Example #14
Source File: ProgramTest.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return Collections.singleton(VertexComputeKey.of(TraversalVertexProgram.HALTED_TRAVERSERS, false));
}
 
Example #15
Source File: ComputerGraph.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
private ComputerGraph(final State state, final Vertex starVertex, final Optional<VertexProgram<?>> vertexProgram) {
    this.state = state;
    this.computeKeys = vertexProgram.isPresent() ? vertexProgram.get().getVertexComputeKeys().stream().map(VertexComputeKey::getKey).collect(Collectors.toSet()) : Collections.emptySet();
    this.starVertex = new ComputerVertex(starVertex);
}
 
Example #16
Source File: VertexProgramHelper.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public static String[] vertexComputeKeysAsArray(final Set<VertexComputeKey> vertexComputeKeySet) {
    return VertexProgramHelper.vertexComputeKeysAsSet(vertexComputeKeySet).toArray(new String[vertexComputeKeySet.size()]);
}
 
Example #17
Source File: TraversalVertexProgram.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return VERTEX_COMPUTE_KEYS;
}
 
Example #18
Source File: MedianVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return Sets.newHashSet(
            VertexComputeKey.of(DEGREE, true),
            VertexComputeKey.of(LABEL, true));
}
 
Example #19
Source File: PeerPressureVertexProgram.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return new HashSet<>(Arrays.asList(VertexComputeKey.of(this.property, false), VertexComputeKey.of(VOTE_STRENGTH, true)));
}
 
Example #20
Source File: ConnectedComponentVertexProgram.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return new HashSet<>(Arrays.asList(
            VertexComputeKey.of(property, false),
            VertexComputeKey.of(TraversalVertexProgram.HALTED_TRAVERSERS, false)));
}
 
Example #21
Source File: PageRankVertexProgram.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return this.vertexComputeKeys;
}
 
Example #22
Source File: ConnectedComponentsVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return Collections.singleton(VertexComputeKey.of(CLUSTER_LABEL, false));
}
 
Example #23
Source File: CountVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return Collections.singleton(VertexComputeKey.of(EDGE_COUNT, false));
}
 
Example #24
Source File: ConnectedComponentVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return Collections.singleton(VertexComputeKey.of(CLUSTER_LABEL, false));
}
 
Example #25
Source File: DegreeVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return Collections.singleton(VertexComputeKey.of(DEGREE, false));
}
 
Example #26
Source File: KCoreVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return VERTEX_COMPUTE_KEYS;
}
 
Example #27
Source File: CorenessVertexProgram.java    From grakn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public Set<VertexComputeKey> getVertexComputeKeys() {
    return VERTEX_COMPUTE_KEYS;
}