Sherpa transform annotations to categories processor
Project description
pyprocessors_metadata_from_categories
Turn the categories carried by a document into a metadata value.
How it works
For every input document the processor converts its categories into a metadata entry and then clears the categories. Conversion happens systematically at both levels:
- Document level — the document's categories are turned into
document.metadata[metadata_name], thendocument.categoriesis cleared. - Segment level — the same conversion is applied to each sentence: its
categories become
sentence.metadata[metadata_name], then the sentence's categories are cleared.
For a given set of categories, only those whose score is greater than or equal
to multi_label_threshold are kept, and the resulting metadata value is:
None(the metadata key is removed) when no category passes the threshold,- a single value when exactly one category passes,
- a list of values when several categories pass.
Parameters
| Parameter | Default | Description |
|---|---|---|
metadata_name |
None |
Name of the generated metadata key. |
multi_label_threshold |
0.0 |
Only categories with a score greater than or equal to this value are kept. |
Installation
You can simply pip install pyprocessors_metadata_from_categories.
Developing
Pre-requesites
You will need to install uv (for managing the virtual environment and running tests):
pip install uv
Clone the repository:
git clone https://github.com/oterrier/pyprocessors_metadata_from_categories
Running the test suite
You can run the full test suite with:
uv run pytest
Linting
uv run ruff check .
uv run ruff format --check .
Building the documentation
You can build the HTML documentation with:
uv run --extra docs sphinx-build docs docs/_build
The built documentation is available at docs/_build/index.html.
SBOM & vulnerability check
Install the SBOM dependencies:
uv sync --extra sbom
Generate a CycloneDX SBOM from the current environment:
uv run cyclonedx-py environment -o sbom.cdx.json --output-format json
Audit dependencies for known vulnerabilities:
uv run pip-audit --format json --output audit-report.json
To fail on any known vulnerability (useful in CI):
uv run pip-audit --strict
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 pyprocessors_metadata_from_categories-1.6.1.tar.gz.
File metadata
- Download URL: pyprocessors_metadata_from_categories-1.6.1.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a52460f1bef355cd2eebf36a7afd8c0ef5bdb660acd075959e850bc17ecd0de6
|
|
| MD5 |
c7edbe7f29fc65aa359a017998991afe
|
|
| BLAKE2b-256 |
34c57ef83091a860667ab323a9ddd1d0efb3a5fd9fad4ff5c18102d92ef63ce3
|
File details
Details for the file pyprocessors_metadata_from_categories-1.6.1-py3-none-any.whl.
File metadata
- Download URL: pyprocessors_metadata_from_categories-1.6.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba2eaf71f1359ae36f38ce777ba49ec26681d0076ef80bc009ab031c022e408e
|
|
| MD5 |
bf478ee6723c2a7185591e91a559b0dd
|
|
| BLAKE2b-256 |
7bb1803dd0f1a565e5d38f9ca9f0b194040d870871646426c70dd8c8030bd83e
|