Standalone abbreviation detection component extracted from scispacy.
Project description
unv_scispacy_abbr
A standalone abbreviation detection component extracted from the scispacy project. This package provides robust abbreviation detection for scientific and biomedical text using the Schwartz & Hearst algorithm.
Features
- Standalone: No scispacy dependencies - works with any spaCy pipeline
- Compatible API: Drop-in replacement for
scispacy.abbreviation - Robust Detection: Handles various abbreviation patterns including reverse definitions
- Scientific Focus: Optimized for scientific and biomedical text
- Lightweight: Minimal dependencies (only requires spaCy)
Installation
pip install unv-scispacy-abbr
Quick Start
As a spaCy Pipeline Component
import spacy
from unv_scispacy_abbr import AbbreviationDetector
# Create a spaCy pipeline (any language model works)
nlp = spacy.load("en_core_web_sm") # or spacy.blank("en")
# Add the abbreviation detector to the pipeline
nlp.add_pipe("abbreviation_detector")
# Process text
doc = nlp("Spinal and bulbar muscular atrophy (SBMA) is a motor neuron disease.")
# Access detected abbreviations
for abbrev in doc._.abbreviations:
print(f"Abbreviation: {abbrev}")
print(f"Long form: {abbrev._.long_form}")
Standalone Functions
from unv_scispacy_abbr import find_abbreviation, filter_matches
import spacy
nlp = spacy.blank("en")
doc = nlp("machine learning (ML) and artificial intelligence (AI)")
# Manual abbreviation detection
long_form = doc[0:2] # "machine learning"
short_form = doc[3:4] # "ML"
short, long = find_abbreviation(long_form, short_form)
if long:
print(f"Found: {short} -> {long}")
Supported Patterns
The detector recognizes various abbreviation patterns:
- Standard:
Long Form (SF)→ "Long Form" abbreviated as "SF" - Reverse:
SF (Long Form)→ "SF" is the abbreviation of "Long Form" - Multiple words:
Multiple Word Form (MWF) - With numbers/hyphens:
Long-Form 2.0 (LF-2)
Examples
import spacy
from unv_scispacy_abbr import AbbreviationDetector
nlp = spacy.blank("en")
nlp.add_pipe("abbreviation_detector")
# Example 1: Biomedical text
text1 = """
The androgen receptor (AR) plays a crucial role in spinal and bulbar
muscular atrophy (SBMA). AR mutations cause SBMA in patients.
"""
doc1 = nlp(text1)
for abbrev in doc1._.abbreviations:
print(f"{abbrev} = {abbrev._.long_form}")
# Output:
# AR = androgen receptor
# SBMA = spinal and bulbar muscular atrophy
# AR = androgen receptor
# SBMA = spinal and bulbar muscular atrophy
# Example 2: Reverse pattern
text2 = "We used BERT (Bidirectional Encoder Representations from Transformers) for NLP."
doc2 = nlp(text2)
for abbrev in doc2._.abbreviations:
print(f"{abbrev} = {abbrev._.long_form}")
# Output: BERT = Bidirectional Encoder Representations from Transformers
Migration from scispacy
If you're using scispacy.abbreviation, you can easily migrate:
# Before (scispacy)
from scispacy.abbreviation import AbbreviationDetector
# After (this package)
from unv_scispacy_abbr import AbbreviationDetector
The API is fully compatible, so no other code changes are needed.
Algorithm
This package implements the abbreviation detection algorithm described in:
Schwartz, A. S., & Hearst, M. A. (2003). A simple algorithm for identifying abbreviation definitions in biomedical text. Pacific symposium on biocomputing, 451-462.
Requirements
- Python ≥ 3.8
- spaCy ≥ 3.3, < 4.0
Development
# Clone the repository
git clone <repository-url>
cd unv_scispacy_abbr
# Install in development mode
pip install -e .
# Run tests
pytest tests/
License
Apache License 2.0
Credits
This package is extracted and adapted from the scispacy project by AllenAI. The original implementation was created by the scispacy team and contributors.
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 unv_scispacy_abbr-0.1.1.tar.gz.
File metadata
- Download URL: unv_scispacy_abbr-0.1.1.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4459df8c1c3ca1a0080d8d89aee873a342ad9d5f498eb85190d2148e57f31418
|
|
| MD5 |
c19ada29c3cea4a37052799620fe56db
|
|
| BLAKE2b-256 |
53224a4e793c73d770769365ef8d6b9a173b1973f853924dff2f2109fcca8111
|
File details
Details for the file unv_scispacy_abbr-0.1.1-py3-none-any.whl.
File metadata
- Download URL: unv_scispacy_abbr-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
859a0869c8ac0649e8ebd06b62380a6e273c0deac9cd7934e28857776c0b1b25
|
|
| MD5 |
1597fe06d54cd2507a316a61e7796dbb
|
|
| BLAKE2b-256 |
e95d52dd3bb2ab7167c2fad5e02836bcb8baddf23160876e09fdcb777d5e5271
|