BratEval Wrapper for NLP
This library wraps the Java-based BratEval utility to evaluate annotation data for named-entity-recognition (NER). Given the availability of the Git, Java JDK and Maven, it clones and compiles brateval and wraps the io interactions into Python.
Note that currently the release v0.3.2 of brateval is used. See: https://github.com/READ-BioMed/brateval/tree/v0.3.2
Note that a valid Java JDK and Maven environment must be set up correctly.
Install
First, make sure to install a Java JDK environment as well as Maven (for compiling the JAR file) before using the wrapper.
[Click to show] Preparation instructions for Ubuntu
# Install Java (11, or 21), Maven and Git first
sudo apt install -y openjdk-21-jdk-headless maven git
# Add JAVA_HOME variable to ~/.bashrc
echo 'export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")' >> $HOME/.bashrc
# Login again to re-load the JAVA_HOME environment variable (or export the variable manually)
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
Eventually, install the package using pip: python3 -m pip install bratevalwrapper4nlp
Example
The following script demonstrates the use of the evaluate function.
import json
from bratevalwrapper4nlp import evaluate
# Define document (ground truth and prediction)
doc_ground_truth = {
"text": "This is a fine example.",
"label": [
(10, 14, "LABEL2"),
(15, 22, "LABEL1"),
]
}
doc_prediction = {
"text": "This is a fine example.",
"label": [
(10, 22, "LABEL1"),
]
}
# Verify the text spans
for src, doc in {"Ground Truth": doc_ground_truth, "Prediction": doc_prediction}.items():
for lbl_start, lbl_stop, lbl_cls in doc.get("label", []):
print("[{}] {} has label {}".format(
src,
repr(doc["text"][lbl_start:lbl_stop]),
lbl_cls
))
# Run evaluation
score_response = evaluate(
doc_ground_truth, # or list of docs: [doc_ground_truth]
doc_prediction, # or list of docs: [doc_prediction]
span_match="overlap", # "overlap", "exact", or float (overlap percentage between 1.0 and 0.0)
type_match="exact" # "exact", or "inexact" (ignores label classes)
)
scores = score_response["scores"]
print("Obtained scores:")
print(json.dumps(scores, indent=2))
Metadata
Release files for bratevalwrapper4nlp 0.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 |
|---|---|---|---|---|
| bratevalwrapper4nlp-0.0.2.tar.gz | 5.5 kB | Without provenance | Details for bratevalwrapper4nlp-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bratevalwrapper4nlp-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for bratevalwrapper4nlp-0.0.2-py3-none-any.whl |
Total release size: 12.0 kB
Release files / bratevalwrapper4nlp-0.0.2.tar.gz
| Download URL | bratevalwrapper4nlp-0.0.2.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5372b0c095d41779d34a43ee42d8b5e0164ca808c3eb93b1b4f179c61484a80e
|
|
BLAKE2b-256 checksum How to use checksums |
3b13f495ed6da63257ac8ef5dab58d9e7767be5f58311e10c174de6f86efb32e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / bratevalwrapper4nlp-0.0.2-py3-none-any.whl
| Download URL | bratevalwrapper4nlp-0.0.2-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
56321a398966389bdb7250a948dfb65c5584337c4b718f9036e6e32451b1aca4
|
|
BLAKE2b-256 checksum How to use checksums |
1c9c116e22731cc35c636c892fec06fd1be8b26090427ff477e070599485b30b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Security for bratevalwrapper4nlp 0.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.