org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep.
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: CountStrategy.java From tinkerpop with Apache License 2.0 | 5 votes |
private boolean doStrategy(final Step step) { if (!(step instanceof CountGlobalStep) || !(step.getNextStep() instanceof IsStep) || step.getPreviousStep() instanceof RangeGlobalStep) // if a RangeStep was provided, assume that the user knows what he's doing return false; final Step parent = step.getTraversal().getParent().asStep(); return (parent instanceof FilterStep || parent.getLabels().isEmpty()) && // if the parent is labeled, then the count matters !(parent.getNextStep() instanceof MatchStep.MatchEndStep && // if this is in a pattern match, then don't do it. ((MatchStep.MatchEndStep) parent.getNextStep()).getMatchKey().isPresent()); }
Example #2
Source File: FilterRankingStrategy.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Ranks the given step. Steps with lower ranks can be moved in front of steps with higher ranks. 0 means that * the step has no rank and thus is not exchangeable with its neighbors. * * @param step the step to get a ranking for * @return The rank of the given step. */ private static int getStepRank(final Step step) { final int rank; if (!(step instanceof FilterStep || step instanceof OrderGlobalStep)) return 0; else if (step instanceof IsStep || step instanceof ClassFilterStep) rank = 1; else if (step instanceof HasStep) rank = 2; else if (step instanceof WherePredicateStep && ((WherePredicateStep) step).getLocalChildren().isEmpty()) rank = 3; else if (step instanceof TraversalFilterStep || step instanceof NotStep) rank = 4; else if (step instanceof WhereTraversalStep) rank = 5; else if (step instanceof OrStep) rank = 6; else if (step instanceof AndStep) rank = 7; else if (step instanceof WherePredicateStep) // has by()-modulation rank = 8; else if (step instanceof DedupGlobalStep) rank = 9; else if (step instanceof OrderGlobalStep) rank = 10; else return 0; //////////// if (step instanceof TraversalParent) return getMaxStepRank((TraversalParent) step, rank); else return rank; }
Example #3
Source File: AdjacentVertexFilterOptimizerStrategy.java From grakn with GNU Affero General Public License v3.0 | 4 votes |
@Override public void apply(Traversal.Admin<?, ?> traversal) { TraversalHelper.getStepsOfClass(TraversalFilterStep.class, traversal).forEach(originalStep -> { // Check if this filter traversal matches the pattern: _.inV/outV/otherV.is(x) Traversal.Admin<?, ?> filterTraversal = (Traversal.Admin<?, ?>) originalStep.getLocalChildren().get(0); List<Step> steps = filterTraversal.getSteps(); if (steps.size() == 2 && (steps.get(0) instanceof EdgeVertexStep || steps.get(0) instanceof EdgeOtherVertexStep) && (steps.get(1) instanceof IsStep)) { //Get the direction in which we filter on the adjacent vertex (or null if not a valid adjacency filter) Direction direction = null; if (steps.get(0) instanceof EdgeVertexStep) { EdgeVertexStep evs = (EdgeVertexStep) steps.get(0); if (evs.getDirection() != Direction.BOTH) direction = evs.getDirection(); } else { direction = Direction.BOTH; } P predicate = ((IsStep) steps.get(1)).getPredicate(); //Check that we have a valid direction and a valid vertex filter predicate if (direction != null && predicate.getBiPredicate() == Compare.eq && predicate.getValue() instanceof Vertex) { Vertex vertex = (Vertex) predicate.getValue(); //Now, check that this step is preceded by VertexStep that returns edges Step<?, ?> currentStep = originalStep.getPreviousStep(); while (currentStep != EmptyStep.instance()) { if (!(currentStep instanceof HasStep) && !(currentStep instanceof IdentityStep)) { break; } //We can jump over other steps as we move backward currentStep = currentStep.getPreviousStep(); } if (currentStep instanceof VertexStep) { VertexStep vertexStep = (VertexStep) currentStep; if (vertexStep.returnsEdge() && (direction == Direction.BOTH || direction.equals(vertexStep.getDirection().opposite()))) { //Now replace the step with a has condition TraversalHelper.replaceStep(originalStep, new HasStep(traversal, new HasContainer(ImplicitKey.ADJACENT_ID.name(), P.eq(vertex))), traversal); } } } } }); }
Example #4
Source File: GraphTraversal.java From tinkerpop with Apache License 2.0 | 2 votes |
/** * Filters <code>E</code> object values given the provided {@code predicate}. * * @param predicate the filter to apply * @return the traversal with an appended {@link IsStep} * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#is-step" target="_blank">Reference Documentation - Is Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> is(final P<E> predicate) { this.asAdmin().getBytecode().addStep(Symbols.is, predicate); return this.asAdmin().addStep(new IsStep<>(this.asAdmin(), predicate)); }
Example #5
Source File: GraphTraversal.java From tinkerpop with Apache License 2.0 | 2 votes |
/** * Filter the <code>E</code> object if it is not {@link P#eq} to the provided value. * * @param value the value that the object must equal. * @return the traversal with an appended {@link IsStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#is-step" target="_blank">Reference Documentation - Is Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> is(final Object value) { this.asAdmin().getBytecode().addStep(Symbols.is, value); return this.asAdmin().addStep(new IsStep<>(this.asAdmin(), value instanceof P ? (P<E>) value : P.eq((E) value))); }