You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@opennlp.apache.org by "mawiesne (via GitHub)" <gi...@apache.org> on 2025/08/01 03:59:18 UTC
[PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
mawiesne opened a new pull request, #829:
URL: https://github.com/apache/opennlp/pull/829
Thank you for contributing to Apache OpenNLP.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [x] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [x] Does your PR title start with OPENNLP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [x] Has your PR been rebased against the latest commit within the target branch (typically main)?
- [x] Is your initial contribution a single, squashed commit?
### For code changes:
- [x] Have you ensured that the full suite of tests is executed via mvn clean install at the root opennlp folder?
- [x] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file in opennlp folder?
- [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found in opennlp folder?
### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check GitHub Actions for build issues and submit an update to your PR as soon as possible.
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne merged PR #829:
URL: https://github.com/apache/opennlp/pull/829
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on code in PR #829:
URL: https://github.com/apache/opennlp/pull/829#discussion_r2247836935
##########
opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/sentdetect/SentenceDetectorMEGermanTest.java:
##########
@@ -131,14 +140,41 @@ void testSentDetectWithUseTokenEndFalse() {
final String sent1 = "Träume sind eine Verbindung von Gedanken.";
final String sent2 = "Verschiedene Gedanken sind während der Traumformation aktiv.";
- SentenceDetectorME sentDetect = new SentenceDetectorME(sentdetectModel);
//There is no blank space before start of the second sentence.
- String[] sents = sentDetect.sentDetect(sent1 + sent2);
- double[] probs = sentDetect.probs();
+ String[] sents = sentenceDetector.sentDetect(sent1 + sent2);
+ double[] probs = sentenceDetector.probs();
- assertAll(() -> assertEquals(2, sents.length),
+ assertAll(
+ () -> assertEquals(2, sents.length),
() -> assertEquals(sent1, sents[0]),
() -> assertEquals(sent2, sents[1]),
() -> assertEquals(2, probs.length));
}
+
+ /*
+ * A reproducer and test for OPENNLP-1767.
+ * It checks that sentence detection with common abbreviations works correctly,
+ * that is, tokenks such as "lt.", "f.", "S." (page), "ca.", or "ugs." do not cause
Review Comment:
Thx for the pointer. Will resolve it.
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on code in PR #829:
URL: https://github.com/apache/opennlp/pull/829#discussion_r2248003500
##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java:
##########
@@ -340,15 +340,27 @@ protected boolean isAcceptableBreak(CharSequence s, int fromIndex, int candidate
return true;
for (StringList abb : abbDict) {
- String token = abb.getToken(0);
+ final String token = abb.getToken(0);
+ final int tokenPosition = s.toString().indexOf(token, fromIndex);
+ if (tokenPosition == -1) {
+ continue; // skip fast
+ }
+ final char prevChar = s.charAt(tokenPosition - 1);
int tokenLength = token.length();
- int tokenPosition = s.toString().indexOf(token, fromIndex);
- if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex)
- continue;
+ if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex ||
+ /*
+ * Note:
+ * Skip abbreviation candidate if regular characters exist directly before it,
+ * That is, any letter or digit except: a whitespace, an apostrophe, or an opening round bracket.
+ * This prevents mismatches from overlaps close to an actual sentence end.
+ */
+ !(prevChar == ' ' || prevChar == '\'' || prevChar == '`' || prevChar == '´' || prevChar == '(')) {
Review Comment:
Would it be beneficial to check for `Character.isWhitespace(...)` instead of `' '` to cover other whitespace derivations?
##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java:
##########
@@ -340,15 +340,27 @@ protected boolean isAcceptableBreak(CharSequence s, int fromIndex, int candidate
return true;
for (StringList abb : abbDict) {
- String token = abb.getToken(0);
+ final String token = abb.getToken(0);
+ final int tokenPosition = s.toString().indexOf(token, fromIndex);
+ if (tokenPosition == -1) {
+ continue; // skip fast
+ }
+ final char prevChar = s.charAt(tokenPosition - 1);
int tokenLength = token.length();
- int tokenPosition = s.toString().indexOf(token, fromIndex);
- if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex)
- continue;
+ if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex ||
+ /*
+ * Note:
+ * Skip abbreviation candidate if regular characters exist directly before it,
+ * That is, any letter or digit except: a whitespace, an apostrophe, or an opening round bracket.
Review Comment:
Comment misses `\`.
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on code in PR #829:
URL: https://github.com/apache/opennlp/pull/829#discussion_r2248144570
##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java:
##########
@@ -340,15 +340,27 @@ protected boolean isAcceptableBreak(CharSequence s, int fromIndex, int candidate
return true;
for (StringList abb : abbDict) {
- String token = abb.getToken(0);
+ final String token = abb.getToken(0);
+ final int tokenPosition = s.toString().indexOf(token, fromIndex);
+ if (tokenPosition == -1) {
+ continue; // skip fast
+ }
+ final char prevChar = s.charAt(tokenPosition - 1);
int tokenLength = token.length();
- int tokenPosition = s.toString().indexOf(token, fromIndex);
- if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex)
- continue;
+ if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex ||
+ /*
+ * Note:
+ * Skip abbreviation candidate if regular characters exist directly before it,
+ * That is, any letter or digit except: a whitespace, an apostrophe, or an opening round bracket.
+ * This prevents mismatches from overlaps close to an actual sentence end.
+ */
+ !(prevChar == ' ' || prevChar == '\'' || prevChar == '`' || prevChar == '´' || prevChar == '(')) {
Review Comment:
Yes. Willl resolve it as suggested.
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "NishantShri4 (via GitHub)" <gi...@apache.org>.
NishantShri4 commented on code in PR #829:
URL: https://github.com/apache/opennlp/pull/829#discussion_r2247473595
##########
opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/sentdetect/SentenceDetectorMEGermanTest.java:
##########
@@ -131,14 +140,41 @@ void testSentDetectWithUseTokenEndFalse() {
final String sent1 = "Träume sind eine Verbindung von Gedanken.";
final String sent2 = "Verschiedene Gedanken sind während der Traumformation aktiv.";
- SentenceDetectorME sentDetect = new SentenceDetectorME(sentdetectModel);
//There is no blank space before start of the second sentence.
- String[] sents = sentDetect.sentDetect(sent1 + sent2);
- double[] probs = sentDetect.probs();
+ String[] sents = sentenceDetector.sentDetect(sent1 + sent2);
+ double[] probs = sentenceDetector.probs();
- assertAll(() -> assertEquals(2, sents.length),
+ assertAll(
+ () -> assertEquals(2, sents.length),
() -> assertEquals(sent1, sents[0]),
() -> assertEquals(sent2, sents[1]),
() -> assertEquals(2, probs.length));
}
+
+ /*
+ * A reproducer and test for OPENNLP-1767.
+ * It checks that sentence detection with common abbreviations works correctly,
+ * that is, tokenks such as "lt.", "f.", "S." (page), "ca.", or "ugs." do not cause
Review Comment:
Thanks for the changes. We can correct some typos i.e. _tokenks_ and _accidentially_.
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on code in PR #829:
URL: https://github.com/apache/opennlp/pull/829#discussion_r2248220625
##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java:
##########
@@ -340,15 +340,27 @@ protected boolean isAcceptableBreak(CharSequence s, int fromIndex, int candidate
return true;
for (StringList abb : abbDict) {
- String token = abb.getToken(0);
+ final String token = abb.getToken(0);
+ final int tokenPosition = s.toString().indexOf(token, fromIndex);
+ if (tokenPosition == -1) {
+ continue; // skip fast
+ }
+ final char prevChar = s.charAt(tokenPosition - 1);
int tokenLength = token.length();
- int tokenPosition = s.toString().indexOf(token, fromIndex);
- if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex)
- continue;
+ if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex ||
+ /*
+ * Note:
+ * Skip abbreviation candidate if regular characters exist directly before it,
+ * That is, any letter or digit except: a whitespace, an apostrophe, or an opening round bracket.
Review Comment:
Dot ends my comment. / is the char not mentioned in the description.
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "NishantShri4 (via GitHub)" <gi...@apache.org>.
NishantShri4 commented on PR #829:
URL: https://github.com/apache/opennlp/pull/829#issuecomment-3144541886
> > Lgtm. Thanks. However, It seems I don't have permissions to approve.
>
> You should be able to approve. Can you check again?
Thanks. Done.
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on code in PR #829:
URL: https://github.com/apache/opennlp/pull/829#discussion_r2248142968
##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java:
##########
@@ -340,15 +340,27 @@ protected boolean isAcceptableBreak(CharSequence s, int fromIndex, int candidate
return true;
for (StringList abb : abbDict) {
- String token = abb.getToken(0);
+ final String token = abb.getToken(0);
+ final int tokenPosition = s.toString().indexOf(token, fromIndex);
+ if (tokenPosition == -1) {
+ continue; // skip fast
+ }
+ final char prevChar = s.charAt(tokenPosition - 1);
int tokenLength = token.length();
- int tokenPosition = s.toString().indexOf(token, fromIndex);
- if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex)
- continue;
+ if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex ||
+ /*
+ * Note:
+ * Skip abbreviation candidate if regular characters exist directly before it,
+ * That is, any letter or digit except: a whitespace, an apostrophe, or an opening round bracket.
Review Comment:
I don't get "\.". There is no check for an escaped dot.
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "NishantShri4 (via GitHub)" <gi...@apache.org>.
NishantShri4 commented on PR #829:
URL: https://github.com/apache/opennlp/pull/829#issuecomment-3144439231
Lgtm. Thanks. However, It seems I don't have permissions to approve.
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on PR #829:
URL: https://github.com/apache/opennlp/pull/829#issuecomment-3144526375
> Lgtm. Thanks. However, It seems I don't have permissions to approve.
You should have be able to approve. Can you check again?
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1767: Fix sentence detection when an abbreviation overlaps at sentence end (opennlp)
Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on code in PR #829:
URL: https://github.com/apache/opennlp/pull/829#discussion_r2248223227
##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/sentdetect/SentenceDetectorME.java:
##########
@@ -340,15 +340,27 @@ protected boolean isAcceptableBreak(CharSequence s, int fromIndex, int candidate
return true;
for (StringList abb : abbDict) {
- String token = abb.getToken(0);
+ final String token = abb.getToken(0);
+ final int tokenPosition = s.toString().indexOf(token, fromIndex);
+ if (tokenPosition == -1) {
+ continue; // skip fast
+ }
+ final char prevChar = s.charAt(tokenPosition - 1);
int tokenLength = token.length();
- int tokenPosition = s.toString().indexOf(token, fromIndex);
- if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex)
- continue;
+ if (tokenPosition + tokenLength < candidateIndex || tokenPosition > candidateIndex ||
+ /*
+ * Note:
+ * Skip abbreviation candidate if regular characters exist directly before it,
+ * That is, any letter or digit except: a whitespace, an apostrophe, or an opening round bracket.
Review Comment:
But I didn't saw the escaped ', so all good. 😁🙂
--
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: dev-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org