;; splork.el ;; Copyright (C) 2024 William R. Moore ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . (switch-to-buffer-other-window "*splork*") (defun find-pos (words pos excludeProper) "Find the Part of Speech from the array" (setq new-words (delq nil (mapcar (lambda (x) (and (equal pos (nth 1 x)) x)) words))) (if (equal 'true excludeProper) (setq new-words (delq nil (mapcar (lambda (x) (and (not (equal "PROPER" (nth 2 x))) x)) new-words))) ) (nth 0 (nth (random (length new-words)) new-words)) ) (defun find-place-noun (words) "Generates a word from the list of place nouns" (setq new-words (delq nil (mapcar (lambda (x) (and (equal "NOUN" (nth 1 x)) x)) words))) (setq new-words (delq nil (mapcar (lambda (x) (and (equal "PLACE" (nth 2 x)) x)) new-words))) (nth 0 (nth (random (length new-words)) new-words)) ) (defun find-noun-with-article (words) "Generates any articles necessary for a noun" (setq new-words (delq nil (mapcar (lambda (x) (and (equal "NOUN" (nth 1 x)) x)) words))) (setq word (nth (random (length new-words)) new-words)) (if (equal "PROPER" (nth 2 word)) (nth 0 word) (format "the %s" (nth 0 word)) ) ) (defun my-sqlite-query (db-file query) "Execute a SQLite query and return the results as a list of lists." (let ((db (sqlite-open db-file))) (if (null db) (error "Failed to open database")) (setq words (sqlite-select db query)) (sqlite-close db) (reverse words)) ) (defun get-words () "Pull all the words from the database" (let ( (db-file "splork.db") (words-query "select word_value, type, categories from words") ) (setq words (my-sqlite-query db-file words-query)) words ) ) (setq words (get-words)) (defun print-word (word) (insert (format "%s\n" (nth 0 word))) ) (let ((sentence-structures '())) (setq sentence-structures (append sentence-structures '( (lambda () "The [random(, .5)] [random(' in ' . , .2)] is " (let ((sentence "the")) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) (setq sentence (format "%s %s" sentence (find-pos words "NOUN" 'true))) (if (<= 2 (random 10)) (setq sentence (format "%s in %s" sentence (find-noun-with-article words))) ) (setq sentence (format "%s is %s" sentence (find-pos words "ADJECTIVE" 'false))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () "The [random(, .5)] [random(' in ' . , .2)] is not " (let ((sentence "the")) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) (setq sentence (format "%s %s" sentence (find-pos words "NOUN" 'true))) (if (<= 2 (random 10)) (setq sentence (format "%s in %s" sentence (find-noun-with-article words))) ) (setq sentence (format "%s is not %s" sentence (find-pos words "ADJECTIVE" 'false))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () "The from will go to " (let ((sentence "the")) (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 ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () " must take the from " (let ((sentence (find-pos words "NOUN" 'true))) (setq sentence (format "%s must take the %s from %s" sentence (find-pos words "NOUN" 'true) (find-place-noun words))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () " is and the is " (let ((sentence (find-place-noun words))) (setq sentence (format "%s is %s and the %s is %s" sentence (find-pos words "ADJECTIVE" 'false) (find-pos words "NOUN" 'true) (find-pos words "ADJECTIVE" 'false))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () " for the " (let ((sentence (find-pos words "NOUN" 'true))) (setq sentence (format "%s %s %s for the %s %s" sentence (find-pos words "PREPOSITION" 'false) (find-place-noun words) (find-pos words "ADJECTIVE" 'false) (find-pos words "NOUN" 'true))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () "The from the the " (let ((sentence "the")) (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 ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () "The [random(, .5)] the [random('in ' . , .2]" (let ((sentence "the")) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) (setq sentence (format "%s %s %s the %s %s" sentence (find-pos words "NOUN" 'true) (find-pos words "VERB" 'false) (find-pos words "ADJECTIVE" 'false) (find-pos words "NOUN" 'true))) (if (<= 2 (random 10)) (setq sentence (format "%s in %s" sentence (find-place-noun words))) ) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () " and the " (let ((sentence (find-pos words "NOUN" 'true))) (setq sentence (format "%s %s %s and %s the %s" sentence (find-pos words "PREPOSITION" 'false) (find-place-noun words) (find-pos words "VERB" 'false) (find-pos words "NOUN" 'true))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () " takes [random(, .5)] and " (let ((sentence (find-pos words "NOUN" 'false))) (setq sentence (format "%s takes %s" sentence (find-pos words "PRONOUN" 'false))) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) (setq sentence (format "%s and %s %s" sentence (find-pos words "NOUN" 'true) (find-pos "PREPOSITION" 'false) (find-place-noun words))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () " the [random(, .5)] " (let ((sentence (find-pos words "NOUN" 'false))) (setq sentence (format "%s %s the" sentence (find-pos words "ACTION" 'false))) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) (setq sentence (format "%s %s" sentence (find-pos words "NOUN" 'true))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () " and [random(, .5)] " (let ((sentence (find-pos words "NOUN" 'false))) (setq sentence (format "%s %s and %s" sentence (find-pos words "ACTION" 'false) (find-pos words "NOUN" 'false) (find-pos words "PRONOUN" 'false))) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) (setq sentence (format "%s %s" sentence (find-pos words "NOUN" 'true))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () "The is the [random(,.5)] ; " (let ((sentence (find-pos words "NOUN" 'false))) (setq sentence (format "%s is the" sentence)) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) (setq sentence (format "%s %s; %s %s %s" sentence (find-pos words "NOUN" 'true) (find-pos words "NOUN" 'true) (find-pos words "PREPOSITION" 'false) (find-place-noun words))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () "You must meet at and retrieve the [random(, .5)] " (let ((sentence "You must meet")) (setq sentence (format "%s %s at %s and retrieve the " sentence, (find-pos words "NOUN" 'false) (find-place-noun words))) (if (<= 5 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) (setq sentence (format "%s %s" sentence (find-pos words "NOUN" 'true))) sentence ))) ) ) (setq sentence-structures (append sentence-structures '( (lambda () "Without the [random(,.3)] , the !" (let ((sentence "Without the")) (if (<= 3 (random 10)) (setq sentence (format "%s %s" sentence (find-pos words "ADJECTIVE" 'false))) ) (setq sentence (format "%s %s!" sentence (find-pos words "NOUN" 'true) (find-pos words "PREPOSITION" 'false) (find-place-noun words))) sentence ))) ) ) (setq generated-sentence (funcall (nth (random (length sentence-structures)) sentence-structures))) (if (<= 1 (random 10)) (setq generated-sentence (format "%s %s" (find-pos words "INTERJECTION" 'false) generated-sentence)) ) (if (not (string-match-p "!" generated-sentence)) (setq generated-sentence (format "%s." generated-sentence)) ) (insert (format "%s\n" generated-sentence)) )