splork-mode/splork.el

273 lines
13 KiB
EmacsLisp
Raw Normal View History

2024-08-07 08:36:00 +00:00
;; splork.el
;; Copyright (C) 2024 William R. Moore <william@nerderium.com>
;; 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 <https://www.gnu.org/licenses/>.
(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(<adjective>, .5)] <noun> [random(' in ' . <place>, .2)] is <adjective>"
(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(<adjective>, .5)] <noun> [random(' in ' . <place>, .2)] is not <adjective>"
(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 <noun> from <place> will go to <place>"
(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 ()
"<name> must take the <adjective> <noun> from <place>"
(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 ()
"<place> is <adjective> and the <noun> is <adjective>"
(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 ()
"<name> <preposition> <place> for the <adjective> <noun>"
(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 <noun> from the <place> <action> the <noun>"
(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(<adjective>, .5)] <noun> <action> the <adjective> <noun> [random('in ' . <place>, .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 ()
"<name> <preposition> <place> and <action> the <noun>"
(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 ()
"<name> takes <pronoun> [random(<adjective>, .5)] <noun> and <preposition> <place>"
(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 ()
"<name> <action> the [random(<adjective>, .5)] <noun>"
(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 ()
"<name> <action> <name> and <pronoun> [random(<adjective>, .5)] <noun>"
(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 <noun> is the [random(<adjective>,.5)] <noun>; <name> <preposition> <place>"
(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 <name> at <place> and retrieve the [random(<adjective>, .5)] <noun>"
(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(<adjective>,.3)] <noun>, the <noun> <preposition> <place>!"
(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))
)