dweiss commented on code in PR #11893:
URL: https://github.com/apache/lucene/pull/11893#discussion_r1014272956


##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/Suggester.java:
##########
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+package org.apache.lucene.analysis.hunspell;
+
+import static org.apache.lucene.analysis.hunspell.Dictionary.FLAG_UNSET;
+import static org.apache.lucene.analysis.hunspell.TimeoutPolicy.NO_TIMEOUT;
+import static org.apache.lucene.analysis.hunspell.WordContext.COMPOUND_BEGIN;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import org.apache.lucene.util.CharsRef;
+
+/**
+ * A generator for misspelled word corrections based on Hunspell flags. The 
suggestions are searched
+ * for in two main ways:
+ *
+ * <ol>
+ *   <li>Modification: trying to insert/remove/delete/swap parts of the word 
to get something
+ *       acceptable. The performance of this part depends heavily on the 
contents of TRY, MAP, REP,
+ *       KEY directives in the .aff file.
+ *   <li>Enumeration: if the modification hasn't produced "good enough" 
suggestions, the whole
+ *       dictionary is scanned and simple affixes are added onto the entries 
to check if that
+ *       produces anything similar to the given misspelled word. This depends 
on the dictionary size
+ *       and the affix count, and it can take noticeable amount of time. To 
speed this up, {@link
+ *       #withSuggestibleEntryCache()} can be used.
+ * </ol>
+ */
+public class Suggester {
+  private final Dictionary dictionary;
+  private final SuggestibleEntryCache suggestibleCache;
+
+  public Suggester(Dictionary dictionary) {
+    this(dictionary, null);
+  }
+
+  private Suggester(Dictionary dictionary, SuggestibleEntryCache 
suggestibleCache) {
+    this.dictionary = dictionary;
+    this.suggestibleCache = suggestibleCache;
+  }
+
+  /**
+   * Returns a copy of this suggester instance with better "Enumeration" phase 
performance (see
+   * {@link Suggester} documentation), but using more memory. With this 
option, the dictionary
+   * entries are stored as fast-to-iterate plain words instead of highly 
compressed prefix trees.
+   */
+  public Suggester withSuggestibleEntryCache() {

Review Comment:
   Ok, makes sense. Thanks for explaining this to me - looking at the diff 
only, I didn't get the whole picture. I still feel like that static mutating 
method is a bit awkward but if it's an experimental API then it's fine to 
change it as you go - no problem there.
   
   As for naming - if nobody from the English part of the world expresses their 
opinion - leave it as it is. I really don't feel like I'm in the position to 
have the final say here :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to