<commit_before>/*
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * Licensed 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 com.github.parboiled1.grappa.matchers.trie;

import org.parboiled.MatcherContext;
import org.parboiled.matchers.AbstractMatcher;
import org.parboiled.matchers.FirstOfMatcher;
import org.parboiled.matchers.FirstOfStringsMatcher;
import org.parboiled.matchervisitors.MatcherVisitor;
import org.parboiled.parserunners.RecoveringParseRunner;

import javax.annotation.concurrent.Immutable;

/**
 * The trie matcher
 *
 * <p>Note that there are a few crucial differences compared to a {@link
 * FirstOfStringsMatcher}:</p>
 *
 * <ul>
 *     <li>this matcher is insensitive about the ordering of its arguments;
 *     unlike {@link FirstOfMatcher}, for instance, it doesn't care about the
 *     order of appearance of strings with a common prefix;</li>
 *     <li>at this moment, it does not play well with a {@link
 *     RecoveringParseRunner} (a {@link FirstOfStringsMatcher} keeps all
 *     submatches information by its virtue of inheriting {@link
 *     FirstOfMatcher}, which has all character subrules).</li>
 * </ul>
 */
@Immutable
public final class TrieMatcher
    extends AbstractMatcher
{
    private final Trie trie;

    public TrieMatcher(final Trie trie)
    {
        super("Trie");
        this.trie = trie;
    }

    /**
     * Tries a match on the given MatcherContext.
     *
     * @param context the MatcherContext
     * @return true if the match was successful
     */
    @Override
    public <V> boolean match(final MatcherContext<V> context)<commit_msg>Small code modification<commit_after>/*
 * Copyright (C) 2014 <NAME> <<EMAIL>>
 *
 * Licensed 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 com.github.parboiled1.grappa.matchers.trie;

import com.google.common.base.Preconditions;
import org.parboiled.MatcherContext;
import org.parboiled.matchers.AbstractMatcher;
import org.parboiled.matchers.FirstOfMatcher;
import org.parboiled.matchers.FirstOfStringsMatcher;
import org.parboiled.matchervisitors.MatcherVisitor;
import org.parboiled.parserunners.RecoveringParseRunner;

import javax.annotation.concurrent.Immutable;

/**
 * The trie matcher
 *
 * <p>Note that there are a few crucial differences compared to a {@link
 * FirstOfStringsMatcher}:</p>
 *
 * <ul>
 *     <li>this matcher is insensitive about the ordering of its arguments;
 *     unlike {@link FirstOfMatcher}, for instance, it doesn't care about the
 *     order of appearance of strings with a common prefix;</li>
 *     <li>at this moment, it does not play well with a {@link
 *     RecoveringParseRunner} (a {@link FirstOfStringsMatcher} keeps all
 *     submatches information by its virtue of inheriting {@link
 *     FirstOfMatcher}, which has all character subrules).</li>
 * </ul>
 */
@Immutable
public final class TrieMatcher
    extends AbstractMatcher
{
    private final Trie trie;

    public TrieMatcher(final Trie trie)
    {
        super("Trie (" + Preconditions.checkNotNull(trie).getNrWords()
            + " strings)");
        this.trie = trie;
    }

    /**
     * Tries a match on the given MatcherContext.
     *
     * @param context the MatcherContext
     * @return true if the match was successful
     */
    @Override
    public <V> boolean match(final MatcherContext<V> context)
{'fraction_non_alphanumeric': 0.08881199538638986, 'fraction_numerical': 0.004152249134948097, 'mean_word_length': 3.7079261672095547, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3230237', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1206, 'n_words': 447}