(defun find-word (stem properties)
"Property is a list of the form (PART-OF-SPEECH TYPE DETAILS),
e.g. (VERB I PRESENT-STEM).
It returns a string like `amO, -Are, -AvI, -Atus (to love)'."
(let ((result nil)
(lst *latin-re-words*))
(while (and lst (null result))
(setq result (and (string-equal stem (caar lst))
(subsetp properties (caddar lst))
(car lst)))
(setq lst (cdr lst)))
(cadr result)))
(defun latin-re-search (word)
(let ((count 0))
(princ (format "%s can be...\n\n" word))
(dolist (regexp *latin-re-regexps*)
(when (and (string-match (car regexp) word)
(= (match-beginning 0) 0)
(= (match-end 0) (length word)))
(let* ((properties (caddr regexp))
(form (cadr regexp))
(real-word (find-word (match-string 1 word) properties)))
(and real-word (princ (format "... the %s of\n %s.\n"
form real-word))
(setq count (1+ count))))))
(princ (format "\n%d matches.\n" count))))
(defun latin-re (word)
"Print a list of possible interpretations of a latin word.
Long vowels are represented by uppercase letters, other letters should all be
lowercase. When the whole word is in lowercase, the vowels are treated as if
they can be either short or long."
(interactive "sLatin word: \n")
(with-output-to-temp-buffer "*latin-re*"
(let ((case-fold-search nil))
(let ((case-fold-search (string-match "^[a-z]+$" word)))
(latin-re-search word)))))
(defvar *latin-re-regexps*
'( ("\\(.*\\)a" "singular nominative" (noun I))
("\\(.*\\)a" "singular vocative" (noun I))
("\\(.*\\)am" "singular accusative" (noun I))
("\\(.*\\)ae" "singular genitive" (noun I))
("\\(.*\\)ae" "singular dative" (noun I))
("\\(.*\\)A" "singular ablative" (noun I))
("\\(.*\\)ae" "plural nominative" (noun I))
("\\(.*\\)ae" "plural vocative" (noun I))
("\\(.*\\)As" "plural accusative" (noun I))
("\\(.*\\)Arum" "plural genitive" (noun I))
("\\(.*\\)Is" "plural dative" (noun I))
("\\(.*\\)Is" "plural ablative" (noun I))
("\\(.*[^i]\\)us" "singular nominative" (noun II-us))
("\\(.*[^i]\\)e" "singular vocative" (noun II-us))
("\\(.*[^i]\\)um" "singular accusative" (noun II-us))
("\\(.*[^i]\\)I" "singular genitive" (noun II-us))
("\\(.*[^i]\\)O" "singular dative" (noun II-us))
("\\(.*[^i]\\)O" "singular ablative" (noun II-us))
("\\(.*[^i]\\)I" "plural nominative" (noun II-us))
("\\(.*[^i]\\)I" "plural vocative" (noun II-us))
("\\(.*[^i]\\)Os" "plural accusative" (noun II-us))
("\\(.*[^i]\\)Orum" "plural genitive" (noun II-us))
("\\(.*[^i]\\)Is" "plural dative" (noun II-us))
("\\(.*[^i]\\)Is" "plural ablative" (noun II-us))
("\\(.*[^i]\\)um" "singular nominative" (noun II-um))
("\\(.*[^i]\\)um" "singular vocative" (noun II-um))
("\\(.*[^i]\\)um" "singular accusative" (noun II-um))
("\\(.*[^i]\\)I" "singular genitive" (noun II-um))
("\\(.*[^i]\\)O" "singular dative" (noun II-um))
("\\(.*[^i]\\)O" "singular ablative" (noun II-um))
("\\(.*[^i]\\)a" "plural nominative" (noun II-um))
("\\(.*[^i]\\)a" "plural vocative" (noun II-um))
("\\(.*[^i]\\)a" "plural accusative" (noun II-um))
("\\(.*[^i]\\)Orum" "plural genitive" (noun II-um))
("\\(.*[^i]\\)Is" "plural dative" (noun II-um))
("\\(.*[^i]\\)Is" "plural ablative" (noun II-um))
("\\(.*\\)ius" "singular nominative" (noun II-ius))
("\\(.*\\)e" "singular vocative" (noun II-ius))
("\\(.*\\)I" "singular vocative" (noun II-ius proper-name))
("\\(.*\\)ium" "singular accusative" (noun II-ius))
("\\(.*\\)I" "singular genitive" (noun II-ius))
("\\(.*\\)iO" "singular dative" (noun II-ius))
("\\(.*\\)iO" "singular ablative" (noun II-ius))
("\\(.*\\)iI" "plural nominative" (noun II-ius))
("\\(.*\\)iI" "plural vocative" (noun II-ius))
("\\(.*\\)iOs" "plural accusative" (noun II-ius))
("\\(.*\\)iOrum" "plural genitive" (noun II-ius))
("\\(.*\\)iIs" "plural dative" (noun II-ius))
("\\(.*\\)iIs" "plural ablative" (noun II-ius))
("\\(.*\\)ium" "singular nominative" (noun II-ium))
("\\(.*\\)ium" "singular vocative" (noun II-ium))
("\\(.*\\)ium" "singular accusative" (noun II-ium))
("\\(.*\\)I" "singular genitive" (noun II-ium))
("\\(.*\\)iO" "singular dative" (noun II-ium))
("\\(.*\\)iO" "singular ablative" (noun II-ium))
("\\(.*\\)ia" "plural nominative" (noun II-ium))
("\\(.*\\)ia" "plural vocative" (noun II-ium))
("\\(.*\\)ia" "plural accusative" (noun II-ium))
("\\(.*\\)iOrum" "plural genitive" (noun II-ium))
("\\(.*\\)iIs" "plural dative" (noun II-ium))
("\\(.*\\)iIs" "plural ablative" (noun II-ium))
("\\(.*[ei]r\\)" "singular nominative" (noun II-er full))
("\\(.*[ei]r\\)" "singular vocative" (noun II-er full))
("\\(.*[ei]?r\\)um" "singular accusative" (noun II-er))
("\\(.*[ei]?r\\)I" "singular genitive" (noun II-er))
("\\(.*[ei]?r\\)O" "singular dative" (noun II-er))
("\\(.*[ei]?r\\)O" "singular ablative" (noun II-er))
("\\(.*[ei]?r\\)I" "plural nominative" (noun II-er))
("\\(.*[ei]?r\\)I" "plural vocative" (noun II-er))
("\\(.*[ei]?r\\)Os" "plural accusative" (noun II-er))
("\\(.*[ei]?r\\)Orum" "plural genitive" (noun II-er))
("\\(.*[ei]?r\\)Is" "plural dative" (noun II-er))
("\\(.*[ei]?r\\)Is" "plural ablative" (noun II-er))
("\\(.*\\)Are" "active infinitive" (verb I))
("\\(.*\\)Ere" "active infinitive" (verb II))
("\\(.*\\)ere" "active infinitive" (verb III))
("\\(.*\\)Ire" "active infinitive" (verb IV))
("\\(.*\\)ArI" "passive infinitive" (verb I))
("\\(.*\\)ErI" "passive infinitive" (verb II))
("\\(.*\\)I" "passive infinitive" (verb III))
("\\(.*\\)IrI" "passive infinitive" (verb IV))
("\\(.*\\)O" "active indicative first person singular" (verb I))
("\\(.*\\)As" "active indicative second person singular" (verb I))
("\\(.*\\)at" "active indicative third person singular" (verb I))
("\\(.*\\)Amus" "active indicative first person plural" (verb I))
("\\(.*\\)Atis" "active indicative second person plural" (verb I))
("\\(.*\\)ant" "active indicative third person plural" (verb I))
("\\(.*\\)eO" "active indicative first person singular" (verb II))
("\\(.*\\)Es" "active indicative second person singular" (verb II))
("\\(.*\\)et" "active indicative third person singular" (verb II))
("\\(.*\\)Emus" "active indicative first person plural" (verb II))
("\\(.*\\)Etis" "active indicative second person plural" (verb II))
("\\(.*\\)ent" "active indicative third person plural" (verb II))
("\\(.*\\)O" "active indicative first person singular" (verb III))
("\\(.*\\)is" "active indicative second person singular" (verb III))
("\\(.*\\)it" "active indicative third person singular" (verb III))
("\\(.*\\)imus" "active indicative first person plural" (verb III))
("\\(.*\\)itis" "active indicative second person plural" (verb III))
("\\(.*\\)unt" "active indicative third person plural" (verb III))
("\\(.*\\)iO" "active indicative first person singular" (verb IV))
("\\(.*\\)Is" "active indicative second person singular" (verb IV))
("\\(.*\\)it" "active indicative third person singular" (verb IV))
("\\(.*\\)Imus" "active indicative first person plural" (verb IV))
("\\(.*\\)Itis" "active indicative second person plural" (verb IV))
("\\(.*\\)iunt" "active indicative third person plural" (verb IV))
)
"Declination and conjugation patterns.")
(defvar *latin-re-words*
'(("puell" "puella, -ae (girl)" (noun I))
("ager" "ager, agrI (field)" (noun II-er full))
("agr" "ager, agrI (field)" (noun II-er))
("puer" "puer, puerI (boy)" (noun II-er full))
("puer" "puer, puerI (boy)" (noun II-er))
("mur" "murus, murI (wall)" (noun II-us))
("vergil" "Vergilius, Vergi'lI (Vergil)" (noun II-ius proper-name))
("fluv" "fluvius, fluvI (river)" (noun II-ius))
("am" "amO, amAre, amAvI, amAtus (to love)" (verb I))))