rmuir commented on issue #13706:
URL: https://github.com/apache/lucene/issues/13706#issuecomment-2324880374

   Here's a round two, to prevent any error on NFA or having transitions to 
dead states:
   ```
   diff --git 
a/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java 
b/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
   index 2052b1c50bf..10103628fad 100644
   --- a/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
   +++ b/lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java
   @@ -864,14 +864,25 @@ public final class Operations {
    
      /**
       * Returns true if the given automaton accepts all strings for the 
specified min/max range of the
   -   * alphabet. The automaton must be minimized.
   +   * alphabet. The automaton must be deterministic with no transitions to 
dead states.
       */
      public static boolean isTotal(Automaton a, int minAlphabet, int 
maxAlphabet) {
   -    if (a.isAccept(0) && a.getNumTransitions(0) == 1) {
   +    // minimal case
   +    if (a.getNumStates() == 1 && a.isAccept(0) && a.getNumTransitions(0) == 
1) {
          Transition t = new Transition();
          a.getTransition(0, 0, t);
          return t.dest == 0 && t.min == minAlphabet && t.max == maxAlphabet;
        }
   +    // deterministic case
   +    if (a.isDeterministic() && hasDeadStatesFromInitial(a) == false) {
   +      Automaton a2 = new Automaton();
   +      int s = a2.createState();
   +      a2.setAccept(s, true);
   +      a2.addTransition(s, s, minAlphabet, maxAlphabet);
   +      a2.finishState();
   +      return sameLanguage(a, a2);
   +    }
   +    // NFA, or has transitions to dead states, return false
        return false;
      }
   ```


-- 
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