Converts source code into human-friendly labels
Project description
source_label_map
Converts source code into human-friendly labels
Quickstart
Using get_source_labels
directly
from bilbyai.source_label_map import get_source_labels
get_source_labels("ben") # outputs 'Beijing Evening News'
get_source_labels(["gmwnews", "ben"]) # outputs ['Enlightenment Daily', 'Beijing Evening News']
get_source_labels("cannot-be-found") # outputs 'cannot-be-found'
get_source_labels("cannot-be-found", when_not_found="set_none") # outputs None
get_source_labels("cannot-be-found", when_not_found="set_unknown") # outputs 'unknown'
get_source_labels("ben", when_not_found="throw_error") # raises ValueError
Using get_source_labels
with DataFrames
import pandas as pd
from bilbyai.source_label_map import get_source_labels
df = pd.DataFrame(
{
"source": [
"gmwnews",
"ben",
"cannot-be-found",
"zqrb",
]
}
)
# Option A: using list comprehension
df["source_label"] = get_source_labels(df["source"])
# Option B: using apply
df["source_label"] = df["source"].apply(get_source_labels)
df["source_label"]
# Outputs:
# 0 Enlightenment Daily
# 1 Beijing Evening News
# 2 cannot-be-found
# 3 Securities Daily
# Name: source_label, dtype: object
Function Specs
Get source labels for a list of inputs.
Args:
inputs
(str | Iterable[str]
): The string or list of strings to get source labels for.
when_not_found
: The action to take when a source label is not found. Set to "preserve_source_name" by default.
"preserve_source_name"
: Preserve the source name as the source label."set_to_none"
: Set the source label to None."set_to_unknown"
: Set the source label to "unknown"."throw_error"
: Raise an error if a source label is not found.
source_label_dict
: A dictionary mapping source names to source labels.
Returns:
A list of source labels for the inputs.
Raises:
ValueError
: If the when_not_found value is not recognized.
ValueError
: If the inputs are not a string or iterable of strings.
ValueError
: If when_not_found is set to "throw_error" and a source label is not found.
The project owner is @leetdavid.
Development
If not already in a virtual environement, create and use one. Read about it in the Python documentation: venv — Creation of virtual environments.
python3 -m venv .venv
source .venv/bin/activate
Install the pinned pip version:
pip install -r $(git rev-parse --show-toplevel)/pip-requirements.txt
Finally, install the dependencies:
pip install -r $(git rev-parse --show-toplevel)/dev-requirements.txt -r requirements.txt
Testing
Execute tests from the library's folder (after having loaded the virtual environment, see above) as follows:
python3 -m pytest tests/
Execute the library's CI locally with act as follows:
act -j ci-libs-source_label_map
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
File details
Details for the file bilbyai_source_label_map-0.2.1.tar.gz
.
File metadata
- Download URL: bilbyai_source_label_map-0.2.1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fcad4d13a697737ab85766ebcf222388afe7c3f49411390fbfe327b17c806d3 |
|
MD5 | 864c78ddc6a0563efb207a91d1ab0954 |
|
BLAKE2b-256 | e5025654f427b3b45ff2965baa51593c018acd8d2a86f73ecd082fdc3c4baef7 |
File details
Details for the file bilbyai_source_label_map-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: bilbyai_source_label_map-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 383adb3c1a781a522e85d894751ce7695fc3d9e9c37680c50dbb4f64660f7ac7 |
|
MD5 | a3740fc703b4179fcfe425aea270e5bd |
|
BLAKE2b-256 | 338f05079345b255d05051401776cded12796bc94b55bcec065fbe127b0a42b7 |