Add per-line meter detection

CMU stress markers -> stress string per line, scored against the
classical feet (iamb, trochee, anapest, dactyl, amphibrach) with
flexible monosyllables. Syllable count + best-fit meter shown in the
toolbar readout for the caret line.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-07 01:12:34 -04:00
parent 84bae60dff
commit 7a1e0e2953
3 changed files with 90 additions and 3 deletions
+25
View File
@@ -190,3 +190,28 @@ def test_stanzas_and_legend():
def test_blank_lines_split_stanzas():
res = analyze(Draft(text="the cat\na hat\n\nso blue\nso true"))
assert [s["scheme"] for s in res["stanzas"]] == ["aa", "aa"]
# ------------------------------------------------------------------ meter
def meter_of(line: str) -> dict:
res = analyze(Draft(text=line))
return res["meter"][0]
def test_iambic_pentameter():
m = meter_of("Shall I compare thee to a summer's day")
assert m["syl"] == 10
assert m["label"] == "iambic pentameter"
def test_trochaic_tetrameter():
m = meter_of("Tyger Tyger burning bright")
assert m["syl"] == 7 # catalectic — final unstressed syllable dropped
assert m["label"] == "trochaic tetrameter"
def test_syllables_always_reported():
m = meter_of("the city hums in amber under fading light")
assert m["syl"] == 12
assert m["stress"]