about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <hi@eli.li>2023-12-30 10:12:44 -0500
committerelioat <hi@eli.li>2023-12-30 10:12:44 -0500
commit098ec8c6104086f3c5e18e6903e2c5e59c3b8bba (patch)
treedbc447c7ff71df5c5805fc00765e2e9fb668fa24
parent988f49feacb86601382e21f026d7c4247a4b159b (diff)
downloadtour-098ec8c6104086f3c5e18e6903e2c5e59c3b8bba.tar.gz
*
-rw-r--r--js/bird-words/README.md37
1 files changed, 36 insertions, 1 deletions
diff --git a/js/bird-words/README.md b/js/bird-words/README.md
index be12836..81940d7 100644
--- a/js/bird-words/README.md
+++ b/js/bird-words/README.md
@@ -10,4 +10,39 @@ In the future I would like to modify this such that I am able to present a scrip
 The @NOUN@ of @ADJECTIVE@ @NOUN@ is known for @MARKOV 13@
 ```
 
-Where `@NOUN@` would select a word from a noun word list at random, `@ADJECTIVE@`, likewise, and `@MARKOV 13@` wold generate a 13 pair long Markov chain to insert at that point.
\ No newline at end of file
+Where `@NOUN@` would select a word from a noun word list at random, `@ADJECTIVE@`, likewise, and `@MARKOV 13@` wold generate a 13 pair long Markov chain to insert at that point.
+
+That'll be something like...
+
+```js
+let nouns = fs.readFileSync('nouns.txt', 'utf8').split('\n');
+let adjectives = fs.readFileSync('adjectives.txt', 'utf8').split('\n');
+
+function fillGaps(script) {
+    let parts = script.split('@');
+    for (let i = 0; i < parts.length; i++) {
+        if (parts[i].startsWith('NOUN')) {
+            parts[i] = nouns[Math.floor(Math.random() * nouns.length)];
+        } else if (parts[i].startsWith('ADJECTIVE')) {
+            parts[i] = adjectives[Math.floor(Math.random() * adjectives.length)];
+        } else if (parts[i].startsWith('MARKOV')) {
+            let length = parseInt(parts[i].split(' ')[1]);
+            let chain = '';
+            let pair = pairs[Math.floor(Math.random() * pairs.length)];
+            for (let j = 0; j < length; j++) {
+                let nextWords = markovChain.get(pair);
+                let nextWord = nextWords[Math.floor(Math.random() * nextWords.length)];
+                chain += ' ' + nextWord;
+                pair = pair.split(' ')[1] + ' ' + nextWord;
+            }
+            parts[i] = chain;
+        }
+    }
+    return parts.join('');
+}
+
+let script = 'The @NOUN@ of @ADJECTIVE@ @NOUN@ is known for @MARKOV 13@';
+console.log(fillGaps(script));
+```
+
+But this remains totally untested at this time.
\ No newline at end of file