A fast implementation of RuSH (Rule-based sentence Segmenter using Hashing).
Project description
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py4jrush-1.0.12.tar.gz.
File metadata
- Download URL: py4jrush-1.0.12.tar.gz
- Upload date:
- Size: 39.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
766f46f86f4e7a6bdc140be523a02fd680a7e4a8636c60c163a0a7b5dd5d171f
|
|
| MD5 |
0729b2edc17e60fcd9520eb7663ab6f4
|
|
| BLAKE2b-256 |
fc5e133cfe4d77b936ddc5952242f1bf97d31b068e006d1cc0edbbb37705ede2
|
Provenance
The following attestation bundles were made for py4jrush-1.0.12.tar.gz:
Publisher:
build_publish.yml on jianlins/py4jrush
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py4jrush-1.0.12.tar.gz -
Subject digest:
766f46f86f4e7a6bdc140be523a02fd680a7e4a8636c60c163a0a7b5dd5d171f - Sigstore transparency entry: 519243623
- Sigstore integration time:
-
Permalink:
jianlins/py4jrush@47579f26559aa73f2a8622a18c675183a214e0e1 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/jianlins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_publish.yml@47579f26559aa73f2a8622a18c675183a214e0e1 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file py4jrush-1.0.12-py3-none-any.whl.
File metadata
- Download URL: py4jrush-1.0.12-py3-none-any.whl
- Upload date:
- Size: 39.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36bcacc37a77febd97da297d22ef80b243a6bf71220d18981777f8168c9d2b6d
|
|
| MD5 |
ae4fb6525cde3fdbae9b1caf320d29db
|
|
| BLAKE2b-256 |
3049e6d2e56828227f7809e2526b2f2ec5cbaa7a40c11e1cff20f13207179473
|
Provenance
The following attestation bundles were made for py4jrush-1.0.12-py3-none-any.whl:
Publisher:
build_publish.yml on jianlins/py4jrush
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py4jrush-1.0.12-py3-none-any.whl -
Subject digest:
36bcacc37a77febd97da297d22ef80b243a6bf71220d18981777f8168c9d2b6d - Sigstore transparency entry: 519243701
- Sigstore integration time:
-
Permalink:
jianlins/py4jrush@47579f26559aa73f2a8622a18c675183a214e0e1 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/jianlins
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_publish.yml@47579f26559aa73f2a8622a18c675183a214e0e1 -
Trigger Event:
workflow_dispatch
-
Statement type: