Skip to main content

nzilbb-labbcat

DOI

Client library for communicating with LaBB-CAT servers using Python.

e.g.

import labbcat

# Connect to the LaBB-CAT corpus
corpus = labbcat.LabbcatView("https://labbcat.canterbury.ac.nz/demo", "demo", "demo")

# Find all tokens of a word
matches = corpus.getMatches({"orthography":"quake"})

# Get the recording of that utterance
audio = corpus.getSoundFragments(matches)

# Get Praat TextGrids for the utterances
textgrids = corpus.getFragments(
    matches, ["utterance", "word","segment"],
    "text/praat-textgrid")

LaBB-CAT is a web-based linguistic annotation store that stores audio or video recordings, text transcripts, and other annotations.

Annotations of various types can be automatically generated or manually added.

LaBB-CAT servers are usually password-protected linguistic corpora, and can be accessed manually via a web browser, or programmatically using a client library like this one.

The current version of this library requires LaBB-CAT version 20220307.1126.

API documentation is available at https://nzilbb.github.io/labbcat-py/

Basic usage

nzilbb-labbcat is available in the Python Package Index here

To install the module:

pip install nzilbb-labbcat

The following example shows how to:

  1. upload a transcript to LaBB-CAT,
  2. wait for the automatic annotation tasks to finish,
  3. extract the annotation labels, and
  4. delete the transcript from LaBB-CAT.
import labbcat

# Connect to the LaBB-CAT corpus
corpus = labbcat.LabbcatEdit("http://localhost:8080/labbcat", "labbcat", "labbcat")

# List the corpora on the server
corpora = corpus.getCorpusIds()

# List the transcript types
transcript_type_layer = corpus.getLayer("transcript_type")
transcript_types = transcript_type_layer["validLabels"]

# Upload a transcript
corpus_id = corpora[0]
transcript_type = next(iter(transcript_types))
taskId = corpus.newTranscript(
    "test/labbcat-py.test.txt", None, None, transcript_type, corpus_id, "test")

# wait for the annotation generation to finish
corpus.waitForTask(taskId)
corpus.releaseTask(taskId)

# get the "POS" layer annotations
annotations = corpus.getAnnotations("labbcat-py.test.txt", "pos")
labels = list(map(lambda annotation: annotation["label"], annotations))

# find all /a/ segments (phones) in the whole corpus
results = corpus.getMatches({ "segment" : "a" })

# get the start/end times of the segments
segments = corpus.getMatchAnnotations(results, "segment", offsetThreshold=50)

# get F1/F2 at the midpoint of each /a/ vowel
formantsAtMidpoint = corpus.processWithPraat(
  labbcat.praatScriptFormants(), 0.025, results, segments)

# delete tha transcript from the corpus
corpus.deleteTranscript("labbcat-py.test.txt")

For batch uploading and other example code, see the examples subdirectory.

Developers

Create a virtual environment (once only):

python3 -m venv labbcat-env

Before running any of the commands below:

source labbcat-env/bin/activate

To build, test, release, and document the module, the following prerequisites are required:

  • pip3 install twine
  • pip3 install pathlib
  • pip3 install deprecated
  • pip3 install setuptools
  • sudo apt install python3-sphinx

Unit tests

python3 -m unittest

...or for specific test suites:

python3 -m unittest test.TestLabbcatAdmin

... or for specific tests:

python3 -m unittest test.TestLabbcatEdit.test_generateLayerUtterances

Documentation generation

cd docs
make clean
make

Publishing

rm dist/*
python3 setup.py sdist bdist_wheel
twine check dist/*
twine upload dist/*

Metadata

Release files for nzilbb-labbcat 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nzilbb-labbcat 1.1.4
File Size Uploaded Provenance Actions
nzilbb_labbcat-1.1.4.tar.gz 55.2 kB Without provenance Details for nzilbb_labbcat-1.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nzilbb-labbcat 1.1.4
File Interpreter ABI Platform Actions
nzilbb_labbcat-1.1.4-py3-none-any.whl Python 3 none any Details for nzilbb_labbcat-1.1.4-py3-none-any.whl

Total release size: 111.5 kB

Release files / nzilbb_labbcat-1.1.4.tar.gz

Download URL nzilbb_labbcat-1.1.4.tar.gz
Size 55.2 kB
Tags Source
SHA-256 checksum
How to use checksums
540b2a8edaf3b3b89f8cb5cd9aca8e2d2802a519c3bafc4f8f688edb34395763
BLAKE2b-256 checksum
How to use checksums
54b6406a06f2810908f3470e8a2f885040cbc839770281ff5a3231c7fd416380
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / nzilbb_labbcat-1.1.4-py3-none-any.whl

Download URL nzilbb_labbcat-1.1.4-py3-none-any.whl
Size 56.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a4cf60e9def87f31a6a456bdc6c985cc2058b08fb35f7b9b21fc4393a231f3d
BLAKE2b-256 checksum
How to use checksums
aa18fb9746650671c7a4e48a865c7eac431757ea25ddea88a1e6df8b694c340b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for nzilbb-labbcat 1.1.4

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page