aboutsummaryrefslogtreecommitdiff
path: root/tools/extract_missalemeum_oracle.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/extract_missalemeum_oracle.py')
-rw-r--r--tools/extract_missalemeum_oracle.py58
1 files changed, 57 insertions, 1 deletions
diff --git a/tools/extract_missalemeum_oracle.py b/tools/extract_missalemeum_oracle.py
index a010b52..4b010e2 100644
--- a/tools/extract_missalemeum_oracle.py
+++ b/tools/extract_missalemeum_oracle.py
@@ -18,7 +18,7 @@
# exists for every day.
#
# One line per day, pipe-separated:
-# date|rank|colors|title|tempora|commemorations|displaced|n_masses|commemoration_ids
+# date|rank|colors|title|tempora|commemorations|displaced|n_masses|commemoration_ids|first|gospel
#
# - rank/colors/title/tempora/commemorations/displaced are info.rank,
# info.colors (sorted, concatenated, e.g. "pv"), info.title, info.tempora
@@ -42,6 +42,35 @@
# is ever commemorated there). Never parsed for its date component by this
# fixture or the comparator (info.rank/colors already give the day's own
# values); kept opaque and compared as a plain string.
+# - first/gospel (Task 9) are the day's own Epistle/Lesson and Gospel
+# citations, extracted from entry[0]["sections"] -- the section with
+# id "Lectio" ("Epistle") and "Evangelium" ("Gospel") respectively. Each
+# section's own body is a [[english, latin]] pair; the ENGLISH text
+# (body[0][0]) embeds the citation as one of possibly several
+# "*...*"-wrapped (markdown-italic) spans -- e.g. "Lesson from the letter
+# of St. Paul... \n*Titus 2:11-15*\nBeloved: ...". It is NOT always the
+# FIRST such span: Holy Saturday's own Gospel section opens with a rubric
+# note, itself "*"-wrapped ("*While singing the Gospel candles are not
+# being hold.*"), before the real citation "*Matt 28:1-7*" -- checked
+# directly against the raw JSON, not assumed. The citation span is
+# identified structurally instead of positionally: the first "*...*" span
+# under 40 characters that contains a chapter:verse-shaped digit pair
+# (`\d+\s*[:,.]\s*\d+`, matching all three separators actually used in
+# this source -- "Titus 2:11-15", "4 Kings, 5:1-15", "John 20. 19-31").
+# Verified exhaustively over the whole fixture (all 1 458 Lectio/
+# Evangelium sections across the 728 days that carry one): exactly one
+# candidate per section, zero ambiguous, zero false positives from a
+# longer rubric sentence. TWO days (Good Friday, both years -- the "Missa
+# Praesanctificatorum" liturgy) have no "Lectio"/"Evangelium" section at
+# all (a multi-lesson structure instead, "Lectiones"/"Passio", with no
+# single reading occupying the Epistle/Gospel slot this schema assumes,
+# the SAME shape colitur's own test_lectionary.ml records for its own
+# hand-authored Holy Week data) -- "-" for both fields on those two rows,
+# a WARNING on stderr naming the date, never a silent guess. Extracted
+# VERBATIM (only .strip()ped of surrounding whitespace) -- not normalized,
+# not re-punctuated: the comparator's job, not this extractor's, matching
+# the same "verbatim, not translated or slugified" discipline the fields
+# above already state.
# - Spaces in tempora are turned to "_" (matching the "no field has an
# internal space" convention test/fixtures/lectio-ef-2005-2050.txt already
# uses, so this fixture can be read the same simple way -- split on '|',
@@ -50,8 +79,27 @@
# pass-through display, is space-collapsed for a cheap column-count check).
import json
import os
+import re
import sys
+STAR_RE = re.compile(r"\*([^*]+)\*")
+VERSE_RE = re.compile(r"\d+\s*[:,.]\s*\d+")
+
+
+def extract_citation(sections, section_id, date, label):
+ for sec in sections:
+ if sec["id"] != section_id:
+ continue
+ text = sec["body"][0][0]
+ candidates = [s.strip() for s in STAR_RE.findall(text) if VERSE_RE.search(s) and len(s) < 40]
+ if candidates:
+ return candidates[0]
+ print(f"WARNING: {date}: {section_id!r} section found but no citation-shaped span in it ({label})",
+ file=sys.stderr)
+ return "-"
+ print(f"WARNING: {date}: no {section_id!r} section ({label})", file=sys.stderr)
+ return "-"
+
def main():
if len(sys.argv) != 3:
@@ -84,8 +132,16 @@ def main():
comms = ";".join(comm_titles) or "-"
disp = ";".join(disp_titles) or "-"
ids = ";".join(comm_ids) or "-"
+ sections = data[0]["sections"]
+ cit_first = extract_citation(sections, "Lectio", date, "Epistle")
+ cit_gospel = extract_citation(sections, "Evangelium", date, "Gospel")
+ for t in (cit_first, cit_gospel):
+ if "|" in t:
+ print(f"ERROR: {date}: citation {t!r} contains a delimiter this fixture uses", file=sys.stderr)
+ return 1
rows.append(
f"{date}|{first['rank']}|{colors}|{first['title']}|{tempora}|{comms}|{disp}|{len(data)}|{ids}"
+ f"|{cit_first}|{cit_gospel}"
)
if len(rows) != 730: