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