A toolkit for accessing and working with data from the CRITT Translation Process Research Database (TPR-DB).
Project description
tprdb-utilities
A Python toolkit for downloading and reading data tables from the CRITT Translation Process Research Database (TPR-DB).
Three functions cover the full workflow:
| Function | What it does |
|---|---|
fetch_TPRDB_tables |
Downloads study tables from the CRITT API and saves them to a local directory structure |
read_TPRDB_tables |
Reads those tables from a local clone into a single pandas.DataFrame |
prep_parallel_texts |
Builds segment-aligned bitext and tritext DataFrames ready for MT evaluation |
Installation
# pip
pip install tprdb-utilities
# uv
uv add tprdb-utilities
# poetry
poetry add tprdb-utilities
Quick Start
1 — Download data (fetcher)
Public study (no credentials needed):
from tprdb_utilities import fetch_TPRDB_tables
fetch_TPRDB_tables(
path="/path/to/local/data",
studies=["DG21"],
extensions=["ss", "st"],
public=True,
)
Private study (requires your TPR-DB username and API token):
from tprdb_utilities import fetch_TPRDB_tables
fetch_TPRDB_tables(
path="/path/to/local/data",
studies=["MYSTUDY"],
extensions=["st"],
public=False,
username="myTPRDBusername", # case-sensitive, must match your account
token="my-api-token",
)
After downloading, the function always prints a summary like this:
DG21 [ss]: Done fetching (^_^)
DG21 [st]: Done fetching (^_^)
=== fetch_TPRDB_tables Summary ===
StudyID : DG21
Clone dir: /path/to/local/data/tprdb-mothership-clone
User dir : PUBLIC
Extension Status Time
--------- ---------------- ------
ss Downloaded 1.23s
st Downloaded 0.98s
To read these files with read_TPRDB_tables:
path = "/path/to/local/data/tprdb-mothership-clone"
user = "PUBLIC"
studies = ["DG21"]
Copy those argument values directly into read_TPRDB_tables.
Subsequent calls are bandwidth-efficient. When files for an extension are
already present, fetch_TPRDB_tables sends the X-Client-Tables-Timestamp
header (sourced from the studySummary.xml bundled with the study). The server
returns 304 Not Modified when nothing has changed, so no data is transferred.
The summary will reflect the outcome:
Extension Status Time
--------- ---------------- ------
ss Up to date (304) 0.21s
st Updated 1.05s
2 — Read data (reader)
Use the path and user values printed by fetch_TPRDB_tables at the end of
its summary output.
Public study (user="PUBLIC"):
from tprdb_utilities import read_TPRDB_tables
df = read_TPRDB_tables(
studies=["DG21", "AR22"],
extension="st",
path="/path/to/local/data/tprdb-mothership-clone",
user="PUBLIC",
)
Private study (user="<your TPR-DB username>"):
from tprdb_utilities import read_TPRDB_tables
df = read_TPRDB_tables(
studies=["MYSTUDY"],
extension="st",
path="/path/to/local/data/tprdb-mothership-clone",
user="USER_DIRECTORY_NAME",
)
3 — Transform data (transformer)
Once you have the SG, ST, and TT tables loaded, prep_parallel_texts aligns
translation segments across participants and builds parallel-text DataFrames
suitable for automatic MT evaluation with tools like BLEU or COMET.
from tprdb_utilities import read_TPRDB_tables, prep_parallel_texts
path = "/path/to/local/data/tprdb-mothership-clone"
sg = read_TPRDB_tables(["RUC17"], "sg", path)
st = read_TPRDB_tables(["RUC17"], "st", path)
tt = read_TPRDB_tables(["RUC17"], "tt", path)
parallel_texts = prep_parallel_texts(sg, st, tt)
The return value is a dictionary. Keys follow two patterns:
| Key pattern | Contains |
|---|---|
"ST_{part}" |
Bitext — source text + one participant's translations |
"ST_{p1}_{p2}" |
Tritext — source text + two participants' translations |
# Bitext: source text aligned with P01's translations
parallel_texts["ST_P01"]
# Study Task Text STseg String_ST String_P01
# RUC17 P 4 1 Developing countries are … 发展中国家不愿 …
# …
# Tritext: source text aligned with P01's and P02's translations
parallel_texts["ST_P01_P02"]
# Study Task Text STseg String_ST String_P01 String_P02
# RUC17 P 4 1 Developing countries are … 发展中国家不愿 … 虽然我们可以 …
# …
# Extract just the text columns for evaluation
bitext = parallel_texts["ST_P01"][["String_ST", "String_P01"]]
tritext = parallel_texts["ST_P01_P02"][["String_ST", "String_P01", "String_P02"]]
By default both bitexts and tritexts are produced. To generate only one kind:
# Bitexts only
parallel_texts = prep_parallel_texts(sg, st, tt, prep_tritexts=False)
# Tritexts only
parallel_texts = prep_parallel_texts(sg, st, tt, prep_bitexts=False)
Tritext DataFrames contain only source segments that both participants translated (inner join on study, task, text, and segment number). Merged segments that could not be split are included in bitexts (with the component source strings concatenated) but excluded from tritexts.
Directory Structure
fetch_TPRDB_tables creates the following layout under path:
<path>/
└── tprdb-mothership-clone/
├── PUBLIC/ ← public studies
│ └── <StudyID>/
│ ├── studySummary.xml
│ └── Tables/
│ ├── session1.st
│ └── ...
└── <username>/ ← private studies
└── <StudyID>/
├── studySummary.xml
└── Tables/
├── session1.st
└── ...
Each zip response bundles a studySummary.xml file alongside the table files.
fetch_TPRDB_tables places it in the <StudyID>/ directory (one level above
Tables/) and uses it on subsequent calls to detect whether the server data
has changed.
read_TPRDB_tables expects this exact layout, so the two functions are designed
to work together seamlessly.
Supported Table Extensions
ag, au, ex, fd, fu, hc, hs, kd, ku, pu, sg, ss, st, tt
License
MIT — see LICENSE.
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 tprdb_utilities-0.4.0.tar.gz.
File metadata
- Download URL: tprdb_utilities-0.4.0.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f607a4536a2a647366ba855fb91a30808cb6b8cf77d5959f288d2dc741d86be
|
|
| MD5 |
d3cb60afd39d4a88bbdec9e6d1991889
|
|
| BLAKE2b-256 |
0dad3e91ada5937087f26f87ddd2780f099399f2b67f18ab0341912ce337f777
|
File details
Details for the file tprdb_utilities-0.4.0-py3-none-any.whl.
File metadata
- Download URL: tprdb_utilities-0.4.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
560b6f3d555ae0b32bf21871dfb38e6eb2a6c4e313e26c9b9dac0fa25c6a92e9
|
|
| MD5 |
4bf499b195a0f18e4dda84ec55957483
|
|
| BLAKE2b-256 |
e276b3c5d0f551b8c7ee45e6fe0cb9f04b5c49b2dfaf941310b06b13b70f6344
|