mirror of https://github.com/apache/lucene.git
Adjust middle of sentence calculation and add test verifying correct behavior (#13170)
This commit is contained in:
parent
3f4413567d
commit
44fa35b65f
|
@ -148,7 +148,7 @@ public final class OpenNLPSentenceBreakIterator extends BreakIterator {
|
||||||
currentSentence = 0;
|
currentSentence = 0;
|
||||||
return DONE;
|
return DONE;
|
||||||
} else {
|
} 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);
|
moveToSentenceAt(pos, 0, sentenceStarts.length - 1);
|
||||||
if (0 == currentSentence) {
|
if (0 == currentSentence) {
|
||||||
text.setIndex(text.getBeginIndex());
|
text.setIndex(text.getBeginIndex());
|
||||||
|
|
|
@ -203,6 +203,17 @@ public class TestOpenNLPSentenceBreakIterator extends LuceneTestCase {
|
||||||
test0Sentences(bi);
|
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) {
|
private void test0Sentences(BreakIterator bi) {
|
||||||
assertEquals(0, bi.current());
|
assertEquals(0, bi.current());
|
||||||
assertEquals(0, bi.first());
|
assertEquals(0, bi.first());
|
||||||
|
|
Loading…
Reference in New Issue