Parsing Latin poetry using constraint satisfaction

logical.ai · 2026-10-03 · by Long Nguyen ·generic
Automatically find and label caesurae in Latin poetry.

Parsing Latin poetry using constraint satisfaction

Write lines of dactylic hexameter on the left; the program will attempt to scan each line, printing the results on the right. You don't need to indicate which vowels are lōng or shŏrt—the program will figure it out. An example from the Aneid is shown below. | Arma virumque cano Troiae qui primus ab orisItaliam fato profugus Lavinjaque venitlitora multum ille et terris iactatus et altovi superum saevae memorem Iunonis ob iram;multa quoque et bello passus dum conderet urbem,inferretque deos Latio genus unde Latinum,Albanique patres atque altae moenia Romae.Musa mihi causas memora quo numine laeso,quidve dolens regina deum tot volvere casusinsignem pietate virum tot adire laboresimpulerit. Tantaene animis caelestibus irae? | | | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |

How it works

Here is the Javascript source code for this page. The process for scanning text works as follows: 1. Split the text into lines; each will be scanned separately. 2. Certain letter combinations are treated as indivisible units; mark them as such. * Determine when “i” acts as a vowel or a consonant. My rule of thumb is to treat “i” as a consonant whenever it's between two vowels (e.g. “Troiae”), or when it's the first letter of a word and the second letter is a vowel (“iacta”)— in all other cases, I treat “i” as a vowel. * Consolidate digraphs. Treat the pairs “qu”, “ch”, “ph”, and “th” as single consonants of length 1. * Consolidate diphthongs. Treat pairs of vowels such as ae and oe as single vowels of length 2. (This has various effects, such as eliding the entire diphthong— and not just the first vowel— whenever elision happens.) * Consolidate muted+liquid consonant pairs. Whenever a mute consonant (b,c,d,f,g,p,t) is followed by a liquid consonant (l,r), treat the pair as a single consonant of length 1. * Mark double-length consonants. Mark the consonants x and z as having length 2. 3. Look at the neighbors of vowels to see which vowels are long by position or elided. * To determine whether a vowel is long by position, look at the letters that follow it (ignoring all whitespace—the letters do not necessarily have to be in the same word.) The vowel is long by position if the next letter is a double-length consonant, or the next two letters are both consonants. Long vowels are marked as having length 2 instead of the default length 1. * A vowel is elided (suppressed or silenced) if it matches the following regular expression: /(\[aeiouy\])m? h?\[aeiouy\]/i. In other words, a vowel is elided if it is the last letter of a word (except for maybe m), and the next word in the line starts with a vowel (or h). There is a special case, which is if the second word is specifically est or es—forms of “to be”— in which case the initial e of es or est is elided instead of the vowel that matched. 4. Guess which vowels are long and short by nature, using the constraint that the meter is dactylic hexameter. Scansion is entirely deterministic if you use accents to mark the so-called natural length of each vowel. But this program trades deterministic computing for an easy-to-use interface: it doesn't require you to mark your vowels in this way; instead, it guesses the appropriate accents (i.e. the natural length of each vowel) using the following inference procedure * The letter-o hack: Assume the letter o at the end of a word is always long. (This is not, as a rule, true— but it's a helpful assumption.) * Compute the number of dactyls and spondees in the line. In a line of perfect dactylic hexameter, you can compute the number of dactyls and spondees based on the number of syllables: The number of dactyls must be 12 less than the number of syllables, and the number of spondees plus the number of dactyls must be 6 (the total number of feet in hexameter). Counting syllables is easy: just count the number of vowels which aren't elided (a diphthong counts as a single vowel). Note on calculation: if D is the number of dactyls, S is the number of spondees, and N is the number of syllables, we know that D + S = 6 in hexameter. Otherwise put, we know that S = 6-D. We also know that each spondee contributes 2 syllables, and each dactyl contributes 3. From this, we find that the number of syllables is N = 2S + 3D. Substituting S = 6-D, the number of syllables becomes N = 2(6-D) + 3D = 12+D. So, D = N-12: the number of dactyls is 12 less than the number of syllables. * Starting at the end of the line and working leftward, greedily try to make each foot a dactyl. This is a very simple constraint satisfaction problem: until you fill your dactyl quota, try to make each foot a dactyl. This will always work except if the dactyl would make a vowel short when it's already known to be long (by position, or because it's a diphthong.) Whenever the attempt fails, assume that the foot is a spondee instead, and continue on to the next foot. When you fill your dactyl quota, mark all remaining feet as spondees (and thus all remaining vowels as long). This simple search heuristic is not flawless— but it works surprisingly well; I suspect part of the success is due to the fact that the penultimate foot is almost always a dactyl (this is why I begin search with the penultimate foot), and because there are usually enough diphthongs and long-by-nature vowels around to make the problem highly constrained. The program is interesting because it has to search and make guesses; it doesn't scan the way you would if you knew the lengths of the vowels by nature. Instead, it works backwards: starting from the assumption that the meter is perfect dactylic hexameter, it is able to determine the natural length of each vowel by guessing which feet are dacyls and which are spondees.

logical.ai · 1 images · 4 links

Comments (0)

No comments yet