Spacy Syllables
A spacy 2+ pipeline component for adding multilingual syllable annotation to tokens.
- Uses well established pyphen for the syllables.
- Supports a ton of languages
- Ease of use thx to the awesome pipeline framework in spacy
Install
$ pip install spacy_syllables
which also installs the following dependencies:
- spacy = "^2.2.3"
- pyphen = "^0.9.5"
Usage
The SpacySyllables class autodetects language from the given spacy nlp instance, but you can also override the detected language by specifying the lang parameter during instantiation, see how here.
Normal usecase
import spacy
from spacy_syllables import SpacySyllables
nlp = spacy.load("en_core_web_sm")
nlp.add_pipe("syllables", after="tagger")
assert nlp.pipe_names == ["tok2vec", "tagger", "syllables", "parser", "ner", "attribute_ruler", "lemmatizer"]
doc = nlp("terribly long")
data = [(token.text, token._.syllables, token._.syllables_count) for token in doc]
assert data == [("terribly", ["ter", "ri", "bly"], 3), ("long", ["long"], 1)]
more examples in tests
Migrating from spacy 2.x to 3.0
In spacy 2.x, spacy_syllables was originally added to the pipeline by instantiating a SpacySyllables object with the desired options and adding it to the pipeline:
from spacy_syllables import SpacySyllables
syllables = SpacySyllables(nlp, "en_US")
nlp.add_pipe(syllables, after="tagger")
In spacy 3.0, you now add the component to the pipeline simply by adding it by name, setting custom configuration information in the add_pipe() parameters:
from spacy_syllables import SpacySyllables
nlp.add_pipe("syllables", after="tagger", config={"lang": "en_US"})
In addition, the default pipeline components have changed between 2.x and 3.0; please make sure to update any asserts you have that check for these. e.g.:
spacy 2.x:
assert nlp.pipe_names == ["tagger", "syllables", "parser", "ner"]
spacy 3.0:
assert nlp.pipe_names == ["tok2vec", "tagger", "syllables", "parser", "ner", "attribute_ruler", "lemmatizer"]
Dev setup / testing
install
install the dev package and pyenv versions
$ pip install -e ".[dev]"
$ python -m spacy download en_core_web_sm
run tests
$ black .
$ pytest
Metadata
Release files for spacy-syllables 3.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spacy_syllables-3.0.2.tar.gz | 4.7 kB | Without provenance | Details for spacy_syllables-3.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spacy_syllables-3.0.2-py3-none-any.whl | Python 3 | none | any | Details for spacy_syllables-3.0.2-py3-none-any.whl |
Total release size: 9.7 kB
Release files / spacy_syllables-3.0.2.tar.gz
| Download URL | spacy_syllables-3.0.2.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1f45a8307382daa0c65d32a996d84bd5dd90552f42e675f721342c35ba3d032b
|
|
BLAKE2b-256 checksum How to use checksums |
159ab94b12188ef0a08e5b87ab95f2f4018365ade7ff36ba22496e6af1c98b21
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / spacy_syllables-3.0.2-py3-none-any.whl
| Download URL | spacy_syllables-3.0.2-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c67cfc086624c643f510bb05c53c93c323de4357761b500ce8d9e48942618ed
|
|
BLAKE2b-256 checksum How to use checksums |
bcc0412775c4db008df8f5d3887e0d96fa4d14306b9ba8ae257c21aa98a3ec4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for spacy-syllables 3.0.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.