You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(text-analyzer): count sentence ends only before whitespace or the end of text - #807
The text-analyzer reference skill split sentences with re.split(r"[.!?]+", text), so every period inside a token started a new sentence. On main (9757f986):
Open input.txt and report the totals. counted 2 sentences.
Pi is 3.14. Done! counted 3.
Ship v1.2.3 today. counted 3.
URLs and e-mail addresses were split the same way.
The skill's description names files such as input.txt as normal input, and SKILL.md documented only abbreviations as a known gap.
A run of ., ! or ? now ends a sentence only when whitespace or the end of the text follows it. Closing quotes or brackets right after the terminator still count, so He said "go." Then left. is 2 sentences. Text with no terminator still counts as 1, and empty or whitespace-only text counts as 0. The starter eval text still reports 3 sentences, Wait... what? still reports 2, and word, line, character, average-length and top-word results do not change. Abbreviations followed by a space (Dr. Smith) still split, and the Limitations entry in SKILL.md now says so.
--file used to crash with a traceback when given a directory (IsADirectoryError: [Errno 21] Is a directory) or an unreadable file. It now prints a message on stderr and exits 1 with no traceback:
Error: not a file: <path> for a directory.
Error: cannot read file: <path> (<reason>) for any other read error.
The existing Error: file not found: <path> is unchanged. The Troubleshooting table lists all three messages.
Did not add credentials, private datasets, or proprietary benchmark content
Release Impact
No user-visible release note needed
Updated CHANGELOG.md
Commands run
Platform: Linux 6.12.113+ x86_64, Python 3.13.5 (uv), on top of upstream 9757f986.
Branch version of tests/test_reference_text_analyzer.py run against untouched upstream/main: 7 failed, 12 passed. The failures are the file name, decimal, version, URL and e-mail sentence counts, plus the directory and unreadable-file cases.
This branch:
uv run pytest -n 0 tests/test_reference_text_analyzer.py tests/test_reference_skill_scripts.py: 37 passed.
uv run make lint: All checks passed.
uv run ruff format --check on the two touched Python files: 2 files already formatted.
uv run make build: Successfully built skillevaluator-1.0.1.tar.gz and skillevaluator-1.0.1-py3-none-any.whl.
PYTEST_ADDOPTS='--deselect tests/test_harbor_secure_docker_environment.py::test_windows_transfer_repeated_cancellation_reaps_process_and_removes_partial_output' uv run make test: 56 failed, 42477 passed, 168 skipped, 20 deselected, 297 errors. Untouched upstream/main with the same command: 56 failed, 42758 passed, 168 skipped, 20 deselected. The 56 failures are the same node IDs on both sides: 27 Docker-client tests in tests/test_harbor_secure_docker_environment.py, 15 Rich terminal-width assertions in tests/reporting/, 3 in tests/test_harbor_local_mode.py, 2 NeMo Gym backend tests, and 9 other tier3/harness/hygiene tests. The deselected Windows-transfer test hangs the serial run on untouched upstream/main too. The 297 errors were setup failures in tests/tier3/test_network_uploads_from_code_and_configs.py (OSError: could not create numbered dir under /tmp/pytest-of-box) because the machine ran out of inodes during the run. Re-running that module alone gave 2150 passed on this branch and 2150 passed on upstream/main.
Not verified: the unreadable-file test on Windows or as root. It is skipped there because permission bits do not apply.
… end of text
The analyzer split on every run of .!? so periods inside file names, decimals,
and version numbers started extra sentences, and --file on a directory or an
unreadable path printed a traceback.
Sentence ends now count only when the terminator is followed by whitespace or
the end of the text, with optional closing quotes or brackets. For those path
problems --file now prints an error on stderr and exits 1.
Signed-off-by: Matt Van Horn <mvanhorn@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a clear improvement and the numbers people rely on do not move. I reproduced the overcount on main (input.txt, 3.14 and v1.2.3 each split), copied the branch tests onto main (7 fail, the five token cases plus the two --file error cases) and ran them here (37 passed with test_reference_skill_scripts.py). I also re-ran the analyzer on everything that quotes a sentence count: the starter fixture still gives 4 words, 2 lines, 27 characters, 2 sentences, the eval text still gives 3, and the evals2 texts give the same counts before and after. U.S., e.g., URLs, ellipses, ?! and a sentence ending at end of text all behave as documented, and the regex has no backtracking problem on long inputs.
One non-blocking note inline about curly closing quotes, which the new trailing class does not include. The --file error handling for directories and unreadable files is a nice touch and the Troubleshooting table matches the messages.
Ruff and format are clean, DCO is signed, CHANGELOG entry is under Unreleased.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The sentence-boundary pattern excludes typographic closing quotes, causing ordinary quoted prose to be undercounted compared with the previous behavior.
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mvanhorn for this contribution. File names, decimals, versions, URLs and e-mail addresses now stay in one sentence, and the new --file messages behave as described. The tests pass here (37 passed with test_reference_skill_scripts.py), and ruff is clean.
I left two inline comments. The new pattern takes quadratic time on long runs of terminators, and a citation marker or Markdown emphasis after a terminator now merges two sentences. The curly-quote note already on line 18 still applies.
Treat curly double, curly single and angle closing quotes like straight
quotes after a terminator, and add regression cases next to the dotted
token tests.
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
A long punctuation run followed by a non-boundary character, such as "!" * n + "word", causes quadratic backtracking because the regex retries the failed run from every punctuation character. A standalone check took about 0.06, 0.25, and 0.99 seconds for 2,000, 4,000, and 8,000 characters, so larger inputs can stall sentence counting. Add a negative lookbehind to restrict matches to the start of each punctuation run while preserving the intended boundaries.
Allow Markdown * and _ and numeric citations such as [1] between a
terminator and the following whitespace, so "1993.[1] The" and
"**done.** Next" count as two sentences again.
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
This pattern takes quadratic time on a punctuation run followed by ordinary text, such as 'Start' + '.' * n + 'suffix', because matching restarts at every period. An isolated check took about 0.10 seconds for 2,000 periods and 1.56 seconds for 8,000, so larger punctuation-heavy inputs can stall analysis. Add (?<![.!?]) before [.!?]+ to prevent these retries while preserving the sentence-boundary behavior.
A run of `.`, `!` or `?` followed by a non-boundary character made
re.split retry the pattern at every position inside the run, and each
attempt backtracked through the rest of it, so the time grew with the
square of the run length (40,000 dots took about a minute).
Start a match only at the first terminator of a run and take the run
possessively, so a failed run costs one pass. Sentence counts are
unchanged.
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Possessive regex quantifiers require Python 3.11, causing immediate module failure on the advertised Python 3.10 target and breaking both inline and file analysis.
@rng1995 the quadratic case is fixed in 855fd66: the (?<![.!?]) lookbehind now starts a match only at the first terminator of a run, and a timing test covers a 50,000-dot run followed by x. That commit also made the run possessive, which as you noted needs Python 3.11, so I'll push a follow-up that drops it back to a plain +, since the lookbehind alone keeps the split linear.
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mvanhorn for this contribution! I reviewed a9216419fb: I read the change and its callers, ran probes on the head, and checked the tests and docs. I left 2 inline comments (2 P3); please take a look. One more blocker outside the code: the DCO check is failing because the latest commit, a9216419fb ("Address review feedback"), has no Signed-off-by: trailer. Amend it with git commit --amend --signoff --no-edit and push with --force-with-lease; the other non-merge commits are already signed.
…osers
Exercise the PermissionError branch on every platform by monkeypatching
Path.read_text, so a broken Windows directory fallback fails the suite.
Also cover sentence ends before ', ], } and the single guillemet.
Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
Re-reviewed at 9d9f5d8. The Markdown footnote case now keeps both sentences, the closing punctuation cases are covered, and unreadable paths still produce the correct diagnostic. All 58 focused tests passed. GitHub is awaiting authorization to run this fork's workflows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The text-analyzer reference skill split sentences with
re.split(r"[.!?]+", text), so every period inside a token started a new sentence. Onmain(9757f986):Open input.txt and report the totals.counted 2 sentences.Pi is 3.14. Done!counted 3.Ship v1.2.3 today.counted 3.The skill's description names files such as
input.txtas normal input, andSKILL.mddocumented only abbreviations as a known gap.A run of
.,!or?now ends a sentence only when whitespace or the end of the text follows it. Closing quotes or brackets right after the terminator still count, soHe said "go." Then left.is 2 sentences. Text with no terminator still counts as 1, and empty or whitespace-only text counts as 0. The starter eval text still reports 3 sentences,Wait... what?still reports 2, and word, line, character, average-length and top-word results do not change. Abbreviations followed by a space (Dr. Smith) still split, and the Limitations entry inSKILL.mdnow says so.--fileused to crash with a traceback when given a directory (IsADirectoryError: [Errno 21] Is a directory) or an unreadable file. It now prints a message on stderr and exits 1 with no traceback:Error: not a file: <path>for a directory.Error: cannot read file: <path> (<reason>)for any other read error.The existing
Error: file not found: <path>is unchanged. The Troubleshooting table lists all three messages.Verification
make lintmake testmake buildRelease Impact
CHANGELOG.mdCommands run
Platform: Linux 6.12.113+ x86_64, Python 3.13.5 (uv), on top of upstream
9757f986.tests/test_reference_text_analyzer.pyrun against untouchedupstream/main: 7 failed, 12 passed. The failures are the file name, decimal, version, URL and e-mail sentence counts, plus the directory and unreadable-file cases.uv run pytest -n 0 tests/test_reference_text_analyzer.py tests/test_reference_skill_scripts.py: 37 passed.uv run make lint: All checks passed.uv run ruff format --checkon the two touched Python files: 2 files already formatted.uv run make build: Successfully builtskillevaluator-1.0.1.tar.gzandskillevaluator-1.0.1-py3-none-any.whl.PYTEST_ADDOPTS='--deselect tests/test_harbor_secure_docker_environment.py::test_windows_transfer_repeated_cancellation_reaps_process_and_removes_partial_output' uv run make test: 56 failed, 42477 passed, 168 skipped, 20 deselected, 297 errors. Untouchedupstream/mainwith the same command: 56 failed, 42758 passed, 168 skipped, 20 deselected. The 56 failures are the same node IDs on both sides: 27 Docker-client tests intests/test_harbor_secure_docker_environment.py, 15 Rich terminal-width assertions intests/reporting/, 3 intests/test_harbor_local_mode.py, 2 NeMo Gym backend tests, and 9 other tier3/harness/hygiene tests. The deselected Windows-transfer test hangs the serial run on untouchedupstream/maintoo. The 297 errors were setup failures intests/tier3/test_network_uploads_from_code_and_configs.py(OSError: could not create numbered dirunder/tmp/pytest-of-box) because the machine ran out of inodes during the run. Re-running that module alone gave 2150 passed on this branch and 2150 passed onupstream/main.Not verified: the unreadable-file test on Windows or as root. It is skipped there because permission bits do not apply.
Demo
Full recording (MP4): https://raw.githubusercontent.com/mvanhorn/pr-demo-assets/main/osc-bulk-1119se/text-analyzer-sentence-ends/out.mp4