Search in sources :

Example 1 with UniGraph

use of org.unipop.structure.UniGraph in project unipop by unipop-graph.

the class UniGraphUnionStepStrategy method apply.

@Override
public void apply(Traversal.Admin<?, ?> traversal) {
    Graph graph = traversal.getGraph().get();
    if (!(graph instanceof UniGraph)) {
        return;
    }
    UniGraph uniGraph = (UniGraph) graph;
    TraversalHelper.getStepsOfClass(UnionStep.class, traversal).forEach(unionStep -> {
        Traversal.Admin[] traversals = (Traversal.Admin[]) unionStep.getGlobalChildren().toArray(new Traversal.Admin[0]);
        for (Traversal.Admin admin : traversals) {
            if (TraversalHelper.getLastStepOfAssignableClass(ReducingBarrierStep.class, admin).isPresent() || traversal.getParent() instanceof RepeatStep)
                return;
        }
        UniGraphUnionStep uniGraphUnionStep = new UniGraphUnionStep(traversal, uniGraph, traversals);
        if (TraversalHelper.stepIndex(unionStep, traversal) != -1) {
            TraversalHelper.replaceStep(unionStep, uniGraphUnionStep, traversal);
        } else {
            TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, traversal).forEach(traversalParent -> {
                traversalParent.getLocalChildren().forEach(child -> {
                    if (TraversalHelper.stepIndex(unionStep, child) != -1) {
                        TraversalHelper.replaceStep(unionStep, uniGraphUnionStep, child);
                    }
                });
                traversalParent.getGlobalChildren().forEach(child -> {
                    if (TraversalHelper.stepIndex(unionStep, child) != -1) {
                        TraversalHelper.replaceStep(unionStep, uniGraphUnionStep, child);
                    }
                });
            });
        }
    });
}
Also used : UniGraph(org.unipop.structure.UniGraph) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) Graph(org.apache.tinkerpop.gremlin.structure.Graph) UniGraph(org.unipop.structure.UniGraph) RepeatStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) UnionStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep)

Example 2 with UniGraph

use of org.unipop.structure.UniGraph in project unipop by unipop-graph.

the class EdgeStepsStrategy method apply.

@Override
public void apply(Traversal.Admin<?, ?> traversal) {
    UniGraph uniGraph = ((UniGraph) traversal.getGraph().get());
    TraversalHelper.getStepsOfClass(EdgeOtherVertexStep.class, traversal).forEach(edgeOtherVertexStep -> {
        UniGraphEdgeOtherVertexStep uniGraphEdgeOtherVertexStep = new UniGraphEdgeOtherVertexStep(traversal, uniGraph, uniGraph.getControllerManager());
        edgeOtherVertexStep.getLabels().forEach(uniGraphEdgeOtherVertexStep::addLabel);
        TraversalHelper.replaceStep(edgeOtherVertexStep, uniGraphEdgeOtherVertexStep, traversal);
    });
    TraversalHelper.getStepsOfClass(EdgeVertexStep.class, traversal).forEach(edgeVertexStep -> {
        UniGraphEdgeVertexStep uniGraphEdgeVertexStep = new UniGraphEdgeVertexStep(traversal, edgeVertexStep.getDirection(), uniGraph, uniGraph.getControllerManager());
        edgeVertexStep.getLabels().forEach(uniGraphEdgeVertexStep::addLabel);
        TraversalHelper.replaceStep(edgeVertexStep, uniGraphEdgeVertexStep, traversal);
    });
}
Also used : UniGraph(org.unipop.structure.UniGraph) EdgeVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep) EdgeOtherVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep)

Example 3 with UniGraph

use of org.unipop.structure.UniGraph in project unipop by unipop-graph.

the class UniGraphStepStrategy method apply.

@Override
public void apply(Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;
    Graph graph = traversal.getGraph().get();
    if (!(graph instanceof UniGraph)) {
        return;
    }
    UniGraph uniGraph = (UniGraph) graph;
    TraversalHelper.getStepsOfClass(GraphStep.class, traversal).forEach(graphStep -> {
        final UniGraphStep<?, ?> uniGraphStep = new UniGraphStep<>(graphStep, uniGraph.getControllerManager());
        TraversalHelper.replaceStep(graphStep, uniGraphStep, traversal);
        PredicatesUtil.collectPredicates(uniGraphStep, traversal);
    });
}
Also used : UniGraph(org.unipop.structure.UniGraph) Graph(org.apache.tinkerpop.gremlin.structure.Graph) UniGraph(org.unipop.structure.UniGraph) GraphStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep)

Example 4 with UniGraph

use of org.unipop.structure.UniGraph in project unipop by unipop-graph.

the class UniGraphRepeatStepStrategy method apply.

@Override
public void apply(Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;
    Graph graph = traversal.getGraph().get();
    if (!(graph instanceof UniGraph)) {
        return;
    }
    UniGraph uniGraph = (UniGraph) graph;
    TraversalHelper.getStepsOfClass(RepeatStep.class, traversal).forEach(repeatStep -> {
        if (TraversalHelper.hasStepOfClass(UnionStep.class, (Traversal.Admin) repeatStep.getGlobalChildren().get(0))) {
            return;
        }
        UniGraphRepeatStep uniGraphRepeatStep = new UniGraphRepeatStep(repeatStep, traversal.asAdmin(), uniGraph);
        if (repeatStep.getUntilTraversal() != null && TraversalHelper.getFirstStepOfAssignableClass(ReducingBarrierStep.class, repeatStep.getUntilTraversal()).isPresent())
            return;
        Traversal.Admin<?, ?> repeatTraversal = uniGraphRepeatStep.getRepeatTraversal();
        TraversalHelper.replaceStep(repeatStep, uniGraphRepeatStep, traversal);
        TraversalHelper.getStepsOfClass(RepeatStep.RepeatEndStep.class, repeatTraversal).forEach(repeatEndStep -> {
            UniGraphRepeatStep.RepeatEndStep uniGraphRepeatEndStep = new UniGraphRepeatStep.RepeatEndStep(repeatTraversal, uniGraphRepeatStep);
            TraversalHelper.replaceStep(repeatEndStep, uniGraphRepeatEndStep, repeatTraversal);
        });
    });
}
Also used : UniGraph(org.unipop.structure.UniGraph) Graph(org.apache.tinkerpop.gremlin.structure.Graph) UniGraph(org.unipop.structure.UniGraph) RepeatStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal)

Example 5 with UniGraph

use of org.unipop.structure.UniGraph in project unipop by unipop-graph.

the class UniGraphVertexStepStrategy method apply.

@Override
public void apply(Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;
    Graph graph = traversal.getGraph().get();
    if (!(graph instanceof UniGraph)) {
        return;
    }
    UniGraph uniGraph = (UniGraph) graph;
    TraversalHelper.getStepsOfAssignableClassRecursively(VertexStep.class, traversal).forEach(vertexStep -> {
        if (TraversalHelper.stepIndex(vertexStep, traversal) != -1) {
            UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
            TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, traversal);
            if (vertexStep.returnsEdge())
                PredicatesUtil.collectPredicates(uniGraphVertexStep, traversal);
        } else {
            TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, traversal).forEach(traversalParent -> {
                traversalParent.getLocalChildren().forEach(child -> {
                    if (TraversalHelper.stepIndex(vertexStep, child) != -1) {
                        UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
                        TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child);
                        if (vertexStep.returnsEdge())
                            PredicatesUtil.collectPredicates(uniGraphVertexStep, child);
                    }
                });
                traversalParent.getGlobalChildren().forEach(child -> {
                    if (TraversalHelper.stepIndex(vertexStep, child) != -1) {
                        UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
                        TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child);
                        if (vertexStep.returnsEdge())
                            PredicatesUtil.collectPredicates(uniGraphVertexStep, child);
                    } else if (TraversalHelper.hasStepOfAssignableClass(TraversalParent.class, child)) {
                        TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, child).forEach(traversalParent1 -> {
                            traversalParent.getLocalChildren().forEach(child1 -> {
                                if (TraversalHelper.stepIndex(vertexStep, child1) != -1) {
                                    UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
                                    TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child1);
                                    if (vertexStep.returnsEdge())
                                        PredicatesUtil.collectPredicates(uniGraphVertexStep, child1);
                                }
                            });
                            traversalParent.getGlobalChildren().forEach(child1 -> {
                                if (TraversalHelper.stepIndex(vertexStep, child1) != -1) {
                                    UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
                                    TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child1);
                                    if (vertexStep.returnsEdge())
                                        PredicatesUtil.collectPredicates(uniGraphVertexStep, child1);
                                }
                            });
                        });
                    }
                });
            });
        }
    });
}
Also used : VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) TraversalHelper(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper) AbstractTraversalStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) Graph(org.apache.tinkerpop.gremlin.structure.Graph) UniGraph(org.unipop.structure.UniGraph) TraversalStrategy(org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) PredicatesUtil(org.unipop.process.predicate.PredicatesUtil) UniGraph(org.unipop.structure.UniGraph) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) Graph(org.apache.tinkerpop.gremlin.structure.Graph) UniGraph(org.unipop.structure.UniGraph)

Aggregations

UniGraph (org.unipop.structure.UniGraph)6 Graph (org.apache.tinkerpop.gremlin.structure.Graph)5 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)3 TraversalParent (org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent)2 RepeatStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep)2 TraversalStrategy (org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy)1 UnionStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep)1 CoalesceStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.CoalesceStep)1 EdgeOtherVertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep)1 EdgeVertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep)1 GraphStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep)1 VertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep)1 AbstractTraversalStrategy (org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy)1 TraversalHelper (org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper)1 UniGraphCoalesceStep (org.unipop.process.coalesce.UniGraphCoalesceStep)1 PredicatesUtil (org.unipop.process.predicate.PredicatesUtil)1