Standalone scripts to handle and transform KIParla data.
-
eaf2csv.py: convert ELAN.eaffiles into tab-separated transcript CSV. -
make_patch.py: generate a.patchfile from a lemmatization CSV to fix transcription errors in a corpus.vert.tsv. It also supports--batch <wip_subdir>to process every CSV in a corpus folder. -
cli.py vert2eaf(serialize.vert2eaf): rebuild.eaffiles from current-schema.vert.tsvoutput, reattaching translations fromtranslations/<name>.translations.jsonthe same waycsv2eafdoes. -
tsv2formats.py: generate linear enriched and orthographic text files from.vert.tsv. -
linear2html.py: generate publication HTML and PDF artifacts in theKIParla-artifactslayout. -
whisperx_align.py: align a WhisperX word-level JSON with the linguistic tokens of a.vert.tsv(Needleman-Wunsch on accent/punctuation-stripped forms; adapted fromintonation-cues-whisper/src/align_nw.py). The output has one row per TSV row withtoken_id,tu_id,speaker,form,tsv_begin/tsv_end(theBegin=/End=of the TSV'saligncolumn),whisper_segment,whisper_speaker(WhisperX diarization) andwhisper_speaker_mapped(the same as a KIParla speaker code: per conversation, the one-to-one assignment that agrees with the mostmatchtokens; the agreement is reported in the log and inwer.tsv),whisper_text,whisper_begin,whisper_end,alignment,whisper_error_text(the WhisperX word onmismatchandwhisper_onlyrows,_elsewhere)whisper_score(WhisperX's confidence of the aligned word,_if none) andwhisper_avg_logprob(theavg_logprobof the word's segment, the transcription confidence) (match/mismatch/tsv_only/skipped, pluswhisper_onlyrows for WhisperX words with no token); every non-linguistic row isskipped. It prints the WER (TSV as reference, linguistic tokens only). The WhisperX times drift against the TSV's, which exist only at unit boundaries, so each unit is also corrected locally, anchored on its first and last token (columns appended afteralignment,--no-correctionleaves them out):whisper_begin_adj/whisper_end_adjfor units whose two boundary tokens are reliablematches and that are at least halfmatch(shifted and stretched ontotsv_begin/tsv_end; units under 6 tokens only shifted),whisper_begin_partial/whisper_end_partialfor units with one reliable boundary (shifted),adj_rule(which rule applied) andgap_even_*/gap_chars_*(times for thetsv_onlyandskippedtokens of a corrected unit, placed between their corrected neighbours; pauses last 0.1 s,((events))get none). Details in the module docstring.python whisperx_align.py <whisperx.json> <X.vert.tsv> [-o out.tsv] [--no-correction]. -
whisperx_run.py: run WhisperX (transcription, forced alignment, speaker diarization) on the audio of every conversation of one or more modules, passing the diarizer the expected number of speakers fromconversations.tsv(participants-number; one fewer as minimum whenunknown-participantisyes). Models are loaded once; finished conversations are skipped, so it can be restarted.--alignalso runswhisperx_align.pyand collects the WER and the speaker mapping per conversation inwer.tsv;--dry-runprints the plan. Needspip install whisperxand anHF_TOKENfor diarization.python whisperx_run.py <module_dir> ... --audio-dir <dir> --output-dir <dir> [--align]. -
merge_metadata.py: merge metadata tables from module repositories. -
check_participants.py: cross-check each conversation'smetadata/conversations.tsvparticipantslist against the actualspeakervalues in itstsv/<code>.vert.tsv, flag transcript speakers missing frommetadata/participants.tsv, and cross-checkconversations.tsvparticipantsagainstparticipants.tsvconversationsin both directions. Runs across all modules by default (auto-discovered), or pass--modules <dir> .... Pass--add-unknown-participant-columnto add/refresh anunknown-participantcolumn (yes/no) in each module'sconversations.tsv. -
summarize.py: write per-conversation summaries and a module-levelsnapshot.jsoninto the summaries repository,KIParla-summaries/<Module>/(token counts by type, speaking time and token/time rates per participant, overlap shares by time and by annotated tokens, variation, plus the pipeline's own warnings/errors), computed fromtsv/*.vert.tsv. Run by hand aftersync.py/cli.py process:python summarize.py --output-dir <summaries_dir> <module_dir> ...;--checkreports summaries that are missing or older than theirtsv/file. Seedocs/modules/ROOT/pages/scripts.adoc. -
build_explorer.py: build the corpus explorer, a small static site (index.html,explorer.css,core.js,app.js,data.json; inKIParla-artifacts/explorer/) from the snapshots inKIParla-summaries. It filters the conversations by metadata, speaker attributes and measured features (overlap shares, token/time rates, ...), shows figures for the resulting sub-corpus and exports it (code list, CSV, a script that copies the files). Runsummarize.pyfirst. Seedocs/modules/ROOT/pages/scripts.adoc. -
generate_validation_report.py: build the validation pages (published as part of the KIParla docs site), combiningcheck_participants.py's metadata-consistency results with per-conversation pipeline warnings/errors from each module'stmp/process/json/summary.json. One page per module,docs/modules/ROOT/pages/validation-<module>.adoc, with two sections:- Errors: an interactive, filterable table (filter by issue type, search by code) of
only real errors, metadata cross-reference gaps, and missing transcripts — the
actionable list, with GitHub links (
devbranch) to jump straight to each file'svert.tsv/eaf. - Warnings: a diary of every warning the pipeline auto-fixed per conversation — informational, not actionable.
docs/modules/ROOT/pages/validation.adocis the index linking to every module page. Regenerating one module (e.g. fromsync.py) only rewrites that module's page and keeps the other modules' rows in the index.Run again (and commit) after reprocessing a module, or via
sync.py, to keep the pages current. - Errors: an interactive, filterable table (filter by issue type, search by code) of
only real errors, metadata cross-reference gaps, and missing transcripts — the
actionable list, with GitHub links (
-
sync.py: one-shot, one-directional sync for a single edited file — run manually after opening/saving a.eafin ELAN, or hand-editing a.vert.tsv:python sync.py --from-eaf <path/to/X.eaf>: eaf2csv → process →reconcile.py(updatestsv/X.vert.tsv,translations/,tmp/process/{csv,json}/,tmp/process/json/summary.json). The new tsv is merged with the one already in the module: every unit and token that still exists in the eaf keeps itstu_id/token_id(and its overlap group numbers); lemma, upos, xpos, feats, deprel, meta_label andLanguage=labels, which the eaf cannot carry, are kept; units and tokens added in ELAN get fresh ids →tsv2formats(linear-enriched/orthographic) →check_participants(this module) →generate_validation_report(this module's page).python sync.py --from-vert <path/to/X.vert.tsv>:vert2eaf-layered(overwriteseaf/X.eafin place;--layout flatfor the old one-tier-per-speaker file) →tsv2formats→check_participants→generate_validation_report. Pipeline warnings/errors in the report are not refreshed for this file (that would require reprocessing the freshly-written eaf — the reverse direction this command deliberately doesn't auto-trigger, to avoid ping-ponging between the two commands).- Module is inferred from the file's path (
<module>/eaf/X.eafor<module>/tsv/X.vert.tsv); override with--moduleif a module's directory name doesn't map to its config name (e.g.Stra-ParlaBO→StraParlaBO) by simply stripping-.
The test suite lives in tests and uses pytest.
From the tools/ directory:
python3 -m venv .venv
source .venv/bin/activate
pip install -e '.[test]'
python -m pytestIf you only want to run one file:
python -m pytest tests/test_tsv2formats.py-
Audio length check:
audio_check.pycompares the end of each transcript's last annotation with the length of its recording (audio file via--audio-dir, elsedurationinconversations.tsv) and warns onAUDIO_OVERRUN/AUDIO_UNDERRUN. It runs insync.py --from-eafandcli.py process, and standalone:python audio_check.py <module_dir> --audio-dir <dir>. See PIPELINE.md. -
Rebuilding EAFs from TSVs:
python sync.py --from-vert <X.vert.tsv> --audio-ext mp3overwriteseaf/X.eaf(translations reattached fromtranslations/, audio linked by the relative pathX.mp3, no emptydefaulttier). Keep the transcribers' files inoriginal/, used only for the first generation and then left untouched as an archive: the rebuilt EAF contains the normalized text, and is the file to edit from then on (sync.py --from-eaf eaf/X.eaf;sync.pywarns if you start again fromoriginal/). Re-processing rebuilt EAFs reproduces the TSVs except for a handful of tokens next to brackets/intonation marks (39 of 629,677 tokens in Stra-ParlaBO). -
Rebuilding the HTML/PDF pages:
python generate_artifacts.py --module-root <module> --artifacts-root <KIParla-artifacts> --release-label KIP@vX.Y.Z --release-url <url>rebuilds every conversation. After a patch release that touched a few files use--only BOA1001 …: only those pages and PDFs are rebuilt, and<module>/version.json(always rewritten when--release-labelis given) updates the release label shown in the footer of all the other pages (the label written into an HTML at generation time is only the fallback; the PDFs keep their own). -
Validation report:
sync.pyrefreshes the synced module's page (validation-<module>.adoc) and the index; to rebuild several modules at once runpython generate_validation_report.py --modules <module dirs>. -
Encoding: all inputs/outputs are UTF-8 (no BOM), LF line endings, Unicode NFC — the same requirements as Universal Dependencies. Text is NFC-normalized on entry (
eaf2csv,TranscriptionUnit); seetextutil.pyand PIPELINE.md. -
#_means "non-Italian from this point to the end of the unit" (the whole unit when it is at the start);[#_ w]is rewritten to#_ [w](HASH_UNIT_SPACE). See PIPELINE.md. -
vert2eafreconstructs the pipeline's normalized enriched text (post accent-correction, post number-to-words, etc.), not necessarily byte-identical pre-normalization source text. One documented, tested lossy case: a TU's TU-level#variation marker (used when individual non-Italian tokens aren't decidable) is not reconstructed whenvariation=some, since vert.tsv can't distinguish that case fromsomearising purely from individually#/$-marked tokens (which round-trip correctly on their own). Seetests/test_vert2eaf.py. -
Two more expected (non-bug) sources of diff on a real eaf -> vert.tsv -> eaf -> vert.tsv round-trip, verified on
Stra-ParlaBO/tsv/SBCA001.vert.tsv(952/10322 lines differ, but the token multiset — speaker/form/type — is byte-identical; zero content loss):- Millisecond rounding: ELAN's native format stores integer milliseconds, so a
Begin=/End=value with sub-millisecond precision (e.g.166.7895) gets truncated on write (166.789). Unavoidable given the file format. - Tie-break order for simultaneous TUs: when two+ different speakers have annotations at
the exact same timestamp (e.g. everyone laughing at once), their relative order — and
therefore their
tu_idnumbering — isn't preserved across a round-trip, since vert.tsv doesn't record the original eaf's tier ordering._csv2eaf_from_rowscreates tiers in first-appearance order (not aset) so re-runningvert2eafon the same vert.tsv is at least deterministic, but that order won't generally match an arbitrary pre-existing eaf's historical tier order.
- Millisecond rounding: ELAN's native format stores integer milliseconds, so a
-
The tests mostly target importable functions rather than shell-level CLI behavior.