You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by to...@apache.org on 2024/03/11 12:21:28 UTC
(lucene) branch main updated: Adjust middle of sentence calculation and add test verifying correct behavior (#13170)
This is an automated email from the ASF dual-hosted git repository.
tommaso pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new 44fa35b65ff Adjust middle of sentence calculation and add test verifying correct behavior (#13170)
44fa35b65ff is described below
commit 44fa35b65ff43d695e6306aab70eeec371e00c77
Author: Tim Grein <ti...@elastic.co>
AuthorDate: Mon Mar 11 13:21:22 2024 +0100
Adjust middle of sentence calculation and add test verifying correct behavior (#13170)
---
.../lucene/analysis/opennlp/OpenNLPSentenceBreakIterator.java | 2 +-
.../analysis/opennlp/TestOpenNLPSentenceBreakIterator.java | 11 +++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/lucene/analysis/opennlp/src/java/org/apache/lucene/analysis/opennlp/OpenNLPSentenceBreakIterator.java b/lucene/analysis/opennlp/src/java/org/apache/lucene/analysis/opennlp/OpenNLPSentenceBreakIterator.java
index e3c2fb78320..d81b06fd90d 100644
--- a/lucene/analysis/opennlp/src/java/org/apache/lucene/analysis/opennlp/OpenNLPSentenceBreakIterator.java
+++ b/lucene/analysis/opennlp/src/java/org/apache/lucene/analysis/opennlp/OpenNLPSentenceBreakIterator.java
@@ -148,7 +148,7 @@ public final class OpenNLPSentenceBreakIterator extends BreakIterator {
currentSentence = 0;
return DONE;
} else {
- currentSentence = sentenceStarts.length / 2; // start search from the middle
+ currentSentence = (sentenceStarts.length - 1) / 2; // start search from the middle
moveToSentenceAt(pos, 0, sentenceStarts.length - 1);
if (0 == currentSentence) {
text.setIndex(text.getBeginIndex());
diff --git a/lucene/analysis/opennlp/src/test/org/apache/lucene/analysis/opennlp/TestOpenNLPSentenceBreakIterator.java b/lucene/analysis/opennlp/src/test/org/apache/lucene/analysis/opennlp/TestOpenNLPSentenceBreakIterator.java
index acd13da0037..465d067070e 100644
--- a/lucene/analysis/opennlp/src/test/org/apache/lucene/analysis/opennlp/TestOpenNLPSentenceBreakIterator.java
+++ b/lucene/analysis/opennlp/src/test/org/apache/lucene/analysis/opennlp/TestOpenNLPSentenceBreakIterator.java
@@ -203,6 +203,17 @@ public class TestOpenNLPSentenceBreakIterator extends LuceneTestCase {
test0Sentences(bi);
}
+ public void testPrecedingWithTwoSentences() throws IOException {
+ NLPSentenceDetectorOp sentenceDetectorOp =
+ OpenNLPOpsFactory.getSentenceDetector(sentenceModelFile);
+ BreakIterator bi = new OpenNLPSentenceBreakIterator(sentenceDetectorOp);
+ bi.setText("This is sentence one. This is sentence two.");
+
+ // set pos to somewhere in the second sentence
+ int precedingSentence = bi.preceding(25);
+ assertEquals(0, precedingSentence);
+ }
+
private void test0Sentences(BreakIterator bi) {
assertEquals(0, bi.current());
assertEquals(0, bi.first());