From 13e7990f533bf6a88e19363d1a0ff9d91c6672a9 Mon Sep 17 00:00:00 2001 From: William Moore Date: Wed, 7 Aug 2024 16:15:27 -0500 Subject: [PATCH] Update with refactoring --- splork.el | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/splork.el b/splork.el index 317445d..bdaac07 100644 --- a/splork.el +++ b/splork.el @@ -16,6 +16,7 @@ (defun sentence-case (sentence) + "Changes the sentence to a capital case letter at the beginning." (format "%s%s" (upcase (substring sentence 0 1)) (substring sentence 1)) ) @@ -42,13 +43,12 @@ (if (string-match-p "PROPER" (nth 2 word)) (nth 0 word) - ) - (if (string-match-p "PLACE" (nth 2 word)) - (nth 0 word) - (format "the %s" (nth 0 word)) + (if (string-match-p "PLACE" (nth 2 word)) + (nth 0 word) + (format "the %s" (nth 0 word)) + ) ) ) - (setq words '( ("Chinese Communist Party" "NOUN" "") ("CCP" "NOUN" "") @@ -1102,13 +1102,11 @@ )) (defun splork () - (interactive) - (switch-to-buffer-other-window "*splork*") (let ((sentence-structures '())) (setq sentence-structures (append sentence-structures '( (lambda () "The [random(, .5)] [random(' in ' . , .2)] is " - (let ((sentence "the")) + (let ((sentence "")) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) @@ -1124,7 +1122,7 @@ (setq sentence-structures (append sentence-structures '( (lambda () "The [random(, .5)] [random(' in ' . , .2)] is not " - (let ((sentence "the")) + (let ((sentence "")) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) @@ -1141,7 +1139,7 @@ (setq sentence-structures (append sentence-structures '( (lambda () "The from will go to " - (let ((sentence "the")) + (let ((sentence "")) (setq sentence (format "%s %s from %s will go to %s" sentence (find-pos words "NOUN" 'false) (find-place-noun words) (find-place-noun words))) sentence ))) @@ -1178,7 +1176,7 @@ (setq sentence-structures (append sentence-structures '( (lambda () "The from the the " - (let ((sentence "the")) + (let ((sentence "")) (setq sentence (format "%s %s from the %s %s the %s" sentence (find-pos words "NOUN" 'true) (find-place-noun words) (find-pos words "VERB" 'false) (find-pos words "NOUN" 'true))) sentence ))) @@ -1187,7 +1185,7 @@ (setq sentence-structures (append sentence-structures '( (lambda () "The [random(, .5)] the [random('in ' . , .2]" - (let ((sentence "the")) + (let ((sentence "")) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) @@ -1304,9 +1302,16 @@ (if (not (string-match-p "!" generated-sentence)) (setq generated-sentence (format "%s." generated-sentence)) ) - (goto-char (point-max)) - (insert (format "%s\n" generated-sentence)) + generated-sentence ) ) +(defun splork-generate () + (interactive) + (switch-to-buffer-other-window "*splork*") + (setq sentence (splork)) + (goto-char (point-max)) + (insert (format "%s\n" sentence)) + ) + (provide 'splork)