You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "zhaih (via GitHub)" <gi...@apache.org> on 2023/12/11 12:14:46 UTC

[PR] Fix bug where NFARunAutomaton#getTransition does not set Transition correctly [lucene]

zhaih opened a new pull request, #12909:
URL: https://github.com/apache/lucene/pull/12909

   ### Description
   
   Fix: #12906 
   <!--
   If this is your first contribution to Lucene, please make sure you have reviewed the contribution guide.
   https://github.com/apache/lucene/blob/main/CONTRIBUTING.md
   -->
   


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix bug where NFARunAutomaton#getTransition does not set Transition correctly [lucene]

Posted by "zhaih (via GitHub)" <gi...@apache.org>.
zhaih merged PR #12909:
URL: https://github.com/apache/lucene/pull/12909


-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix bug where NFARunAutomaton#getTransition does not set Transition correctly [lucene]

Posted by "zhaih (via GitHub)" <gi...@apache.org>.
zhaih commented on code in PR #12909:
URL: https://github.com/apache/lucene/pull/12909#discussion_r1426010905


##########
lucene/core/src/test/org/apache/lucene/util/automaton/TestNFARunAutomaton.java:
##########
@@ -73,6 +73,37 @@ public void testWithRandomRegex() {
     }
   }
 
+  public void testRandomAccessTransition() {
+    Automaton nfa = new RegExp(AutomatonTestUtil.randomRegexp(random()), RegExp.NONE).toAutomaton();
+    while (nfa.isDeterministic()) {
+      nfa = new RegExp(AutomatonTestUtil.randomRegexp(random()), RegExp.NONE).toAutomaton();
+    }
+    NFARunAutomaton runAutomaton1, runAutomaton2;
+    runAutomaton1 = new NFARunAutomaton(nfa);
+    runAutomaton2 = new NFARunAutomaton(nfa);
+    assertRandomAccessTransition(runAutomaton1, runAutomaton2, 0, new HashSet<>());
+  }
+
+  private void assertRandomAccessTransition(
+      NFARunAutomaton automaton1, NFARunAutomaton automaton2, int state, Set<Integer> visited) {
+    if (visited.contains(state)) {
+      return;
+    }
+    visited.add(state);
+
+    Transition t1 = new Transition();
+    Transition t2 = new Transition();
+    automaton1.initTransition(state, t1);
+    automaton2.initTransition(state, t2);

Review Comment:
   Yeah that's actually true, let me add the flag



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix bug where NFARunAutomaton#getTransition does not set Transition correctly [lucene]

Posted by "zhaih (via GitHub)" <gi...@apache.org>.
zhaih commented on code in PR #12909:
URL: https://github.com/apache/lucene/pull/12909#discussion_r1424011845


##########
lucene/core/src/test/org/apache/lucene/util/automaton/TestNFARunAutomaton.java:
##########
@@ -73,6 +73,37 @@ public void testWithRandomRegex() {
     }
   }
 
+  public void testRandomAccessTransition() {
+    Automaton nfa = new RegExp(AutomatonTestUtil.randomRegexp(random()), RegExp.NONE).toAutomaton();
+    while (nfa.isDeterministic()) {
+      nfa = new RegExp(AutomatonTestUtil.randomRegexp(random()), RegExp.NONE).toAutomaton();
+    }
+    NFARunAutomaton runAutomaton1, runAutomaton2;
+    runAutomaton1 = new NFARunAutomaton(nfa);
+    runAutomaton2 = new NFARunAutomaton(nfa);
+    assertRandomAccessTransition(runAutomaton1, runAutomaton2, 0, new HashSet<>());
+  }
+
+  private void assertRandomAccessTransition(
+      NFARunAutomaton automaton1, NFARunAutomaton automaton2, int state, Set<Integer> visited) {
+    if (visited.contains(state)) {
+      return;
+    }
+    visited.add(state);
+
+    Transition t1 = new Transition();
+    Transition t2 = new Transition();
+    automaton1.initTransition(state, t1);
+    automaton2.initTransition(state, t2);

Review Comment:
   Yeah but I think with the current contract we always need to `initTransition` to know the total number of Transitions, no matter using RA or getNext?



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix bug where NFARunAutomaton#getTransition does not set Transition correctly [lucene]

Posted by "Tony-X (via GitHub)" <gi...@apache.org>.
Tony-X commented on code in PR #12909:
URL: https://github.com/apache/lucene/pull/12909#discussion_r1424472195


##########
lucene/core/src/test/org/apache/lucene/util/automaton/TestNFARunAutomaton.java:
##########
@@ -73,6 +73,37 @@ public void testWithRandomRegex() {
     }
   }
 
+  public void testRandomAccessTransition() {
+    Automaton nfa = new RegExp(AutomatonTestUtil.randomRegexp(random()), RegExp.NONE).toAutomaton();
+    while (nfa.isDeterministic()) {
+      nfa = new RegExp(AutomatonTestUtil.randomRegexp(random()), RegExp.NONE).toAutomaton();
+    }
+    NFARunAutomaton runAutomaton1, runAutomaton2;
+    runAutomaton1 = new NFARunAutomaton(nfa);
+    runAutomaton2 = new NFARunAutomaton(nfa);
+    assertRandomAccessTransition(runAutomaton1, runAutomaton2, 0, new HashSet<>());
+  }
+
+  private void assertRandomAccessTransition(
+      NFARunAutomaton automaton1, NFARunAutomaton automaton2, int state, Set<Integer> visited) {
+    if (visited.contains(state)) {
+      return;
+    }
+    visited.add(state);
+
+    Transition t1 = new Transition();
+    Transition t2 = new Transition();
+    automaton1.initTransition(state, t1);
+    automaton2.initTransition(state, t2);

Review Comment:
   > but I think with the current contract we always need to initTransition
   
   Well, not necessarily.  One can do the following without calling init. 
   
   ```
   var n = automaton2.getNumTransitions(state);
   automaton2.getTransition(state, i, t2);
   ```



-- 
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-unsubscribe@lucene.apache.org

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


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


Re: [PR] Fix bug where NFARunAutomaton#getTransition does not set Transition correctly [lucene]

Posted by "Tony-X (via GitHub)" <gi...@apache.org>.
Tony-X commented on code in PR #12909:
URL: https://github.com/apache/lucene/pull/12909#discussion_r1423089503


##########
lucene/core/src/test/org/apache/lucene/util/automaton/TestNFARunAutomaton.java:
##########
@@ -73,6 +73,37 @@ public void testWithRandomRegex() {
     }
   }
 
+  public void testRandomAccessTransition() {
+    Automaton nfa = new RegExp(AutomatonTestUtil.randomRegexp(random()), RegExp.NONE).toAutomaton();
+    while (nfa.isDeterministic()) {
+      nfa = new RegExp(AutomatonTestUtil.randomRegexp(random()), RegExp.NONE).toAutomaton();
+    }
+    NFARunAutomaton runAutomaton1, runAutomaton2;
+    runAutomaton1 = new NFARunAutomaton(nfa);
+    runAutomaton2 = new NFARunAutomaton(nfa);
+    assertRandomAccessTransition(runAutomaton1, runAutomaton2, 0, new HashSet<>());
+  }
+
+  private void assertRandomAccessTransition(
+      NFARunAutomaton automaton1, NFARunAutomaton automaton2, int state, Set<Integer> visited) {
+    if (visited.contains(state)) {
+      return;
+    }
+    visited.add(state);
+
+    Transition t1 = new Transition();
+    Transition t2 = new Transition();
+    automaton1.initTransition(state, t1);
+    automaton2.initTransition(state, t2);

Review Comment:
   maybe add a random flag here. For the RA API you don't strictly need to init, as long as you know the state and the index of the transition. 



-- 
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-unsubscribe@lucene.apache.org

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


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