From 75e005e81b73d8471f16dc5fad7bbdc312bdbfe7 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Sun, 26 Apr 2026 23:47:18 -0400 Subject: Update --- src/gizmo/wasp-combo.el | 92 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/gizmo/wasp-combo.el (limited to 'src/gizmo/wasp-combo.el') diff --git a/src/gizmo/wasp-combo.el b/src/gizmo/wasp-combo.el new file mode 100644 index 00000000..5e4d7338 --- /dev/null +++ b/src/gizmo/wasp-combo.el @@ -0,0 +1,92 @@ +;;; wasp-combo --- description -*- lexical-binding: t; -*- +;;; Commentary: +;;; Code: + +(require 'cl-lib) +(require 'rx) +(require 'dash) +(require 's) +(require 'ht) +(require 'f) + +(require 'wasp-utils) + +(defvar w/combo-words (ht-create)) +(defvar w/combo-word-phonemes (ht-create)) +(defun w/combo-words-process-line (line) + "Parse one LINE from the syllable table." + (-let* ( ((word rest) (s-split-up-to " " line 1)) + (phonemes (s-split " " rest))) + (message "processing: %s" word) + (ht-set! w/combo-word-phonemes word + (--map (s-replace-regexp (rx digit) "" it) phonemes)) + (ht-set! w/combo-words + word + (-non-nil + (--map (-some-> (s-match (rx digit) it) (car) (string-to-number)) + phonemes))))) +(defun w/combo-words-load () + "Populate `w/combo-words'." + (let* + ( (text (f-read-text (w/asset "syllables.txt"))) + (lines (s-lines text))) + (--each lines + (w/combo-words-process-line it)))) +(w/combo-words-load) + +(defun w/combo-split-words (sentence) + "Split SENTENCE into uppercase words." + (-map #'s-upcase + (-filter #'s-present? + (s-split (rx (not (or alnum "'"))) sentence)))) + +(defun w/combo-word-syllables (word) + "Determine the pattern of syllables in WORD." + (ht-get w/combo-words (s-upcase word))) + +(defun w/combo-scansion (words) + "Determine the pattern of syllables in WORDS." + (-mapcat #'w/combo-word-syllables words)) + +(defun w/combo-alliteration? (words) + "Determine if WORDS contain an alliterative pattern." + (> + (-max (cons 0 (--map (length (cdr it)) (--group-by (seq-elt it 0) words)))) + (max 1 (/ (length words) 2)))) + +(defun w/combo-palindrome? (words) + "Determine if WORDS form a palindrome." + (let ((joined (s-join "" words))) + (s-equals? joined (s-reverse joined)))) + +(defun w/combo-assonance? (words) + "Determine if WORDS have assonance." + (> + (-max + (cons 0 + (--map (length (cdr it)) + (-group-by (lambda (x) x) + (--mapcat (ht-get w/combo-word-phonemes it) words))))) + (max 2 (/ (length words) 8)))) + +(defun w/combo-classify (sentence) + "Return a list of tags indicating properties of SENTENCE." + (let* ( (words (w/combo-split-words sentence)) + (scan (w/combo-scansion words))) + (-concat + (when (= (length scan) 17) + '(haiku)) + (when (= (length scan) 10) + '(pentameter)) + (when (w/combo-alliteration? words) + '(alliteration)) + (when (w/combo-assonance? words) + '(assonance)) + (when (w/combo-palindrome? words) + '(palindrome)) + (when-let* ( (sexp (w/read-sexp sentence)) + (_ (listp sexp))) + '(sexp))))) + +(provide 'wasp-combo) +;;; wasp-combo.el ends here -- cgit v1.2.3