ReductionSettings.java

1
/*******************************************************************************
2
 * Copyright (C) 2026, Leo Galambos
3
 * All rights reserved.
4
 * 
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 * 
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 
11
 * 2. Redistributions in binary form must reproduce the above copyright notice,
12
 *    this list of conditions and the following disclaimer in the documentation
13
 *    and/or other materials provided with the distribution.
14
 * 
15
 * 3. All advertising materials mentioning features or use of this software must
16
 *    display the following acknowledgement:
17
 *    This product includes software developed by the Egothor project.
18
 * 
19
 * 4. Neither the name of the copyright holder nor the names of its contributors
20
 *    may be used to endorse or promote products derived from this software
21
 *    without specific prior written permission.
22
 * 
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
 * POSSIBILITY OF SUCH DAMAGE.
34
 ******************************************************************************/
35
package org.egothor.stemmer;
36
37
import java.util.Objects;
38
39
/**
40
 * Immutable reduction configuration used by {@link FrequencyTrie.Builder}.
41
 *
42
 * <p>
43
 * The settings influence how mutable trie nodes are merged into canonical
44
 * read-only nodes during compilation.
45
 * 
46
 * @param reductionMode                 reduction mode
47
 * @param dominantWinnerMinPercent      minimum dominant winner percentage
48
 * @param dominantWinnerOverSecondRatio minimum winner-over-second ratio
49
 */
50
@SuppressWarnings("PMD.LongVariable")
51
public record ReductionSettings(ReductionMode reductionMode, int dominantWinnerMinPercent,
52
        int dominantWinnerOverSecondRatio) {
53
54
    /**
55
     * Default minimum dominant winner percentage.
56
     */
57
    public static final int DEFAULT_DOMINANT_WINNER_MIN_PERCENT = 75;
58
59
    /**
60
     * Default minimum winner-over-second ratio.
61
     */
62
    public static final int DEFAULT_DOMINANT_WINNER_OVER_SECOND_RATIO = 3;
63
64
    /**
65
     * Creates a new instance.
66
     *
67
     * @param reductionMode                 reduction mode
68
     * @param dominantWinnerMinPercent      minimum dominant winner percentage in
69
     *                                      the inclusive range {@code 1..100}
70
     * @param dominantWinnerOverSecondRatio minimum winner-over-second ratio, must
71
     *                                      be at least {@code 1}
72
     * @throws NullPointerException     if {@code reductionMode} is {@code null}
73
     * @throws IllegalArgumentException if any numeric value is outside the valid
74
     *                                  range
75
     */
76
    public ReductionSettings(final ReductionMode reductionMode, final int dominantWinnerMinPercent,
77
            final int dominantWinnerOverSecondRatio) {
78
        this.reductionMode = Objects.requireNonNull(reductionMode, "reductionMode");
79
        if (dominantWinnerMinPercent < 1 || dominantWinnerMinPercent > 100) {
80
            throw new IllegalArgumentException("dominantWinnerMinPercent must be in range 1..100.");
81
        }
82
        if (dominantWinnerOverSecondRatio < 1) { // NOPMD
83
            throw new IllegalArgumentException("dominantWinnerOverSecondRatio must be at least 1.");
84
        }
85
        this.dominantWinnerMinPercent = dominantWinnerMinPercent;
86
        this.dominantWinnerOverSecondRatio = dominantWinnerOverSecondRatio;
87
    }
88
89
    /**
90
     * Creates settings with default dominance thresholds.
91
     *
92
     * @param reductionMode reduction mode
93
     * @return new settings instance
94
     * @throws NullPointerException if {@code reductionMode} is {@code null}
95
     */
96
    public static ReductionSettings withDefaults(final ReductionMode reductionMode) {
97 1 1. withDefaults : replaced return value with null for org/egothor/stemmer/ReductionSettings::withDefaults → KILLED
        return new ReductionSettings(reductionMode, DEFAULT_DOMINANT_WINNER_MIN_PERCENT,
98
                DEFAULT_DOMINANT_WINNER_OVER_SECOND_RATIO);
99
    }
100
}

Mutations

97

1.1
Location : withDefaults
Killed by : org.egothor.stemmer.StemmerPatchTrieLoaderTest.[engine:junit-jupiter]/[class:org.egothor.stemmer.StemmerPatchTrieLoaderTest]/[nested-class:ApiContractTests]/[test-template:shouldRejectNullArguments(java.lang.String, org.egothor.stemmer.StemmerPatchTrieLoaderTest$ExecutableOperation, java.lang.String)]
replaced return value with null for org/egothor/stemmer/ReductionSettings::withDefaults → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1