words.wordform.WordForm

words.wordform.WordForm(self, children=[], txt=None, sylls_ipa=[], sylls_text=[], syll_sep='.', num=None, text=None, key=None, parent=None, **kwargs)

Represents a specific form of a word.

Attributes

Name Description
rime Get the rime of the word form.

Methods

Name Description
rime_distance Calculate the rime distance between this word form and another.
rime_distance_nc Decompose rime distance into (nucleus, coda) components.
rime_type Classify the rhyme between this word form and another.

rime_distance

words.wordform.WordForm.rime_distance(wordform, max_dist=RHYME_MAX_DIST)

Calculate the rime distance between this word form and another.

Uses feature-weighted edit distance on rime phonemes (via panphon), which properly aligns phonemes of different lengths and weights substitution cost by phonetic similarity. Returns a value in [0, 1] where 0 is a perfect rhyme.

Args: wordform (WordForm): The word form to compare with. max_dist: Maximum distance threshold. Distances above this return np.nan. 0 = exact match only. None = no limit.

Returns: float: The rime distance (0-1), or np.nan if above max_dist or comparing identical words.

rime_distance_nc

words.wordform.WordForm.rime_distance_nc(wordform)

Decompose rime distance into (nucleus, coda) components.

The nucleus is the leading vowel run of the rime (the stressed syllable’s vowel); the coda component is everything after it, including any unstressed tail syllables. Each component is a feature-weighted edit distance in [0, 1]; a present-vs-absent mismatch (one word open, the other closed) scores 1.0. The 2-D decomposition separates rhyme types a single scalar conflates: consonance (gone/alone: nucleus drifts, coda identical) vs assonance (day/late: nucleus identical, coda differs).

Returns: (nucleus_dist, coda_dist) floats, or (nan, nan) for identical words or missing rimes.

rime_type

words.wordform.WordForm.rime_type(wordform, perfect_nuc_max=RHYME_PERFECT_NUC_MAX, perfect_coda_max=RHYME_PERFECT_CODA_MAX, slant_coda_max=RHYME_SLANT_CODA_MAX, assonance_nuc_max=RHYME_ASSONANCE_NUC_MAX)

Classify the rhyme between this word form and another.

Works in the 2-D (nucleus, coda) distance space of rime_distance_nc, with regions calibrated against Walker’s (1775) rhyming dictionary (scripts/rime_eval.py, 2-D section; macro-F1 0.758 vs 0.679 for the 1-D scalar). The calibration independently recovers the classical taxonomy:

  • ‘perfect’: nucleus match (dn <= 0.05) + near-coda (dc <= 0.15)
  • ‘slant’: coda identity (dc <= 0.05), nucleus free — consonance / half-rhyme (love/prove, gone/alone)
  • ‘assonance’: nucleus identity (dn <= 0.05) with coda mismatch (day/late). Linguistically real but NOT Walker-validated (his taxonomy has no assonance class) — treat as a weaker signal.
  • None otherwise (also for identical words, which do not rhyme with themselves).

Independently validated on real verse (sonnet-scheme-derived positives AND true negatives, scripts/rime_eval.py): counting perfect+slant as rhyme gives F1 0.912, precision 0.944, FPR 0.041 — vs FPR 0.226 for the 1-D scalar at 0.35. Counting assonance as rhyme trades +0.004 TPR for 3x the FPR; don’t.