<commit_before>package com.tinkerpop.gremlin.process.graph.strategy;

import com.tinkerpop.gremlin.process.Step;
import com.tinkerpop.gremlin.process.Traversal;
import com.tinkerpop.gremlin.process.TraversalStrategy;
import com.tinkerpop.gremlin.process.graph.step.filter.WhereStep;
import com.tinkerpop.gremlin.process.graph.step.map.SelectOneStep;
import com.tinkerpop.gremlin.process.graph.step.map.SelectStep;
import com.tinkerpop.gremlin.process.graph.step.map.match.MatchStep;
import com.tinkerpop.gremlin.process.graph.step.util.IdentityStep;
import com.tinkerpop.gremlin.process.util.TraversalHelper;

import java.util.List;

/**
 * @author <NAME> (http://markorodriguez.com)
 */
public class MatchWhereStrategy implements TraversalStrategy {

    private static final MatchWhereStrategy INSTANCE = new MatchWhereStrategy();

    private MatchWhereStrategy() {
    }

    public void apply(final Traversal traversal) {
        final List<MatchStep> matchSteps = TraversalHelper.getStepsOfClass(MatchStep.class, traversal);
        for (final MatchStep matchStep : matchSteps) {
            Step currentStep = matchStep.getNextStep();
            while (currentStep instanceof WhereStep || currentStep instanceof IdentityStep || currentStep instanceof SelectStep || currentStep instanceof SelectOneStep) {
                if (currentStep instanceof WhereStep) {
                    if (!((WhereStep) currentStep).hasBiPredicate()) {
                        matchStep.addTraversal(((WhereStep) currentStep).constraint);
                        TraversalHelper.removeStep(currentStep, traversal);
                    }
                } else if (currentStep instanceof SelectStep) {
                    if (((SelectStep) currentStep).hasStepFunctions())
                        break;
                } else if (currentStep instanceof SelectOneStep) {
                    if (((SelectOneStep) currentStep).hasStepFunction())
                        break;
                } // else is the identity step

                currentStep = currentStep.getNextStep();
            }
        }
    }

    public static MatchWhereStrategy instance() {
        return INSTANCE;
    }

    public int compareTo(final TraversalStrategy traversalStrategy) {
        return traversalStrategy instanceof IdentityReductionStrategy ? 1 : -1;
    }
}
<commit_msg>more thoughts on MatchWhereStrategy...for @joshsh.<commit_after>package com.tinkerpop.gremlin.process.graph.strategy;

import com.tinkerpop.gremlin.process.Step;
import com.tinkerpop.gremlin.process.Traversal;
import com.tinkerpop.gremlin.process.TraversalStrategy;
import com.tinkerpop.gremlin.process.graph.step.filter.WhereStep;
import com.tinkerpop.gremlin.process.graph.step.map.SelectOneStep;
import com.tinkerpop.gremlin.process.graph.step.map.SelectStep;
import com.tinkerpop.gremlin.process.graph.step.map.match.MatchStep;
import com.tinkerpop.gremlin.process.graph.step.util.IdentityStep;
import com.tinkerpop.gremlin.process.util.TraversalHelper;

import java.util.List;

/**
 * @author <NAME> (http://markorodriguez.com)
 */
public class MatchWhereStrategy implements TraversalStrategy {

    private static final MatchWhereStrategy INSTANCE = new MatchWhereStrategy();

    private MatchWhereStrategy() {
    }

    public void apply(final Traversal traversal) {
        final List<MatchStep> matchSteps = TraversalHelper.getStepsOfClass(MatchStep.class, traversal);
        for (final MatchStep matchStep : matchSteps) {
            boolean foundWhereWithNoTraversal = false;
            Step currentStep = matchStep.getNextStep();
            while (currentStep instanceof WhereStep || currentStep instanceof SelectStep || currentStep instanceof SelectOneStep || currentStep instanceof IdentityStep) {
                if (currentStep instanceof WhereStep) {
                    if (!((WhereStep) currentStep).hasBiPredicate()) {
                        matchStep.addTraversal(((WhereStep) currentStep).constraint);
                        TraversalHelper.removeStep(currentStep, traversal);
                    } else {
                        foundWhereWithNoTraversal = true;
                    }
                } else if (currentStep instanceof SelectStep) {
                    if (((SelectStep) currentStep).hasStepFunctions() || foundWhereWithNoTraversal)
                        break;
                } else if (currentStep instanceof SelectOneStep) {
                    if (((SelectOneStep) currentStep).hasStepFunction() || foundWhereWithNoTraversal)
                        break;
                } // else is the identity step

                currentStep = currentStep.getNextStep();
            }
        }
    }

    public static MatchWhereStrategy instance() {
        return INSTANCE;
    }

    public int compareTo(final TraversalStrategy traversalStrategy) {
        return traversalStrategy instanceof IdentityReductionStrategy ? 1 : -1;
    }
}

{'fraction_non_alphanumeric': 0.08814589665653495, 'fraction_numerical': 0.0008105369807497467, 'mean_word_length': 2.765064836003051, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7665376', 'n_tokens_mistral': 1350, 'n_tokens_neox': 1243, 'n_words': 258}