You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by do...@apache.org on 2024/03/07 11:30:56 UTC
(lucene) 02/03: hunspell: allow ignoring exceptions on duplicate ICONV/OCONV mappings (#13155)
This is an automated email from the ASF dual-hosted git repository.
donnerpeter pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit ed343f49dac4ba5cc06ed66107d1374cdeffa1cd
Author: Peter Gromov <pe...@jetbrains.com>
AuthorDate: Tue Mar 5 09:54:20 2024 +0100
hunspell: allow ignoring exceptions on duplicate ICONV/OCONV mappings (#13155)
hunspell: allow ignoring exceptions on duplicate ICONV/OCONV mappings
(cherry picked from commit 44d48df4b7cb76af9748f8c873e3b8ebcfb08675)
---
lucene/CHANGES.txt | 2 ++
.../java/org/apache/lucene/analysis/hunspell/Dictionary.java | 10 +++++++++-
.../org/apache/lucene/analysis/hunspell/TestDictionary.java | 5 +++++
.../org/apache/lucene/analysis/hunspell/forgivable-errors.aff | 6 +++++-
4 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index c5c43bd553a..7c0c6db6f17 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -24,6 +24,8 @@ Improvements
* GITHUB#13087: Changed `static final Set` constants to be immutable. Among others it affected
ScandinavianNormalizer.ALL_FOLDINGS set with public access. (Dmitry Cherniachenko)
+* GITHUB#13155: Hunspell: allow ignoring exceptions on duplicate ICONV/OCONV mappings (Peter Gromov)
+
Optimizations
---------------------
diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
index 9d23aca9a6e..3be870efd36 100644
--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Dictionary.java
@@ -815,7 +815,7 @@ public class Dictionary {
for (int i = 0; i < num; i++) {
String[] parts = splitBySpace(reader, reader.readLine(), 3);
- if (mappings.put(parts[1], parts[2]) != null) {
+ if (mappings.put(parts[1], parts[2]) != null && !tolerateDuplicateConversionMappings()) {
throw new IllegalStateException("duplicate mapping specified for: " + parts[1]);
}
}
@@ -1162,6 +1162,14 @@ public class Dictionary {
return false;
}
+ /**
+ * Whether duplicate ICONV/OCONV lines should be silently ignored. False by default: an {@link
+ * IllegalStateException} will happen.
+ */
+ protected boolean tolerateDuplicateConversionMappings() {
+ return false;
+ }
+
char[] allNonSuggestibleFlags() {
return Dictionary.toSortedCharArray(
Stream.of(HIDDEN_FLAG, noSuggest, forbiddenword, onlyincompound, subStandard)
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java
index 6bef82d7b39..852e2cb3f65 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestDictionary.java
@@ -206,6 +206,11 @@ public class TestDictionary extends LuceneTestCase {
protected boolean tolerateAffixRuleCountMismatches() {
return true;
}
+
+ @Override
+ protected boolean tolerateDuplicateConversionMappings() {
+ return true;
+ }
};
}
}
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/forgivable-errors.aff b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/forgivable-errors.aff
index b9b56cc5d65..cb093496691 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/forgivable-errors.aff
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/forgivable-errors.aff
@@ -12,4 +12,8 @@ MAP a b
SFX A Y 1
SFX A nout l [aeiouyáéíóúýůěr][^aeiouyáéíóúýůěrl][^aeiouy
-SFX A b c d
\ No newline at end of file
+SFX A b c d
+
+ICONV 2
+ICONV x y
+ICONV x y
\ No newline at end of file