py4jrush
py4jrush is the python interface to RuSH(https://github.com/jianlins/RuSH) (Ru le-based sentence S egmenter using H ashing), which is originally developed using Java. This version is implemented through py4j, compared with the original PyRuSH.
RuSH is an efficient, reliable, and easy adaptable rule-based sentence segmentation solution. It is specifically designed to handle the telegraphic written text in clinical note. It leverages a nested hash table to execute simultaneous rule processing, which reduces the impact of the rule-base growth on execution time and eliminates the effect of rule order on accuracy.
If you wish to cite RuSH in a publication, please use:
Jianlin Shi ; Danielle Mowery ; Kristina M. Doing-Harris ; John F. Hurdle.RuSH: a Rule-based Segmentation Tool Using Hashing for Extremely Accurate Sentence Segmentation of Clinical Text. AMIA Annu Symp Proc. 2016: 1587.
The full text can be found here.
Installation
When you run pip install py4jrush, the installer will automatically check for Java JDK 8. If JDK 8 is not found, it will use the install-jdk Python package to download and install JDK 8 for you. No manual Java setup is required.
pip install py4jrush
Development and Release Process
This project uses automated workflows for building, testing, and releasing. Here's how it works:
Automated Release Workflow
The project has an automated release workflow that:
- Automatically bumps version numbers using semantic versioning
- Builds and tests the package across multiple environments
- Publishes to PyPI with proper validation
- Creates GitHub releases with built artifacts
How to Release
Option 1: Manual Workflow Trigger (Recommended)
- Go to the Actions tab in GitHub
- Select Build and Publish Python Package workflow
- Click Run workflow and configure:
- Publish to PyPI:
true(to actually publish) - Create GitHub release:
true(to create a release) - Version bump type: Choose
patch,minor, ormajor
- Publish to PyPI:
Option 2: GitHub Release Creation
Create a new release in the GitHub UI, and the workflow will automatically trigger.
Version Bumping Strategy
- patch (1.0.10 → 1.0.11): Bug fixes, small changes
- minor (1.0.10 → 1.1.0): New features, backwards compatible
- major (1.0.10 → 2.0.0): Breaking changes
Workflow Features
- ✅ Automatic version detection from current VERSION file
- ✅ Smart version bumping prevents conflicts with existing releases
- ✅ Multi-environment testing (Python 3.9, 3.10, 3.11 on Ubuntu, Windows, macOS)
- ✅ PyPI validation with twine before publishing
- ✅ Automatic VERSION file updates after successful release
- ✅ GitHub release creation with built artifacts
How to use
A standalone RuSH class is available to be directly used in your code. From 1.0.4, pyRush adopt spaCy 3.x api to initiate an component.
Basic Usage
from py4jrush import RuSH
input_str = "The patient was admitted on 03/26/08\n and was started on IV antibiotics elevation" +\
", was also counseled to minimizing the cigarette smoking. The patient had edema\n\n" +\
"\n of his bilateral lower extremities. The hospital consult was also obtained to " +\
"address edema issue question was related to his liver hepatitis C. Hospital consult" +\
" was obtained. This included an ultrasound of his abdomen, which showed just mild " +\
"cirrhosis. "
rush = RuSH('../conf/rush_rules.tsv')
sentences=rush.segToSentenceSpans(input_str)
for sentence in sentences:
print("Sentence({0}-{1}):\t>{2}<".format(sentence.begin, sentence.end, input_str[sentence.begin:sentence.end]))
Maximum Sentence Length Control
The RuSH class now supports a max_sentence_length parameter that automatically splits sentences exceeding a specified character limit. This is particularly useful for downstream NLP tasks that have input length constraints.
from py4jrush import RuSH
# Initialize RuSH with maximum sentence length of 100 characters
rush = RuSH('../conf/rush_rules.tsv', max_sentence_length=100, enable_logger=True)
# Long sentence that will be automatically split
long_text = "This is a very long clinical sentence that contains multiple medical concepts and exceeds the maximum length limit, so it will be intelligently split into smaller segments at appropriate boundaries like whitespace or punctuation marks to ensure each resulting sentence stays within the specified character limit."
sentences = rush.segToSentenceSpans(long_text)
for i, sentence in enumerate(sentences):
segment = long_text[sentence.begin:sentence.end]
print(f"Sentence {i} (length {len(segment)}): {segment}")
Splitting Strategy
When max_sentence_length is specified, RuSH uses an intelligent splitting strategy:
- Whitespace preferred: Splits at word boundaries when possible
- Punctuation fallback: Splits at punctuation marks (
,,;,., etc.) when no whitespace is available - Force split: Hard split at character limit when no good split points exist
Parameters
max_sentence_length(Optional[int]): Maximum allowed sentence length in characters. IfNone(default), no length-based splitting is performed.enable_logger(bool): WhenTrue, enables detailed logging of the splitting process.
Example Output
Sentence 0 (length 98): This is a very long clinical sentence that contains multiple medical concepts and exceeds the
Sentence 1 (length 97): maximum length limit, so it will be intelligently split into smaller segments at appropriate
Sentence 2 (length 87): boundaries like whitespace or punctuation marks to ensure each resulting sentence
Sentence 3 (length 58): stays within the specified character limit.
Constructor Parameters
The RuSH class constructor accepts the following parameters:
RuSH(rules='', min_sent_chars=5, enable_logger=False, py4jar=None, rushjar=None, java_path='java', max_sentence_length=None)
rules(Union[str, List]): Path to segmentation rules file or list of rule stringsmin_sent_chars(int): Minimum sentence length in characters (default: 5)enable_logger(bool): Whether to enable logging (default: False)py4jar(Optional[str]): Path to py4j JAR file (auto-detected if None)rushjar(Optional[str]): Path to RuSH JAR file (auto-detected if None)java_path(str): Path to Java executable (default: 'java')max_sentence_length(Optional[int]): Maximum sentence length in characters (default: None - no splitting)
Metadata
Release files for py4jrush 1.0.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py4jrush-1.0.13.tar.gz | 39.6 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py4jrush-1.0.13-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 79.2 MB
Release files / py4jrush-1.0.13.tar.gz
| Download URL | py4jrush-1.0.13.tar.gz |
|---|---|
| Size | 39.6 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
35e53f4370a19b3c15c38ac6eee4865a3d1750075e2ebed68ecc23a0a50eb326
|
|
BLAKE2b-256 checksum How to use checksums |
63f4d5e7e1f130b04e171830479ff6e19233cc6820f425e4a915f7135dc1d2da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 15, 2025.
Transparency logRelease files / py4jrush-1.0.13-py3-none-any.whl
| Download URL | py4jrush-1.0.13-py3-none-any.whl |
|---|---|
| Size | 39.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e312d13987e540795e7b75eedeb816d7c22a98bc15fed489ca1b1197ad8c07ac
|
|
BLAKE2b-256 checksum How to use checksums |
4e76fbf45b60388c8f6cfa19dc2f054fb729ffed1989083aafe425b8457c768f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 15, 2025.
Transparency log