Skip to content

OPENNLP-1946: UrlCharSequenceNormalizer removes whole URLs including ports, userinfo and non-ASCII hosts - #1315

Merged
rzo1 merged 2 commits into
mainfrom
OPENNLP-1946-url-normalizer
Sep 18, 2026
Merged

rzo1 merged 2 commits into
mainfrom
OPENNLP-1946-url-normalizer

Conversation

@rzo1

@rzo1 rzo1 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Replaces #1295, reworked as discussed in the review there. Kristian's commit is kept as the first commit. Based on main, which has StringUtil.isAsciiLetter since #1311.

What changes

UrlCharSequenceNormalizer is fixed in place instead of getting a separate opt-in class:

  • An http or https URL (any letter case, with a left boundary) is removed as a whole, up to the next Unicode whitespace, control character, unpaired surrogate, typographic quote or < > ". Ports, userinfo, percent escapes, bracketed IPv6 hosts and non-ASCII hosts and paths are included.
  • Trailing . , ; : ! ?, a trailing apostrophe and closing brackets without their opening bracket are given back: (http://example.com/a). gives ( )., 'http://example.com/a' gives ' '.
  • URLs with other schemes (git+https://, telnet://, redis://, ...) are kept, and no email address is matched inside them.
  • Under -Dopennlp.compat.mode=LEGACY (OPENNLP-1973: Regex removal (prep): Add a CompatibilityMode switch for the earlier output #1312) the earlier output is produced, for language detector models trained with it. The existing characterization test against the former regexes now runs under LEGACY.

BoundedUrlCharSequenceNormalizer is removed; its rules and its tests move to the default. The ASCII letter/digit set moves from MailAddressScan to AsciiChars, and the scheme check uses StringUtil.isAsciiLetter. The manual row in the language detector chapter describes the new output and the LEGACY switch; the opt-in section is gone.

Before merge

  • Language detector eval build: the normalizer is in the default chain, so the default output changes.

Commits by @krickert (#1295) and @rzo1.

OPENNLP-1946

@rzo1

rzo1 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

https://ci-builds.apache.org/job/OpenNLP/job/eval-tests-configurable/80/

@rzo1
rzo1 force-pushed the OPENNLP-1946-url-normalizer branch from b894023 to 62fd146 Compare September 18, 2026 13:29
Base automatically changed from OPENNLP-1928-regex-removal-scans to main September 18, 2026 17:04
krickert and others added 2 commits September 18, 2026 19:06
…and document the limits of the default

The default normalizer and the language detector chain are unchanged, and the
class Javadoc states the limits found with the WHATWG URL test data. The new
class removes http and https URLs with ports, userinfo, percent escapes, IPv6
hosts and non-ASCII paths, bounded by whitespace and delimiters, with a left
boundary before the scheme, in linear time. The manual describes both and how
to opt in.
…e earlier output as LEGACY

UrlCharSequenceNormalizer now removes each http or https URL as a whole,
including a port, userinfo, percent escapes, a bracketed IPv6 host and
non-ASCII hosts and paths, and gives back trailing punctuation, a trailing
apostrophe and unbalanced closing brackets. Under
CompatibilityMode.LEGACY it produces the earlier output for language
detector models trained with it. BoundedUrlCharSequenceNormalizer is
removed; its rules and tests move to the default. The ASCII letter and
digit set moves to AsciiChars, and the scheme check uses
StringUtil.isAsciiLetter.
@rzo1
rzo1 force-pushed the OPENNLP-1946-url-normalizer branch from 62fd146 to 3a40854 Compare September 18, 2026 17:07
@rzo1
rzo1 marked this pull request as ready for review September 18, 2026 17:10
@mawiesne mawiesne added java Pull requests that update Java code tests Pull requests that add or update test code labels Sep 18, 2026

@mawiesne mawiesne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and clean. Thx @krickert & @rzo1

@mawiesne

Copy link
Copy Markdown
Contributor

@rzo1
rzo1 merged commit f2ab1cc into main Sep 18, 2026
10 checks passed
@rzo1
rzo1 deleted the OPENNLP-1946-url-normalizer branch September 18, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

java Pull requests that update Java code tests Pull requests that add or update test code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants