summaryrefslogtreecommitdiff
path: root/src/gizmo/wasp-combo.el
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-04-26 23:47:18 -0400
committerLLLL Colonq <llll@colonq>2026-04-26 23:47:18 -0400
commit75e005e81b73d8471f16dc5fad7bbdc312bdbfe7 (patch)
tree1ad7d61b04c44fc52b453aef44868a42012f3551 /src/gizmo/wasp-combo.el
parentcf266a56f30daae8b9af7c9bc3267c61b1973192 (diff)
Diffstat (limited to 'src/gizmo/wasp-combo.el')
-rw-r--r--src/gizmo/wasp-combo.el92
1 files changed, 92 insertions, 0 deletions
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