<commit_before>/*
 * Licensed to Crate.io GmbH ("Crate") under one or more contributor
 * license agreements.  See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.  Crate licenses
 * this file to you 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.
 *
 * However, if you have executed another commercial license agreement
 * with Crate these terms will supersede the license and you may use the
 * software solely pursuant to the terms of the relevant commercial agreement.
 */

package io.crate.analyze;

import com.google.common.base.Predicates;

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.function.Predicate;

import static java.util.Map.entry;

public class MatchOptionsAnalysis {

    private static final Predicate<Object> POSITIVE_NUMBER = x -> x instanceof Number && ((Number) x).doubleValue() > 0;
    private static final Predicate<Object> IS_STRING = x -> x instanceof String;
    private static final Predicate<Object> IS_NUMBER = x -> x instanceof Number;
    private static final Predicate<Object> NUMBER_OR_STRING = IS_NUMBER.or(IS_STRING);

    private static final Map<String, Predicate<Object>> ALLOWED_SETTINGS = Map.ofEntries(
        entry("analyzer", IS_STRING),
        entry("boost", POSITIVE_NUMBER),
        entry("cutoff_frequency", POSITIVE_NUMBER),
        entry("fuzziness", NUMBER_OR_STRING), // validated at ES QueryParser
        entry("fuzzy_rewrite", IS_STRING),
        entry("max_expansions", POSITIVE_NUMBER),
        entry("minimum_should_match", NUMBER_OR_STRING),
        entry(
            "operator",
            Predicates.in(List.of("or", "and", "OR", "AND"))),
        entry("prefix_length", POSITIVE_NUMBER),
        entry("rewrite", IS_STRING),<commit_msg>Remove Guava's Predicates<commit_after>/*
 * Licensed to Crate.io GmbH ("Crate") under one or more contributor
 * license agreements.  See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.  Crate licenses
 * this file to you 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.
 *
 * However, if you have executed another commercial license agreement
 * with Crate these terms will supersede the license and you may use the
 * software solely pursuant to the terms of the relevant commercial agreement.
 */

package io.crate.analyze;

import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;

import static java.util.Map.entry;

public class MatchOptionsAnalysis {

    private static final Predicate<Object> POSITIVE_NUMBER = x -> x instanceof Number && ((Number) x).doubleValue() > 0;
    private static final Predicate<Object> IS_STRING = x -> x instanceof String;
    private static final Predicate<Object> IS_NUMBER = x -> x instanceof Number;
    private static final Predicate<Object> NUMBER_OR_STRING = IS_NUMBER.or(IS_STRING);
    private static final Predicate<Object> IS_OPERATOR = Set.of("or", "and", "OR", "AND")::contains;

    private static final Map<String, Predicate<Object>> ALLOWED_SETTINGS = Map.ofEntries(
        entry("analyzer", IS_STRING),
        entry("boost", POSITIVE_NUMBER),
        entry("cutoff_frequency", POSITIVE_NUMBER),
        entry("fuzziness", NUMBER_OR_STRING), // validated at ES QueryParser
        entry("fuzzy_rewrite", IS_STRING),
        entry("max_expansions", POSITIVE_NUMBER),
        entry("minimum_should_match", NUMBER_OR_STRING),
        entry("operator", IS_OPERATOR),
        entry("prefix_length", POSITIVE_NUMBER),
        entry("rewrite", IS_STRING),
{'fraction_non_alphanumeric': 0.08932840686807215, 'fraction_numerical': 0.0021734405564007822, 'mean_word_length': 4.0627062706270625, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 24, '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': '4739754', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1215, 'n_words': 468}